Securing Vulnerable Methods in iOS and macOS Binaries via Interposing Dynamic Libraries.
This project create a dynamic library using interposing to replace vulnerable libc functions with safer alternatives on macOS and iOS. Specifically, it interposes the strcmp, strcpy, and strcat functions.
Dynamic library interposition in iOS, implemented through the DYLD_INTERPOSE macro, is a runtime technique that allows developers to replace or intercept calls to existing functions within dynamically linked libraries. The DYLD_INTERPOSE macro creates a special section in the binary that the dynamic linker (dyld) processes at load time, establishing function redirections before the main program executes.
This mechanism works by creating tuples that map original function addresses to replacement function addresses, enabling developers to hook into system calls, library functions, or any dynamically linked code. Originally designed for debugging, profiling, and testing purposes, interposition has become a powerful tool for runtime analysis, security research, and reverse engineering on iOS and macOS platforms.
The technique operates at a lower level than method swizzling in Objective-C, working directly with C functions and providing more comprehensive coverage of the system's function calls, though it requires careful implementation to avoid crashes and maintain system stability.
The library uses the DYLD_INTERPOSE to replace dangerous functions with secure implementations:
strcmpwithstrncmp.strcpywithstrncpy.strcatwithstrncat.sprintfwithsnprintf.vsprintfwithvsnprintf.getswithfgets.
secmet.c: Secure function implementations with interposition logic and replacement functions.Makefile: The makefile to compile the dynamic library.README.md: Project documentation.
To compile the dynamic library, use the provided Makefile: make
This produces libsecmet.dylib.
For new applications, link directly during compilation:
# Compile your app with the security library
clang -o myapp myapp.c -L. -lsecmet
# Run normally - security is built-in
./myappAdd to your Xcode project:
- Build Settings → Other Linker Flags → Add
-L/path/to/lib -lsecmet. - Build Phases → Copy Files → Add
libsecmet.dylibto bundle. - Build and run - security functions activate automatically.
For existing binaries or testing:
# Inject into running process
DYLD_INSERT_LIBRARIES=./libsecmet.dylib ./existing_appThis will ensure that the interposed functions are used by your_application.
To clean up the generated files, run: make clean
Barak Aharoni