This sample encrypts and decrypts a sensitive API key using CommonCrypto's CCCrypt. The app does not implement any runtime hook detection mechanisms. On the contrary, Detecting Frida Hooks Before Sensitive Cryptographic Operations demonstrates a runtime hook detection mechanism.
Environment
This demo was built using Xcode 26.2.9 and tested on an iPhone running iOS 16.7.10 (jailbroken with Dopamine 2.4.9).
Note
This is a series of correlated tests.
This demo is a failed test (failed defense/successful attack) against a data exfiltration attack.
The output contains 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. Backtraces are also provided to help identify the locations in the code.
[+]CCCrypthooked:extractingsensitivecryptographicdata[*]CCCryptcalledOperation:kCCEncryptAlgorithm:kCCAlgorithmAESInput:sk-OWASP-MAS-SuperSecretKey-1234567890Returnstatus:0Output:0xcc2b9758f2c54f40c950c980d380804530a86f51b2e9ada2317aef5d0741b94a32c421e365ce47229349f313aed40d0bBacktrace:0x104689934MASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x104689b84MASTestApp.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>(_:)0x104689740MASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x104689b08MASTestApp.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>(_:)[*]CCCryptcalledOperation:kCCDecryptAlgorithm:kCCAlgorithmAESInput:0xcc2b9758f2c54f40c950c980d380804530a86f51b2e9ada2317aef5d0741b94a32c421e365ce47229349f313aed40d0bReturnstatus:0Output:sk-OWASP-MAS-SuperSecretKey-1234567890Backtrace:0x104689934MASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x104689b84MASTestApp.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>(_:)0x104689740MASTestApp.debug.dylib!closure#1 in closure #1 in closure #1 in static MastgTest.crypt(operation:data:key:iv:)0x104689b08MASTestApp.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 hook executes successfully and the sensitive API key sk-OWASP-MAS-SuperSecretKey-1234567890 is extracted in plaintext from the CCCrypt calls. The app lacks runtime integrity verification, allowing instrumentation tools to intercept cryptographic operations without any defensive response.