본문 바로가기

wargame/bandit

Level 22 → Level 23

Level Goal

A program is running automatically at regular intervals from cron, the time-based job scheduler. Look in /etc/cron.d/ for the configuration and see what command is being executed.
NOTE: Looking at shell scripts written by other people is a very useful skill. The script for this level is intentionally made easy to read. If you are having problems understanding what it does, try executing it to see the debug information it prints.
프로그램은 (시간에 기반을 둔 job scheduler인) cron에서 일정한 시간 간격을 두고 자동적으로 실행된다. /etc/cron.d/에서 구성을 찾고 명령어가 실행되는지 확인하여라
NOTE: 다른 사람이 작성한 shell scripts를 살펴 보는 것은 매우 유용한 방법이다. 이 단계의 script는 의도적으로 읽기 쉽게 만들어졌다. 만약 그것이 무엇을 하는지 이해하는데 문제가 있다면, 그것이 출력하는 디버그 정보를 보기위해 실행하여라.

Code

bandit22@bandit:~$ cd /etc/cron.d/
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
bandit22@bandit:/etc/cron.d$ cat /usr/bin/cronjob_bandit23.sh
#!/bin/bash

myname=$(whoami) # myname은 whoami 명령어를 출력한 결과이다
mytarget=$(echo I am user $myname | md5sum | cut -d ' ' -f 1) # mytarget은 뒤의 명령어를 출력한 결과이다

echo "Copying passwordfile /etc/bandit_pass/$myname to /tmp/$mytarget" # "비밀번호파일인 ~를 ~로 복사하여라"를 출력한다

cat /etc/bandit_pass/$myname > /tmp/$mytarget # ~를 ~로 붙여넣는다
bandit22@bandit:/etc/cron.d$ whoami
bandit22
bandit22@bandit:/etc/cron.d$ echo I am user bandit22 | md5sum | cut -d ' ' -f 1 # mytarget 값 알아내기
8169b67bd894ddbb4412f91573b38db3
bandit22@bandit:/etc/cron.d$ cat /etc/bandit_pass/bandit22 > /tmp/8169b67bd894ddbb4412f91573b38db3
bandit22@bandit:/etc/cron.d$ cat /tmp/8169b67bd894ddbb4412f91573b38db3
#비밀번호
bandit22@bandit:/usr/bin$ echo I am user bandit23 | md5sum | cut -d ' ' -f 1 # 다시 시도
8ca319486bfbbc3663ea0fbe81326349
bandit22@bandit:/usr/bin$ cat /tmp/8ca319486bfbbc3663ea0fbe81326349
#비밀번호

이전 단계와 비슷하게 파일을 출력하고 그에 따라 명령어를 실행하여 출력하는 문제였다. 중간에 myname=$(whoami) 부분과 지역변수 선언/출력 부분이 헷갈려서 잠시 헤메기는 했지만 문제없이 풀 수 있었다. 그러나 실행해보니 비밀번호가 이전 단계에서의 비밀번호와 동일하였다. 잠시 혼란스러웠지만 문제의 NOTE 부분을 다시 읽고 문제를 풀면서 느꼈던 기시감을 다시 생각해보니 문제를 해결할 수 있었다. 명령어에서 myname이 들어갈 부분에 bandit22가 들어가 있으므로 bandit22의 비밀번호가 출력되었다고 추론할 수 있었고 문제에서 이 단계의 script는 쉽게 읽을 수 있다고 한 부분에서 확신할 수 있었다. 위와 같은 방법으로 다시 실행하였을 때 마지막에 cat 명령어로 복사&붙여넣기를 하면 권한이 없다고 해서 헤맸다. 생각해보니 복사&붙여넣기를 하는 건 crontab파일이므로 그냥 파일을 출력해서 비밀번호를 구했다.

'wargame > bandit' 카테고리의 다른 글

Level 24 → Level 25  (0) 2019.02.28
Level 23 → Level 24  (0) 2019.02.28
Level 21 → Level 22  (0) 2019.02.28
Level 20 → Level 21  (0) 2019.02.28
Level 19 → Level 20  (0) 2019.02.24