socket activity #refactoring

This commit is contained in:
iddoeldor 2019-04-17 15:14:14 +03:00 committed by GitHub
parent 11fce7c847
commit 2b87e7e6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,15 +67,19 @@
#### Socket activity
```js
var socketFunctionPrefixes = ['connect', 'recv', 'send', 'read', 'write'];
function isSocketFunction(name) {
return socketFunctionPrefixes.some(function (prefix) {
return name.indexOf(prefix) === 0;
});
}
var libcPath = Process.enumerateModulesSync().filter(function(m){return m.name.indexOf('libc.so')!=-1})[0].path; // on iOS (darwin) instead of libc search for libSystem.B.dylib
Module.enumerateExportsSync(libcPath).forEach(function(ex){
if (ex.type === 'function' && isSocketFunction(ex.name)) {
Module.enumerateExportsSync(
// finding socket module path
Process.enumerateModulesSync().filter(function(m){·
return m.name === { linux: 'libc.so', darnwin: 'libSystem.B.dylib', windows: 'ws2_32.dll' }[Process.platform]
})[0].path
).forEach(function(ex){
if (
ex.type === 'function' &&·
// if function contains the prefix of one of the socket related functions
['connect', 'recv', 'send', 'read', 'write'].some(function(prefix) {
return ex.name.indexOf(prefix) === 0
})
) {
Interceptor.attach(ex.address, {
onEnter: function (args) {
this.fd = args[0].toInt32();
@ -91,7 +95,7 @@
}
});
}
});
});
```
<details>
@ -100,15 +104,19 @@
Android example
```
Java.perform(function(){
var socketFunctionPrefixes = ['connect', 'recv', 'send', 'read', 'write'];
function isSocketFunction(name) {
return socketFunctionPrefixes.some(function (prefix) {
return name.indexOf(prefix) === 0;
});
}
var libcPath = Process.enumerateModulesSync().filter(function(m){return m.name.indexOf('libc.so')!=-1})[0].path;
Module.enumerateExportsSync(libcPath).forEach(function(ex){
if (ex.type === 'function' && isSocketFunction(ex.name)) {
Module.enumerateExportsSync(
// finding socket module path
Process.enumerateModulesSync().filter(function(m){·
return m.name === { linux: 'libc.so', darnwin: 'libSystem.B.dylib', windows: 'ws2_32.dll' }[Process.platform]
})[0].path
).forEach(function(ex){
if (
ex.type === 'function' &&·
// if function contains the prefix of one of the socket related functions
['connect', 'recv', 'send', 'read', 'write'].some(function(prefix) {
return ex.name.indexOf(prefix) === 0
})
) {
Interceptor.attach(ex.address, {
onEnter: function (args) {
this.fd = args[0].toInt32();
@ -124,7 +132,7 @@ Java.perform(function(){
}
});
}
});
});
});
```
```sh