From 78fa288d464bc2b4cc36150d012f51057d92fff4 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 15 Nov 2023 18:39:51 +0100 Subject: [PATCH] Revert "Always loudly log intercepted connections that fail to reach the proxy" This reverts commit 6eec741f5c6842916a9158c2d9c98592703dfb16. This doensn't actually work correctly, as connect() will return -1 (treated here as failure) for sockets that are still in progress, when opened non-blocking, and therefore we end up logging these as failures. We need to handle async connection state detection - that's a bit fiddly from inside Frida, so for now let's just roll this back. --- native-connect-hook.js | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/native-connect-hook.js b/native-connect-hook.js index 5ffbd1b..caa9209 100644 --- a/native-connect-hook.js +++ b/native-connect-hook.js @@ -58,10 +58,7 @@ if (!connectFn) { // Should always be set, but just in case : PROXY_HOST_IPv4_BYTES ); - if (isIntercepted) { - this.intercepted = true; - return; - } + if (isIntercepted) return; if (!shouldBeIntercepted) { // Not intercecpted, sent to unrecognized port - probably not HTTP(S) @@ -91,33 +88,22 @@ if (!connectFn) { // Should always be set, but just in case // Skip 4 bytes: 2 family, 2 port addrPtr.add(4).writeByteArray(PROXY_HOST_IPv4_BYTES); } - this.intercepted = true; } else if (DEBUG_MODE) { console.log(`Ignoring ${sockType} connection`); + this.ignored = true; } // N.b. we ignore all non-TCP connections: both UDP and Unix streams }, onLeave: function (result) { - if (!this.intercepted) return; // Don't log about connections we don't touch. - const wasSuccessful = result.toInt32() === 0; - - if (wasSuccessful && !DEBUG_MODE) return; + if (!DEBUG_MODE || this.ignored) return; const fd = this.sockFd; const sockType = Socket.type(fd); const address = Socket.peerAddress(fd); - - if (wasSuccessful) { - console.debug( - `Connected ${sockType} fd ${fd} to ${JSON.stringify(address)} (${result.toInt32()})` - ); - } else { - console.error( - `\n !!! --- Intercepted ${sockType} connection ${fd} failed when redirected to proxy ${PROXY_HOST}:${PROXY_PORT} --- !!!\n` + - ` Is your proxy configured correctly?\n` - ); - } + console.debug( + `Connected ${sockType} fd ${fd} to ${JSON.stringify(address)} (${result.toInt32()})` + ); } });