-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcatch_socket.js
62 lines (50 loc) · 1.89 KB
/
catch_socket.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
const AF_INET = 2;
const AF_INET6 = 10;
var sockets = {};
var sockets_message = {};
var calculate_offset = (address) => {
var modules = Process.enumerateModules();
for (let index = 0; index < modules.length; index++) {
const module = modules[index];
console.log("Module [" + module.name + "], offset: " + module.base + " end: " + module.base.add(module.size));
if (address >= module.base && address <= module.base.add(module.size)) {
console.log(module.name);
return address.sub(module.base);
}
}
return undefined;
}
var find_library = (address) => {
var modules = Process.enumerateModules();
for (let index = 0; index < modules.length; index++) {
const module = modules[index];
// console.log("Module [" + module.name + "], offset: " + module.base + " end: " + module.base.add(module.size));
if (address >= module.base && address <= module.base.add(module.size)) {
return module.name;
}
}
return undefined;
}
Interceptor.attach(Module.findExportByName("libc.so", "socket"), {
// int socket(int domain, int type, int protocol);
onEnter: function (args) {
this.domain = args[0];
this.type = args[1];
this.protocol = args[2];
this.inet = false;
if (this.domain == AF_INET || this.domain == AF_INET6) {
this.inet = true;
console.log('socket(' + this.domain + ", " + this.type + ", " + this.protocol + ")");
console.log(find_library(this.returnAddress));
// console.log('Context : ' + JSON.stringify(this.context));
// console.log('Return : ' + this.returnAddress);
console.log();
}
},
onLeave: function (retval) {
if (this.inet) {
sockets[retval] = [this.domain, this.type, this.protocol];
}
return retval;
}
});