bandit23

KJH·2022년 12월 1일

bandit

목록 보기
19/29
ssh bandit23@bandit.labs.overthewire.org -p 2220 
#QYw0Y2aiA672PsMmh9puTQuhoz8SyR2G

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…

프로그램은 시간 기반 작업 스케줄러인 cron에서 일정한 간격으로 자동으로 실행됩니다. /etc/cron.d/에서 구성을 확인하고 실행 중인 명령을 확인합니다.
참고: 이 수준에서는 자신의 첫 번째 셸 스크립트를 만들어야 합니다. 이것은 매우 큰 단계이고 여러분이 이 수준을 이길 때 여러분은 스스로를 자랑스러워해야 합니다!
참고 2: 셸 스크립트가 실행되면 제거되므로 복사본을 보관할 수 있습니다

풀이

cron을 확인한다

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)	#bandit24 
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)"		#owner변수는 파일의 소유자
        if [ "${owner}" = "bandit23" ]; then	#만약 owner가 bandit23이라면
            timeout -s 9 60 ./$i		(60초 후 kill -9)
        fi			# 		#if문 끝
        rm -f ./$i		#파일지우기
    fi		#then문 끝
done		#아예끝

비밀번호를 읽어서 내 폴더에 쓰는 역활의 파일 test.sh만들기
cat /etc/bandit_pass/bandit24 > /tmp/jiheon/passwd

#bandit23@bandit:/tmp/jiheon 에서 작업

chmod 666 /tmp/jiheon		# 현재 폴더에 누구나 쓸 수 있게 (비번을써야됨)
cp ./test.sh /var/spool/bandit24/foo/test.sh	#파일을 옮김
# cron에 의해 1분마다 작업이 실행되고, 내 폴더의 passwd에 비번이 써짐
# VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar

0개의 댓글