티스토리 뷰

Wargame/Bandit

Bandit Level 22 → Level 23

장일영 2024. 5. 16. 13:29

 

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.

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

노트: 다른 사람이 작성한 쉘 스크립트를 볼 수 있는 능력은 아주 유용하다. 이 레벨의 스크립트는 읽기 쉽게 작성되었다. 내용을 이해하는 것이 어렵다면 이 스크립트를 실행해 출력되는 디버그 정보를 확인해라.
 
Commands you may need to solve this level
`cron`, `crontab`, `crontab(5)`(use “man 5 crontab” to access this)
 

Write Up

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

bandit22@bandit:~$ 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

 
`cronjob_bandit23.sh` 파일을 1분 마다 실행한다. 쉘 스크립트의 내용을 확인해보면 bash로 실행되고, `whoami` 명령의 결과를 `myname` 변수에 할당한다.

그리고 "i am user $(whoami)"의 md5 해시값을 공백 기준으로 잘라 `mytarget` 변수에 할당한다.

결과적으로 이 스크립트는 `/etc/bandit_pass/$myname`의 내용을 `/tmp/$mytarget`에 저장하는 동작을 명시하고 있다.

그러면 bandit23 계정으로 접속했을 때 해당 크론잡이 동작했을 때 bandit23의 패스워드가 있는 임시 파일 이름을 알 수 있다.

bandit22@bandit:~$ cat /tmp/$(echo I am user bandit23 | md5sum | cut -d ' ' -f 1)

'Wargame > Bandit' 카테고리의 다른 글

Bandit Level 24 → Level 25  (0) 2024.05.16
Bandit Level 23 → Level 24  (0) 2024.05.16
Bandit Level 21 → Level 22  (0) 2024.05.16
Bandit Level 20 → Level 21  (0) 2024.05.16
Bandit Level 19 → Level 20  (0) 2024.05.16
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함