-
-
Save rwestergren/6c05c0feb7c7d009b9de3f5fca324fb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Flutter TLS Bypass + Socket Observation Script | |
| * | |
| * This script: | |
| * 1. Disables Flutter's TLS certificate verification (from NVISO's disable-flutter-tls-verification) | |
| * 2. Hooks connect() to observe all socket connections made by the app | |
| * | |
| * Usage: frida -U -n "AppName" -l flutter-intercept.js | |
| */ | |
| // ============================================================================ | |
| // CONFIGURATION | |
| // ============================================================================ | |
| // Proxy configuration - will be detected from system settings | |
| var PROXY_HOST = null; | |
| var PROXY_PORT = null; | |
| var proxyDetected = false; | |
| var proxyDetectionFailed = false; | |
| // Hostnames to redirect through proxy | |
| var PROXY_TARGETS = [ | |
| "mobile.cronometer.com" | |
| ]; | |
| // Configuration object containing patterns to locate the ssl_verify_peer_cert function | |
| var config = { | |
| "ios": { | |
| "modulename": "Flutter", | |
| "patterns": { | |
| "arm64": [ | |
| "FF 83 01 D1 FA 67 01 A9 F8 5F 02 A9 F6 57 03 A9 F4 4F 04 A9 FD 7B 05 A9 FD 43 01 91 F4 03 00 AA 68 31 00 F0 08 01 40 F9 08 01 40 F9 E8 07 00 F9", | |
| "FF 83 01 D1 FA 67 01 A9 F8 5F 02 A9 F6 57 03 A9 F4 4F 04 A9 FD 7B 05 A9 FD 43 01 91 F? 03 00 AA ?? 0? 40 F? ?8 ?? 40 F9 ?? ?? 4? F9 ?? 00 00", | |
| "FF 43 01 D1 F8 5F 01 A9 F6 57 02 A9 F4 4F 03 A9 FD 7B 04 A9 FD 03 01 91 F3 03 00 AA 14 00 40 F9 88 1A 40 F9 15 E9 40 F9 B5 00 00 B4 B6 46 40 F9" | |
| ], | |
| }, | |
| }, | |
| "android": { | |
| "modulename": "libflutter.so", | |
| "patterns": { | |
| "arm64": [ | |
| "F? 0F 1C F8 F? 5? 01 A9 F? 5? 02 A9 F? ?? 03 A9 ?? ?? ?? ?? 68 1A 40 F9", | |
| "F? 43 01 D1 FE 67 01 A9 F8 5F 02 A9 F6 57 03 A9 F4 4F 04 A9 13 00 40 F9 F4 03 00 AA 68 1A 40 F9", | |
| "FF 43 01 D1 FE 67 01 A9 ?? ?? 06 94 ?? 7? 06 94 68 1A 40 F9 15 15 41 F9 B5 00 00 B4 B6 4A 40 F9", | |
| ], | |
| "arm": [ | |
| "2D E9 F? 4? D0 F8 00 80 81 46 D8 F8 18 00 D0 F8", | |
| ], | |
| "x64": [ | |
| "55 41 57 41 56 41 55 41 54 53 50 49 89 F? 4? 8B ?? 4? 8B 4? 30 4C 8B ?? ?? 0? 00 00 4D 85 ?? 74 1? 4D 8B", | |
| "55 41 57 41 56 41 55 41 54 53 48 83 EC 18 49 89 FF 48 8B 1F 48 8B 43 30 4C 8B A0 28 02 00 00 4D 85 E4 74", | |
| "55 41 57 41 56 41 55 41 54 53 48 83 EC 18 49 89 FE 4C 8B 27 49 8B 44 24 30 48 8B 98 D0 01 00 00 48 85 DB" | |
| ], | |
| "x86": [ | |
| "55 89 E5 53 57 56 83 E4 F0 83 EC 20 E8 00 00 00 00 5B 81 C3 2B 79 66 00 8B 7D 08 8B 17 8B 42 18 8B 80 88 01" | |
| ] | |
| } | |
| }, | |
| "windows": { | |
| "modulename": "flutter_windows.dll", | |
| "patterns": { | |
| "x64": [ | |
| "41 57 41 56 41 55 41 54 56 57 53 48 83 EC 40 4? 89 CF 48 8B 05 ?? ?? ?? 00 48 31 E0 48 89 44 24 38 4? 8B 31 4? 8B", | |
| "41 57 41 56 41 55 41 54 56 57 55 53 48 83 EC 38 48 89 CF 48 8B 05 20 45 C6 00 48 31 E0 48 89 44 24 30 48 8B 31 48", | |
| ] | |
| } | |
| }, | |
| "linux": { | |
| "modulename": "libflutter_linux_gtk.so", | |
| "patterns": { | |
| "x64": [ | |
| "55 41 57 41 56 41 55 41 54 53 48 83 EC 18 49 89 FE 4C 8B 27 49 8B 44 24 30 48 8B 98 D0 01 00 00 48 85 DB" | |
| ] | |
| } | |
| } | |
| }; | |
| // ============================================================================ | |
| // SOCKET CONSTANTS | |
| // ============================================================================ | |
| var AF_INET = 2; | |
| var AF_INET6 = 10; | |
| var AF_UNIX = 1; | |
| // ============================================================================ | |
| // DNS MAPPING | |
| // ============================================================================ | |
| // Map to store IP -> hostname mappings from DNS lookups | |
| var dnsCache = {}; | |
| // Map to track pending DNS lookups (hostname -> timestamp) | |
| var pendingLookups = {}; | |
| // ============================================================================ | |
| // INITIALIZATION | |
| // ============================================================================ | |
| console.log("=".repeat(60)); | |
| console.log("[*] Flutter TLS Bypass + Socket Observer + DNS Tracking"); | |
| console.log("[*] Pattern version: May 19 2025"); | |
| console.log("[*] Arch: " + Process.arch); | |
| console.log("[*] Platform: " + Process.platform); | |
| console.log("=".repeat(60)); | |
| // State tracking | |
| var TLSValidationDisabled = false; | |
| var flutterLibraryFound = false; | |
| var tries = 0; | |
| var maxTries = 5; | |
| var timeout = 1000; | |
| var androidBypass = false; | |
| var connectHooked = false; | |
| var dnsHooked = false; | |
| // Start proxy detection - wait for Java to be ready | |
| console.log("[*] Waiting for Java runtime..."); | |
| Java.perform(function() { | |
| console.log("[*] Java runtime ready, detecting system proxy..."); | |
| detectSystemProxy(); | |
| }); | |
| // ============================================================================ | |
| // PROXY DETECTION | |
| // ============================================================================ | |
| function detectSystemProxy() { | |
| try { | |
| var Settings = Java.use("android.provider.Settings$Global"); | |
| var ActivityThread = Java.use("android.app.ActivityThread"); | |
| var app = ActivityThread.currentApplication(); | |
| if (!app) { | |
| console.log("[!] App context not ready yet, retrying in 100ms..."); | |
| setTimeout(detectSystemProxy, 100); | |
| return; | |
| } | |
| var context = app.getApplicationContext(); | |
| if (!context) { | |
| console.log("[!] App context not ready yet, retrying in 100ms..."); | |
| setTimeout(detectSystemProxy, 100); | |
| return; | |
| } | |
| var contentResolver = context.getContentResolver(); | |
| var proxy = Settings.getString(contentResolver, "http_proxy"); | |
| if (proxy && proxy.indexOf(":") !== -1) { | |
| var parts = proxy.split(":"); | |
| PROXY_HOST = parts[0]; | |
| PROXY_PORT = parseInt(parts[1]); | |
| console.log("[+] Detected system proxy: " + PROXY_HOST + ":" + PROXY_PORT); | |
| proxyDetected = true; | |
| // Now that proxy is detected, start the hooks | |
| initializeHooks(); | |
| } else { | |
| console.log("[!] ERROR: No system proxy configured!"); | |
| console.log("[!] Set proxy via: Settings > Wi-Fi > [network] > Proxy"); | |
| proxyDetectionFailed = true; | |
| } | |
| } catch (e) { | |
| console.log("[!] Error detecting proxy, retrying in 100ms... (" + e + ")"); | |
| setTimeout(detectSystemProxy, 100); | |
| } | |
| } | |
| function initializeHooks() { | |
| hookDns(); | |
| hookConnect(); | |
| waitForTLSBypass(); | |
| console.log("[*] Initialization complete. Waiting for connections..."); | |
| } | |
| // ============================================================================ | |
| // DNS RESOLUTION HOOKING | |
| // ============================================================================ | |
| function hookDns() { | |
| if (dnsHooked) return; | |
| var libc = Process.getModuleByName("libc.so"); | |
| // Hook getaddrinfo - this is the main entry point | |
| // getaddrinfo calls android_getaddrinfofornetcontext internally | |
| var getaddrinfoPtr = libc.findExportByName("getaddrinfo"); | |
| if (getaddrinfoPtr) { | |
| console.log("[+] Hooking getaddrinfo() at " + getaddrinfoPtr); | |
| Interceptor.attach(getaddrinfoPtr, { | |
| onEnter: function(args) { | |
| var hostPtr = ptr(args[0]); | |
| if (!hostPtr.isNull()) { | |
| this.hostname = hostPtr.readCString(); | |
| // Skip if it's already an IP address | |
| if (/^\d+\.\d+\.\d+\.\d+$/.test(this.hostname)) { | |
| this.hostname = null; | |
| return; | |
| } | |
| this.resPtr = args[3]; // struct addrinfo **res | |
| } else { | |
| this.hostname = null; | |
| } | |
| }, | |
| onLeave: function(retval) { | |
| if (retval.toInt32() !== 0 || !this.hostname || !this.resPtr) { | |
| return; | |
| } | |
| try { | |
| parseAddrinfo(this.hostname, ptr(this.resPtr)); | |
| } catch (e) { | |
| console.log("[DNS] Error parsing result for " + this.hostname + ": " + e); | |
| } | |
| } | |
| }); | |
| console.log("[+] getaddrinfo() hook installed"); | |
| } | |
| dnsHooked = true; | |
| } | |
| function parseAddrinfo(hostname, resPtrPtr) { | |
| // resPtrPtr is struct addrinfo **res, so we need to dereference twice | |
| var resPtr = resPtrPtr.readPointer(); | |
| if (resPtr.isNull()) { | |
| return; | |
| } | |
| var addrInfo = ptr(resPtr); | |
| var count = 0; | |
| while (!addrInfo.isNull() && count < 10) { | |
| count++; | |
| // struct addrinfo on Android arm64 (empirically determined): | |
| // int ai_flags; // 0 | |
| // int ai_family; // 4 | |
| // int ai_socktype; // 8 | |
| // int ai_protocol; // 12 | |
| // socklen_t ai_addrlen; // 16 | |
| // (padding) // 20-23 | |
| // (padding/unused) // 24-31 | |
| // struct sockaddr *ai_addr; // 32 <-- NOT 24! | |
| // struct addrinfo *ai_next; // 40 | |
| var ai_family = addrInfo.add(4).readS32(); | |
| var ai_addr = addrInfo.add(32).readPointer(); // Offset 32, not 24 | |
| if (!ai_addr.isNull()) { | |
| if (ai_family === AF_INET) { | |
| // struct sockaddr_in: family(2) + port(2) + addr(4) | |
| var addr = ntohl(ai_addr.add(4).readU32()); | |
| var ip = int2ip(addr); | |
| dnsCache[ip] = hostname; | |
| console.log("[DNS] " + hostname + " -> " + ip); | |
| } else if (ai_family === AF_INET6) { | |
| // struct sockaddr_in6: family(2) + port(2) + flowinfo(4) + addr(16) | |
| var addrBytes = ai_addr.add(8).readByteArray(16); | |
| var ip = bytes2ipv6(addrBytes); | |
| dnsCache[ip] = hostname; | |
| // Also check for IPv4-mapped IPv6 | |
| var ipv4 = ipv6ToIpv4Mapped(addrBytes); | |
| if (ipv4) { | |
| dnsCache[ipv4] = hostname; | |
| console.log("[DNS] " + hostname + " -> " + ipv4 + " (from IPv6)"); | |
| } else { | |
| console.log("[DNS] " + hostname + " -> " + ip); | |
| } | |
| } | |
| } | |
| // Move to next in linked list (offset 40) | |
| var nextPtr = addrInfo.add(40).readPointer(); | |
| if (nextPtr.isNull()) { | |
| break; | |
| } | |
| addrInfo = ptr(nextPtr); | |
| } | |
| } | |
| // Helper to extract IPv4 from IPv4-mapped IPv6 address | |
| function ipv6ToIpv4Mapped(bytes) { | |
| var arr = new Uint8Array(bytes); | |
| // Check for ::ffff:x.x.x.x pattern (IPv4-mapped IPv6) | |
| var isIpv4Mapped = true; | |
| for (var i = 0; i < 10; i++) { | |
| if (arr[i] !== 0) { | |
| isIpv4Mapped = false; | |
| break; | |
| } | |
| } | |
| if (isIpv4Mapped && arr[10] === 0xff && arr[11] === 0xff) { | |
| return arr[12] + "." + arr[13] + "." + arr[14] + "." + arr[15]; | |
| } | |
| return null; | |
| } | |
| // Lookup hostname from IP in DNS cache | |
| function lookupHostname(ip) { | |
| if (ip in dnsCache) { | |
| return dnsCache[ip]; | |
| } | |
| return null; | |
| } | |
| // ============================================================================ | |
| // SOCKET OBSERVATION + PROXY REDIRECTION - Hook connect() | |
| // ============================================================================ | |
| // Track connections that need CONNECT handshake | |
| var pendingConnects = {}; // fd -> {hostname, port} | |
| // Native functions - initialized lazily | |
| var _sendFunc = null; | |
| var _recvFunc = null; | |
| var _pollFunc = null; | |
| function getSendFunc() { | |
| if (_sendFunc === null) { | |
| var libc = Process.getModuleByName("libc.so"); | |
| _sendFunc = new NativeFunction(libc.findExportByName("send"), 'int64', ['int', 'pointer', 'size_t', 'int']); | |
| } | |
| return _sendFunc; | |
| } | |
| function getRecvFunc() { | |
| if (_recvFunc === null) { | |
| var libc = Process.getModuleByName("libc.so"); | |
| _recvFunc = new NativeFunction(libc.findExportByName("recv"), 'int64', ['int', 'pointer', 'size_t', 'int']); | |
| } | |
| return _recvFunc; | |
| } | |
| function getPollFunc() { | |
| if (_pollFunc === null) { | |
| var libc = Process.getModuleByName("libc.so"); | |
| _pollFunc = new NativeFunction(libc.findExportByName("poll"), 'int', ['pointer', 'uint', 'int']); | |
| } | |
| return _pollFunc; | |
| } | |
| function shouldRedirectToProxy(hostname) { | |
| if (!hostname) return false; | |
| // Don't redirect until proxy is detected and TLS bypass is active! | |
| if (!proxyDetected || !TLSValidationDisabled) { | |
| return false; | |
| } | |
| for (var i = 0; i < PROXY_TARGETS.length; i++) { | |
| if (hostname === PROXY_TARGETS[i]) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| function hookConnect() { | |
| if (connectHooked) return; | |
| var libc = Process.getModuleByName("libc.so"); | |
| var connectPtr = libc.findExportByName("connect"); | |
| if (connectPtr === null) { | |
| console.log("[!] Could not find connect() function in libc"); | |
| return; | |
| } | |
| console.log("[+] Hooking connect() at " + connectPtr); | |
| console.log("[+] Proxy target: " + PROXY_HOST + ":" + PROXY_PORT); | |
| console.log("[+] Redirecting: " + PROXY_TARGETS.join(", ")); | |
| Interceptor.attach(connectPtr, { | |
| onEnter: function(args) { | |
| this.fd = args[0].toInt32(); | |
| this.sockaddr = ptr(args[1]); | |
| this.addrlen = args[2].toInt32(); | |
| this.redirected = false; | |
| this.targetHostname = null; | |
| this.targetPort = null; | |
| try { | |
| var family = this.sockaddr.readU16(); | |
| this.family = family; | |
| if (family === AF_UNIX) { | |
| this.ip = null; | |
| this.port = null; | |
| return; | |
| } | |
| if (family === AF_INET) { | |
| var port = ntohs(this.sockaddr.add(2).readU16()); | |
| var addr = ntohl(this.sockaddr.add(4).readU32()); | |
| var ip = int2ip(addr); | |
| this.ip = ip; | |
| this.port = port; | |
| var hostname = lookupHostname(ip); | |
| if (shouldRedirectToProxy(hostname)) { | |
| // Store original target for CONNECT | |
| this.targetHostname = hostname; | |
| this.targetPort = port; | |
| // Rewrite sockaddr to point to proxy | |
| var proxyAddr = htonl(ip2int(PROXY_HOST)); | |
| var proxyPort = htons(PROXY_PORT); | |
| this.sockaddr.add(2).writeU16(proxyPort); | |
| this.sockaddr.add(4).writeU32(proxyAddr); | |
| this.redirected = true; | |
| console.log("[REDIRECT] " + hostname + " (" + ip + "):" + port + " -> " + PROXY_HOST + ":" + PROXY_PORT); | |
| } else if (hostname) { | |
| console.log("[CONNECT] " + hostname + " (" + ip + "):" + port); | |
| } else { | |
| console.log("[CONNECT] " + ip + ":" + port); | |
| } | |
| } else if (family === AF_INET6) { | |
| var port = ntohs(this.sockaddr.add(2).readU16()); | |
| var addrBytes = this.sockaddr.add(8).readByteArray(16); | |
| var ip = bytes2ipv6(addrBytes); | |
| this.ip = ip; | |
| this.port = port; | |
| var ipv4Mapped = ipv6ToIpv4Mapped(addrBytes); | |
| var hostname = lookupHostname(ip); | |
| if (!hostname && ipv4Mapped) { | |
| hostname = lookupHostname(ipv4Mapped); | |
| } | |
| if (shouldRedirectToProxy(hostname)) { | |
| // Store original target for CONNECT | |
| this.targetHostname = hostname; | |
| this.targetPort = port; | |
| // Rewrite to proxy (IPv4-mapped) | |
| var proxyPort = htons(PROXY_PORT); | |
| this.sockaddr.add(2).writeU16(proxyPort); | |
| var proxyIpParts = PROXY_HOST.split("."); | |
| var ipv6Bytes = [ | |
| 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 0xff, 0xff, | |
| parseInt(proxyIpParts[0]), | |
| parseInt(proxyIpParts[1]), | |
| parseInt(proxyIpParts[2]), | |
| parseInt(proxyIpParts[3]) | |
| ]; | |
| for (var i = 0; i < 16; i++) { | |
| this.sockaddr.add(8 + i).writeU8(ipv6Bytes[i]); | |
| } | |
| this.redirected = true; | |
| var displayIp = ipv4Mapped || ip; | |
| console.log("[REDIRECT] " + hostname + " (" + displayIp + "):" + port + " -> " + PROXY_HOST + ":" + PROXY_PORT); | |
| } else if (hostname) { | |
| if (ipv4Mapped) { | |
| console.log("[CONNECT] " + hostname + " (" + ipv4Mapped + "):" + port); | |
| } else { | |
| console.log("[CONNECT] " + hostname + " ([" + ip + "]):" + port); | |
| } | |
| } else { | |
| if (ipv4Mapped) { | |
| console.log("[CONNECT] " + ipv4Mapped + ":" + port + " (IPv4-mapped)"); | |
| } else { | |
| console.log("[CONNECT] [" + ip + "]:" + port); | |
| } | |
| } | |
| } else { | |
| this.ip = null; | |
| this.port = null; | |
| } | |
| } catch (e) { | |
| this.ip = null; | |
| this.port = null; | |
| console.log("[CONNECT] Error parsing sockaddr: " + e); | |
| } | |
| }, | |
| onLeave: function(retval) { | |
| if (!this.redirected || !this.targetHostname) return; | |
| var result = retval.toInt32(); | |
| if (result === 0) { | |
| // Blocking socket - connected immediately, do CONNECT now | |
| console.log("[PROXY] Connection established (blocking), sending CONNECT"); | |
| doHttpConnect(this.fd, this.targetHostname, this.targetPort); | |
| } else if (result === -1) { | |
| // Non-blocking socket - need to wait for connection, then do CONNECT | |
| // Use poll() to wait for socket to be writable | |
| console.log("[PROXY] Waiting for non-blocking connect to complete..."); | |
| if (waitForConnect(this.fd, 5000)) { | |
| console.log("[PROXY] Connection ready, sending CONNECT"); | |
| doHttpConnect(this.fd, this.targetHostname, this.targetPort); | |
| } else { | |
| console.log("[PROXY] Timeout waiting for connection"); | |
| } | |
| } | |
| } | |
| }); | |
| connectHooked = true; | |
| console.log("[+] connect() hook installed"); | |
| } | |
| function waitForConnect(fd, timeoutMs) { | |
| var pollFunc = getPollFunc(); | |
| // struct pollfd { int fd; short events; short revents; } | |
| // Size: 8 bytes on most platforms | |
| var POLLOUT = 4; | |
| var POLLERR = 8; | |
| var POLLHUP = 16; | |
| var pollfd = Memory.alloc(8); | |
| pollfd.writeS32(fd); // fd | |
| pollfd.add(4).writeS16(POLLOUT); // events - wait for writable | |
| pollfd.add(6).writeS16(0); // revents | |
| var ret = pollFunc(pollfd, 1, timeoutMs); | |
| if (ret > 0) { | |
| var revents = pollfd.add(6).readS16(); | |
| if (revents & POLLOUT) { | |
| return true; // Socket is writable (connected) | |
| } | |
| if (revents & (POLLERR | POLLHUP)) { | |
| console.log("[PROXY] Poll error: revents=" + revents); | |
| return false; | |
| } | |
| } else if (ret === 0) { | |
| console.log("[PROXY] Poll timeout"); | |
| } else { | |
| console.log("[PROXY] Poll error: " + ret); | |
| } | |
| return false; | |
| } | |
| function doHttpConnect(fd, hostname, port) { | |
| var sendFunc = getSendFunc(); | |
| var recvFunc = getRecvFunc(); | |
| var pollFunc = getPollFunc(); | |
| var connectRequest = "CONNECT " + hostname + ":" + port + " HTTP/1.1\r\n" + | |
| "Host: " + hostname + ":" + port + "\r\n" + | |
| "\r\n"; | |
| var requestBuf = Memory.allocUtf8String(connectRequest); | |
| var requestLen = connectRequest.length; | |
| console.log("[PROXY] Sending: CONNECT " + hostname + ":" + port); | |
| // Send CONNECT request | |
| var sent = sendFunc(fd, requestBuf, requestLen, 0); | |
| if (sent < 0) { | |
| console.log("[PROXY] Failed to send CONNECT request, errno might be EAGAIN"); | |
| return false; | |
| } | |
| console.log("[PROXY] Sent " + sent + " bytes"); | |
| // Wait for response using poll | |
| var POLLIN = 1; | |
| var pollfd = Memory.alloc(8); | |
| pollfd.writeS32(fd); | |
| pollfd.add(4).writeS16(POLLIN); | |
| pollfd.add(6).writeS16(0); | |
| var ret = pollFunc(pollfd, 1, 5000); // 5 second timeout | |
| if (ret <= 0) { | |
| console.log("[PROXY] Timeout waiting for CONNECT response"); | |
| return false; | |
| } | |
| // Read response | |
| var responseBuf = Memory.alloc(1024); | |
| var received = recvFunc(fd, responseBuf, 1023, 0); | |
| if (received > 0) { | |
| responseBuf.add(received).writeU8(0); // Null terminate | |
| var response = responseBuf.readUtf8String(); | |
| var statusLine = response.split("\r\n")[0]; | |
| if (response.indexOf("200") !== -1) { | |
| console.log("[PROXY] SUCCESS: " + statusLine); | |
| return true; | |
| } else { | |
| console.log("[PROXY] FAILED: " + statusLine); | |
| return false; | |
| } | |
| } else { | |
| console.log("[PROXY] No response received (recv returned " + received + ")"); | |
| return false; | |
| } | |
| } | |
| // ============================================================================ | |
| // HELPER FUNCTIONS | |
| // ============================================================================ | |
| function ntohs(n) { | |
| return ((n & 0xFF) << 8) | ((n >> 8) & 0xFF); | |
| } | |
| function htons(n) { | |
| return ((n & 0xFF) << 8) | ((n >> 8) & 0xFF); | |
| } | |
| function ntohl(n) { | |
| return (((n & 0xFF) << 24) | | |
| ((n & 0xFF00) << 8) | | |
| ((n >> 8) & 0xFF00) | | |
| ((n >> 24) & 0xFF)) >>> 0; // >>> 0 ensures unsigned | |
| } | |
| function htonl(n) { | |
| return (((n & 0xFF) << 24) | | |
| ((n & 0xFF00) << 8) | | |
| ((n >> 8) & 0xFF00) | | |
| ((n >> 24) & 0xFF)) >>> 0; // >>> 0 ensures unsigned | |
| } | |
| function int2ip(int) { | |
| return ((int >> 24) & 0xFF) + "." + | |
| ((int >> 16) & 0xFF) + "." + | |
| ((int >> 8) & 0xFF) + "." + | |
| (int & 0xFF); | |
| } | |
| function ip2int(ip) { | |
| var parts = ip.split("."); | |
| return ((parseInt(parts[0]) << 24) | | |
| (parseInt(parts[1]) << 16) | | |
| (parseInt(parts[2]) << 8) | | |
| parseInt(parts[3])) >>> 0; | |
| } | |
| function bytes2ipv6(bytes) { | |
| var arr = new Uint8Array(bytes); | |
| var parts = []; | |
| for (var i = 0; i < 16; i += 2) { | |
| parts.push(((arr[i] << 8) | arr[i + 1]).toString(16)); | |
| } | |
| return parts.join(":"); | |
| } | |
| // ============================================================================ | |
| // TLS BYPASS (from NVISO's disable-flutter-tls-verification) | |
| // ============================================================================ | |
| function waitForTLSBypass() { | |
| console.log("[*] Waiting for Flutter library to load before enabling proxy..."); | |
| var platformConfig = {}; | |
| if (Java.available) { | |
| platformConfig = config["android"]; | |
| } else if (ObjC.available) { | |
| platformConfig = config["ios"]; | |
| } else if (Process.platform in config) { | |
| platformConfig = config[Process.platform]; | |
| } else { | |
| console.log("[!] Platform not supported: " + Process.platform); | |
| return; | |
| } | |
| // Poll for Flutter library | |
| var checkInterval = setInterval(function() { | |
| var m = Process.findModuleByName(platformConfig["modulename"]); | |
| if (m !== null) { | |
| clearInterval(checkInterval); | |
| console.log("[+] Flutter library loaded: " + m.name); | |
| // Now find and patch ssl_verify_peer_cert | |
| if (!(Process.arch in platformConfig["patterns"])) { | |
| console.log("[!] Architecture not supported: " + Process.arch); | |
| return; | |
| } | |
| var ranges; | |
| if (Java.available) { | |
| ranges = Process.enumerateRanges({ protection: 'r-x' }).filter(isFlutterRange); | |
| } else { | |
| ranges = m.enumerateRanges('r-x'); | |
| } | |
| var patterns = platformConfig["patterns"][Process.arch]; | |
| var thumb = Java.available && Process.arch == "arm" ? 1 : 0; | |
| var patched = false; | |
| ranges.forEach(function(range) { | |
| patterns.forEach(function(pattern) { | |
| var matches = Memory.scanSync(range.base, range.size, pattern); | |
| matches.forEach(function(match) { | |
| var info = DebugSymbol.fromAddress(match.address); | |
| console.log("[+] ssl_verify_peer_cert found at: " + (info.name || match.address)); | |
| hook_ssl_verify_peer_cert(match.address.add(thumb)); | |
| console.log("[+] ssl_verify_peer_cert has been PATCHED - TLS bypass active!"); | |
| TLSValidationDisabled = true; | |
| patched = true; | |
| }); | |
| }); | |
| }); | |
| if (!patched) { | |
| console.log("[!] Warning: Could not find ssl_verify_peer_cert to patch"); | |
| } | |
| } | |
| }, 100); // Check every 100ms | |
| } | |
| function disableTLSValidation() { | |
| if (TLSValidationDisabled) return; | |
| tries++; | |
| // Figure out which patterns to use | |
| var platformConfig = {}; | |
| if (Java.available) { | |
| platformConfig = config["android"]; | |
| } else if (ObjC.available) { | |
| platformConfig = config["ios"]; | |
| } else if (Process.platform in config) { | |
| platformConfig = config[Process.platform]; | |
| } else { | |
| console.log("[!] Platform not supported: " + Process.platform); | |
| return; | |
| } | |
| var m = Process.findModuleByName(platformConfig["modulename"]); | |
| if (tries > maxTries && !androidBypass) { | |
| console.warn("[!] Flutter library not found after " + maxTries + " tries"); | |
| console.warn("[!] Enabling bypass mode..."); | |
| androidBypass = true; | |
| } | |
| if (m === null && !androidBypass) { | |
| console.log("[ ] Locating Flutter library " + tries + "/" + maxTries); | |
| setTimeout(disableTLSValidation, timeout); | |
| return; | |
| } | |
| if (m !== null && !flutterLibraryFound) { | |
| console.log("[+] Flutter library found: " + m.name); | |
| flutterLibraryFound = true; | |
| tries = 0; | |
| } | |
| if (!(Process.arch in platformConfig["patterns"])) { | |
| console.log("[!] Architecture not supported: " + Process.arch); | |
| return; | |
| } | |
| console.log("[ ] Locating ssl_verify_peer_cert " + tries + "/" + maxTries); | |
| var ranges; | |
| if (Java.available) { | |
| ranges = Process.enumerateRanges({ protection: 'r-x' }).filter(isFlutterRange); | |
| } else if (m !== null) { | |
| ranges = m.enumerateRanges('r-x'); | |
| } else { | |
| ranges = Process.enumerateRanges({ protection: 'r-x' }); | |
| } | |
| findAndPatch(ranges, platformConfig["patterns"][Process.arch], Java.available && Process.arch == "arm" ? 1 : 0); | |
| if (!TLSValidationDisabled) { | |
| if (tries >= maxTries) { | |
| console.warn("[!] Could not locate ssl_verify_peer_cert"); | |
| TLSValidationDisabled = true; // Give up | |
| } else { | |
| setTimeout(disableTLSValidation, timeout); | |
| } | |
| } | |
| } | |
| function findAndPatch(ranges, patterns, thumb) { | |
| ranges.forEach(function(range) { | |
| patterns.forEach(function(pattern) { | |
| var matches = Memory.scanSync(range.base, range.size, pattern); | |
| matches.forEach(function(match) { | |
| var info = DebugSymbol.fromAddress(match.address); | |
| console.log("[+] ssl_verify_peer_cert found at: " + (info.name || match.address)); | |
| TLSValidationDisabled = true; | |
| hook_ssl_verify_peer_cert(match.address.add(thumb)); | |
| console.log("[+] ssl_verify_peer_cert has been patched"); | |
| }); | |
| if (matches.length > 1) { | |
| console.log("[!] Warning: Multiple matches found"); | |
| } | |
| }); | |
| }); | |
| } | |
| function isFlutterRange(range) { | |
| if (androidBypass) return true; | |
| var info = DebugSymbol.fromAddress(range.base); | |
| if (info.moduleName !== null) { | |
| if (info.moduleName.toLowerCase().indexOf("flutter") !== -1) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| function hook_ssl_verify_peer_cert(address) { | |
| Interceptor.replace(address, new NativeCallback(function(pathPtr, flags) { | |
| return 0; | |
| }, 'int', ['pointer', 'int'])); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment