Post

Bandit Level 22 → Level 23

문제

https://overthewire.org/wargames/bandit/bandit23.html

목표

다음 레벨의 패스워드를 찾는다.

시간 기반 작업 스케줄러 cron에서 일정한 간격으로 프로그램이 실행된다. /etc/cron.d/ 에서 어떤 명령이 실행되고 있는지 확인해라.

풀이

1
2
3
4
5
bandit22@bandit:~$ cd /etc/cron.d/
bandit22@bandit:/etc/cron.d$ ls
cronjob_bandit15_root  cronjob_bandit22  cronjob_bandit24       e2scrub_all  sysstat
cronjob_bandit17_root  cronjob_bandit23  cronjob_bandit25_root  otw-tmp-dir
bandit22@bandit:/etc/cron.d$ cat cronjob_bandit23

/etc/cron.d/로 이동해서 파일 목록을 확인해보니 cronjob_bandit23이라는 파일이 보인다.


1
2
3
bandit22@bandit:/etc/cron.d$ cat cronjob_bandit23
@reboot bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null
* * * * * bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null

파일의 내용을 보니 프로그램 부팅시, 매분 매초 /usr/bin/cronjob_bandit23.sh 파일을 /dev/null로 버린다고 한다.


1
2
3
4
5
6
7
8
9
bandit22@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit23.sh
#!/bin/bash

myname=$(whoami)
mytarget=$(echo I am user $myname | md5sum | cut -d ' ' -f 1)

echo "Copying passwordfile /etc/bandit_pass/$myname to /tmp/$mytarget"

cat /etc/bandit_pass/$myname > /tmp/$mytarget

/usr/bin/cronjob_bandit23.sh 파일을 보면 /tmp/$mytarget에 패스워드가 저장되어 있는 것을 알 수 있다.

mynamebandit23이고, 따라서 mytargetecho I am user bandit23 | md5sum | cut -d ' ' -f 1 명령어를 통해 알 수 있다.

1
2
bandit22@bandit:/etc/cron.d$ echo I am user bandit23 | md5sum | cut -d ' ' -f 1
8ca319486bfbbc3663ea0fbe81326349


/tmp/8ca319486bfbbc3663ea0fbe81326349에 저장된 패스워드를 확인한다.

1
2
bandit22@bandit:~$ cat /tmp/8ca319486bfbbc3663ea0fbe81326349
QYw0Y2aiA672PsMmh9puTQuhoz8SyR2G


Password : QYw0Y2aiA672PsMmh9puTQuhoz8SyR2G

배운 것

  • 쉘 스크립트를 읽는 방법
This post is licensed under CC BY 4.0 by the author.