
There is a setuid binary in the homedirectory that does the following: it makes a connection to localhost on the port you specify as a commandline argument. It then reads a line of text from the connection and compares it to the password in the previous level (bandit20). If the password is correct, it will transmit the password for the next level (bandit21).
NOTE: Try connecting to your own network daemon to see if it works as you think
home 디렉토리에 setuid가 걸린 바이너리 파일의 기능은 다음과 같다. 커맨드라인에서 인자로 입력한 포트를 통해 localhost에 연결한다. 이후 텍스트 한 줄을 읽고 이전 레벨(bandit20)의 패스워드와 비교한다. 일치하면 다음 레벨(bandit21)의 패스워드를 전송할 것이다.
노트: 당신의 네트워크 데몬에 연결해 당신이 생각한 대로 동작하는지 확인해라.
ssh, nc, cat, bash, screen, tmux, Unix ‘job control’ (bg, fg, jobs, &, CTRL-Z, …)
bandit20@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 ..
-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
-rwsr-x--- 1 bandit21 bandit20 15600 Oct 5 2023 suconnect
bandit20@bandit:~$ file suconnect
suconnect: setuid ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=4d95c75f0fe296f2477bfaad8b17039de5a56534, for GNU/Linux 3.2.0, not stripped
bandit20@bandit:~$ ./suconnect
Usage: ./suconnect <portnumber>
This program will connect to the given port on localhost using TCP. If it receives the correct password from the other side, the next password is transmitted back.
suconnect 파일이 setuid가 걸린 바이너리 파일이다. 이 파일의 동작은 다음과 같다.
그렇다면 suconnect 파일이 특정 포트에 접속했을 때 bandit20 패스워드를 읽어들일 수 있도록 하면 다음 레벨의 패스워드를 반환할 것이다.
bandit20@bandit:~$ nc -l -p 12345 < /etc/bandit_pass/bandit20
이렇게 하면 12345번 포트가 열리고 접속 시 /etc/bandit_pass/bandit20 파일의 내용을 출력하게 된다.