Description
Find the flag in droids2.apk. A native library is involved.
Setup
Download the APK file.
wget <url>/droids2.apkSolution
Walk me through it- Step 1Decompile the APK and identify the native callDecompile with jadx. Find the MainActivity - it will show a method declared with the 'native' keyword. This method is implemented in a shared library (.so file) bundled in the APK.bash
jadx droids2.apk -d droids2_java/bashgrep -r 'native' droids2_java/bashunzip droids2.apk -d droids2_raw/bashls droids2_raw/lib/Learn more
Android Native Interface (JNI) allows Java/Kotlin code to call C/C++ functions in
.soshared libraries. The Java method is markednativeand Android links it to the corresponding JNI function in the .so file at runtime.The .so files live in
lib/armeabi-v7a/,lib/arm64-v8a/, orlib/x86/inside the APK. For analysis, use the x86 version if available, as it is easier to analyze on a desktop system. - Step 2Analyze the .so with GhidraLoad the .so file into Ghidra. Find the JNI function (it will have a name like Java_com_example_droids2_MainActivity_nativeCheck). Analyze it to find the hardcoded password or flag.bash
ls droids2_raw/lib/x86/bash# Open the .so in Ghidrabashghidra &Learn more
JNI function naming convention:
Java_+ package name (dots replaced with underscores) +_+ class name +_+ method name. For example,Java_com_example_droids2_MainActivity_getFlag.In Ghidra, use the Symbol Tree (Window > Symbol Tree) to navigate to the JNI function. The decompiled view shows the C logic. Look for string literals, character arrays, or XOR operations that produce the flag.
- Step 3Extract the flag from the native codeRead the flag from the Ghidra decompilation. It may be a hardcoded string or computed from a simple algorithm.
Learn more
Native library analysis is harder than Java analysis because decompilation loses more information (variable names, types). However, string literals, function calls, and control flow are usually clear enough to extract the relevant logic.
Flag
picoCTF{...}
Unzip the APK to get the .so file, then use Ghidra to find the hardcoded flag in the JNI native function.