-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture.js
74 lines (63 loc) · 2.16 KB
/
capture.js
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
const mongo = require("mongodb").MongoClient;
const url = "mongodb://******:49159";
const dbName = "anyproxy";
module.exports = {
summary: 'a rule to hack response',
flist: ['getGlobalData', 'init', 'xiangxiangapps.com/index'],
* beforeSendRequest(requestDetail) {
const key = 'pid'
if (requestDetail.requestOptions.method === 'GET') {
let u = new URL(requestDetail.url);
u.searchParams.set(key, 'hello')
requestDetail.url = u.toString()
} else {
let reqBody = requestDetail.requestData;
const r = tryParse(reqBody.toString())
const newBody = JSON.stringify(r)
const n = Buffer.from(newBody)
requestDetail.requestData = n
}
},
* beforeSendResponse(requestDetail, responseDetail) {
for (let l of this.flist) {
if (requestDetail.url.includes(l)) {
const b = {};
b.reqUrl = requestDetail.url
let reqBody = requestDetail.requestData;
b.reqBody = tryParse(reqBody.toString());
const resp = responseDetail.response
const respBody = tryParse(resp.body.toString())
if (requestDetail.url.includes('getGlobalData')) {
respBody.data.appver.AndroidForce = 0
} else if (requestDetail.url.includes('init')) {
respBody.data.globalData.appver.AndroidForce = 0
respBody.data.appver.AndroidForce = 0
}
const newBody = JSON.stringify(respBody)
const n = Buffer.from(newBody)
b.respBody = respBody
yield logger.info(b);
resp.body = n
return {response: resp};
}
}
}
}
function tryParse(str) {
try {
return JSON.parse(str);
} catch (e) {
return str;
}
}
const logger = {
info: function* (msg) {
console.info(msg)
yield mian(msg)
}
}
function* mian(msg) {
const client = yield mongo.connect(url)
const s = client.db("anyproxy").collection("xx");
yield s.insertOne(msg)
}