Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Hook socket APIs

  • Loading branch information...
commit e051573795bbcbc59ec9bd2861ac7128d927a637 1 parent 065cbc5
Ole André Vadla Ravnås oleavr authored
Showing with 48 additions and 0 deletions.
  1. +48 0 agent.js
48 agent.js
View
@@ -25,3 +25,51 @@ send({
threadId: Process.getCurrentThreadId()
}
});
+
+var socketModule = {
+ "windows": "ws2_32.dll",
+ "darwin": "libSystem.B.dylib",
+ "linux": "libc-2.19.so"
+};
+var socketFunctionPrefixes = [
+ "connect",
+ "recv",
+ "send",
+ "read",
+ "write"
+];
+function isSocketFunction(name) {
+ return socketFunctionPrefixes.some(function (prefix) {
+ return name.indexOf(prefix) === 0;
+ });
+}
+Module.enumerateExports(socketModule[Process.platform], {
+ onMatch: function (exp) {
+ if (exp.type === "function"
+ && isSocketFunction(exp.name)) {
+ Interceptor.attach(exp.address, {
+ onEnter: function (args) {
+ this.fd = args[0].toInt32();
+ },
+ onLeave: function (retval) {
+ var fd = this.fd;
+ if (Socket.type(fd) !== "tcp")
+ return;
+ var address = Socket.peerAddress(fd);
+ if (address === null)
+ return;
+ send({
+ name: "socket-activity",
+ payload: {
+ fd: fd,
+ func: exp.name,
+ address: address
+ }
+ });
+ }
+ });
+ }
+ },
+ onComplete: function () {
+ }
+});
Please sign in to comment.
Something went wrong with that request. Please try again.