This sample uses the same code as Detecting Frida Hooks Before Sensitive Cryptographic Operations, which encrypts and decrypts a sensitive API key using CommonCrypto's CCCrypt. The code includes a runtime hook detection mechanism that probes 127.0.0.1:27042 with a D-Bus AUTH message and terminates via exit(0) if a D-Bus endpoint responds. This demo demonstrates bypassing the detection by hooking connect() to block connections to Frida's default port, causing detectHooking() to return false so the termination path is never reached.
The output shows that the connect() call to a Frida port was blocked, followed by two CCCrypt calls found at runtime. The encryption call reveals the sensitive API key as plaintext input, and the decryption call reveals the same API key as plaintext output.
[+]connect()hooked:filteringFridaD-Busports[+]CCCrypthooked:extractingsensitivecryptographicdata[*]Blockingconnect()tolocalhost:27042[*]Blockingconnect()tolocalhost:27042[*]CCCryptcalledOperation:kCCEncryptAlgorithm:kCCAlgorithmAESInput:sk-OWASP-MAS-SuperSecretKey-1234567890Returnstatus:0Output:0xd83622ca61af7dd4b1ba514a2ab2dc21d4b0a4ac7362bddeea3411f5708b13f5369f4e3a6a547afe02bf844af5fc0d24Backtrace:0x1007cfe2cMASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1007d0a9cMASTestApp.debug.dylib!partialapplyforclosure#1 in closure #1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1c7a19f50Foundation!Data.InlineSlice.withUnsafeBytes<A>(_:)0x1c7a13ed4Foundation!Data.withUnsafeBytes<A>(_:)0x1007cfc38MASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1007d0a20MASTestApp.debug.dylib!partialapplyforclosure#1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1c7a19f50Foundation!Data.InlineSlice.withUnsafeBytes<A>(_:)0x1c7a13ed4Foundation!Data.withUnsafeBytes<A>(_:)[*]Blockingconnect()tolocalhost:27042[*]CCCryptcalledOperation:kCCDecryptAlgorithm:kCCAlgorithmAESInput:0xd83622ca61af7dd4b1ba514a2ab2dc21d4b0a4ac7362bddeea3411f5708b13f5369f4e3a6a547afe02bf844af5fc0d24Returnstatus:0Output:sk-OWASP-MAS-SuperSecretKey-1234567890Backtrace:0x1007cfe2cMASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1007d0a9cMASTestApp.debug.dylib!partialapplyforclosure#1 in closure #1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1c7a19f50Foundation!Data.InlineSlice.withUnsafeBytes<A>(_:)0x1c7a13ed4Foundation!Data.withUnsafeBytes<A>(_:)0x1007cfc38MASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1007d0a20MASTestApp.debug.dylib!partialapplyforclosure#1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x1c7a19f50Foundation!Data.InlineSlice.withUnsafeBytes<A>(_:)0x1c7a13ed4Foundation!Data.withUnsafeBytes<A>(_:)
The test case fails because the connect() hook successfully prevented the D-Bus port detection from reaching Frida's endpoint, causing detectHooking() to return false. With detection bypassed, the app proceeded with its cryptographic operations, which were intercepted by the CCCrypt hooks to extract the sensitive API key sk-OWASP-MAS-SuperSecretKey-1234567890 in plaintext.