Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising. Learn More

Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Microsoft Exchange Server Attacks
Stay protected against emerging threats
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
SpiderLabs Blog

Debugging Android Libraries using IDA

During a recent test, I encountered a native JNI library used by an Android application. I needed to understand this library and what it did, so the first step was to load the library in IDA to see what it looked like. It did not take long until I realized I was looking at obfuscated code that was doing a lot of manipulation on the stack. Understanding the library through static analysis alone would take a long time, so the best way forward would be to combine static and dynamic analysis.

Having debugged a lot of iOS apps using GDB, I started looking at debugging Android apps with GDB. Until this point, DEX2JAR, Smali and some other tools had been sufficient for my Android reversing requirements.

Some research lead me to a discussion at xda-developers about Android debugging through the remote debugging functionality in IDA.

Below is a description of the steps I had to take before I could start debugging the library in question. In this case I used the Android emulator, but this should work just as well on a rooted device.

  1. Create anAndroid Virtual Device (AVD) for use in the emulator and make sure it works.

  2. Start the emulator, and when the emulator is running, use the command "a db devices" to make sure the Android Debug Bridge (adb) is working properly. You should seethe emulator listed if it works. It is also best if only one device is connected, so if you see multiple devices, disconnect the extra ones.

  3. Start the emulator again using the following command: "emulator –avd [AVD_NAME] –partition-size512". It is possible to use a partition size lower(or higher) than 512 although I did not test this.

  4. Run the following commands.

    a db remount
    a db push android_server /system/
    a db shell
    su (probably not needed for the emulator but is necessary if doing this on a rooted device)
    cd /system
    chmod 755 android_server

    The commands above will begin by mounting the system partition as read-write, and then push the file android_server to the /system folder. This file can be found in the db gsrv folder of IDA. Next, it will create a shell, make the android_server file executable and then run it.

  5. Minimize the windows where android_server is running and open a new command prompt /terminal, and type this command: "adb forward tcp:23946 tcp:23946". This will allow connections to localhost:23946 and forward those to the emulator.

    In my case, I wanted to debug specific functions in the library. Therefore, I used a custom library loader that loaded the library and then stopped execution. I then attached IDA to the running process, moved the instruction pointer to the next instruction to get past the breakpoint, and then jump directly into the function I wanted to debug. This part will be described in detail in upcoming post.

  6. To attach IDA to a running process, just load the library in IDA, go into the debugger options and select the "Remote ARM Linux/Android debugger", go into "Process Options" in the debugger menu, and set the hostname to localhost. If you used the same ports as above, you should not need to change anything else.

  7. Go into the debugger menu again, this time choose "Attach to process…" and you should see a list of all running processes. Select the one you are interested in, attach and start debugging.

Depending on what is being analyzed, it is possible to do a memory dump from the process into IDA and save the IDB. This may be good for future analysis, and there is always a risk of a crash somewhere that can terminate the debug session.

Also, if you have the library or file to be analyzed open in IDA before the debugger is attached, IDA should identify the memory address shift (due to ASLR) and ask if you want to rebase the file / library.

Latest SpiderLabs Blogs

Trustwave SpiderLabs: Insights and Solutions to Defend Educational Institutions Against Cyber Threats

Security teams responsible for defending educational institutions at higher education and primary school levels often find themselves facing harsh lessons from threat actors who exploit the numerous...

Read More

Breakdown of Tycoon Phishing-as-a-Service System

Just weeks after Trustwave SpiderLabs reported on the Greatness phishing-as-a-service (PaaS) framework, SpiderLabs’ Email Security team is tracking another PaaS called Tycoon Group.

Read More

Trustwave SpiderLabs Uncovers Ov3r_Stealer Malware Spread via Phishing and Facebook Advertising

During an Advanced Continual Threat Hunt (ACTH) investigation that took place in early December 2023, Trustwave SpiderLabs discovered Ov3r_Stealer, an infostealer distributed using Facebook...

Read More