
To gain access to the next level, you should use the setuid binary in the homedirectory. Execute it without arguments to find out how to use it. The password for this level can be found in the usual place (/etc/bandit_pass), after you have used the setuid binary.
다음 레벨에 접근하려면 home 디렉토리에 있는 setuid 바이너리를 이용해야 한다. 이를 어떻게 사용하는지 알고 싶다면 인자 없이 바이너리 파일을 실행해라. 다음 레벨의 패스워드는 /etc/bandit_pass에서 setuid 바이너리 파일을 사용하면 찾을 수 있다.
bandit19@bandit:~$ ls -al
total 36
drwxr-xr-x 2 root root 4096 Oct 5 2023 .
drwxr-xr-x 70 root root 4096 Oct 5 2023 ..
-rwsr-x--- 1 bandit20 bandit19 14876 Oct 5 2023 bandit20-do
-rw-r--r-- 1 root root 220 Jan 6 2022 .bash_logout
-rw-r--r-- 1 root root 3771 Jan 6 2022 .bashrc
-rw-r--r-- 1 root root 807 Jan 6 2022 .profile
bandit19@bandit:~$ file bandit20-do
bandit20-do: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=037b97b430734c79085a8720c90070e346ca378e, for GNU/Linux 3.2.0, not stripped
bandit20-d0 파일을 확인해보면 setuid가 걸려 있음을 알 수 있다. 권한 비트(-rwsr-x---)만 보아도 중간에 setuid 비트를 확인할 수 있다. 따라서 이 파일을 실행하면 일시적으로 파일 소유자(bandit20)의 권한을 얻어 실행할 수 있다.
bandit19@bandit:~$ ls -al /etc/bandit_pass/ | grep bandit20
-r-------- 1 bandit20 bandit20 33 Oct 5 2023 bandit20
bandit20 파일은 bandit20 유저만 읽을 수 있다. 그러면 bandit20-do 파일을 실행해 권한 상승을 하면 /etc/bandit_pass 디렉토리 내의 bandit20 파일에 접근해 플래그를 얻을 수 있지 않을까?
bandit19@bandit:~$ ./bandit20-do
Run a command as another user.
Example: ./bandit20-do id
bandit19@bandit:~$ id
uid=11019(bandit19) gid=11019(bandit19) groups=11019(bandit19)
bandit19@bandit:~$ ./bandit20-do id
uid=11019(bandit19) gid=11019(bandit19) euid=11020(bandit20) groups=11019(bandit19)
일시적으로 bandit20의 권한을 얻은 것을 확인할 수 있다. 그러므로 인자에 /etc/bandit_pass/bandit20 파일을 읽을 수 있는 명령어를 입력하면 해당 파일을 읽을 수 있을 것이다.
bandit19@bandit:~$ ./bandit20-do cat /etc/bandit_pass/bandit20