forked from cnmsec/MpaasPentestTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpaas_request.py
121 lines (88 loc) · 3.28 KB
/
mpaas_request.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from threading import Thread
from http.server import HTTPServer, BaseHTTPRequestHandler
import sys
import requests
import frida
#By:Gr33k
#mail:[email protected]
ECHO_PORT = 28080
BURP_PORT = 8080
class RequestHandler(BaseHTTPRequestHandler):
def do_REQUEST(self):
content_length = int(self.headers.get('content-length', 0))
self.send_response(200)
self.end_headers()
self.wfile.write(self.rfile.read(content_length))
do_RESPONSE = do_REQUEST
def echo_server_thread():
print('start echo server at port {}'.format(ECHO_PORT))
server = HTTPServer(('', ECHO_PORT), RequestHandler)
server.serve_forever()
t = Thread(target=echo_server_thread)
t.daemon = True
t.start()
session = frida.get_usb_device().attach('支付宝')
script = session.create_script('''
try{
var className = "DTURLRequestOperation";
var funcName = "- addHTTPBodyParameter:forKey:";
var hook = eval('ObjC.classes.' + className + '["' + funcName + '"]');
console.log("[*] Class Name: " + className);
console.log("[*] Method Name: " + funcName);
Interceptor.attach(hook.implementation, {
onEnter: function(args) {
var v = new ObjC.Object(args[2]);
send({type: 'REQ', data: v.toString()})
var op = recv('NEW_REQ', function(val) {
var s = val.payload;
var new_s = ObjC.classes.NSString.stringWithString_(s);
args[2] = new_s;
});
op.wait();
},
onLeave: function(retval) {
}
});
var className1 = "DTURLRequestOperation";
var funcName1 = "- responseString";
var err = ObjC.classes.NSError.alloc();
var hook1 = eval('ObjC.classes.' + className1 + '["' + funcName1 + '"]');
console.log("[*] Class Name: " + className1);
console.log("[*] Method Name: " + funcName1);
Interceptor.attach(hook1.implementation, {
onEnter: function(args) {
},
onLeave: function(retval) {
var re = new ObjC.Object(retval);
send({type: 'RESP', data: re.toString()});
var op = recv('NEW_RESP', function(val) {
var new_data = val.payload;
var new_ret = ObjC.classes.NSString.stringWithString_(new_data);
retval.replace(new_ret);
});
op.wait();
}
});
}
catch(err){
console.log("[!] Exception2: " + err.message);
}
''')
def on_message(message, data):
if message['type'] == 'send':
payload = message['payload']
_type, data = payload['type'], payload['data']
if _type == 'REQ':
data = str(data)
r = requests.request('REQUEST', 'http://127.0.0.1:{}/'.format(ECHO_PORT),
proxies={'http': 'http://127.0.0.1:{}'.format(BURP_PORT)},
data=data.encode('utf-8'))
script.post({'type': 'NEW_REQ', 'payload': r.text})
elif _type == 'RESP':
r = requests.request('RESPONSE', 'http://127.0.0.1:{}/'.format(ECHO_PORT),
proxies={'http': 'http://127.0.0.1:{}'.format(BURP_PORT)},
data=data.encode('utf-8'))
script.post({'type': 'NEW_RESP', 'payload': r.text})
script.on('message', on_message)
script.load()
sys.stdin.read()