CVE-2024-3400: PAN-OS Command Injection Vulnerability in GlobalProtect Gateway. Learn More

CVE-2024-3400: PAN-OS Command Injection Vulnerability in GlobalProtect Gateway. Learn More

Services
Capture
Managed Detection & Response

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

twi-managed-portal-color
Co-Managed SOC (SIEM)

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

twi-briefcase-color-svg
Advisory & Diagnostics

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

tw-laptop-data
Penetration Testing

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

twi-database-color-svg
Database Security

Prevent unauthorized access and exceed compliance requirements.

twi-email-color-svg
Email Security

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

tw-officer
Digital Forensics & Incident Response

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

tw-network
Firewall & Technology Management

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

Solutions
BY TOPIC
Offensive Security
Solutions to maximize your security ROI
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
Partners
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

Capturing Ghosts: Using inotify to defeat an Android DRM system

Apart from our typical application penetration testing engagements, clients sometimes come to us looking to test the resiliancy of various security mechanisms they want to apply to their applications. This was the case a few weeks ago when one of our larger clients approached us and asked us to test a copy protection, DRM solution for one of their Android applications.

Attacking copy protection is usually a combination of both static and dynamic analysis. This includes looking at the reverse-engineered source code to figure out how the copy protection worked and to find any encryption keys, as well as, watching the application transform into the unencrypted version.

Our first step was to reverse engineer the target .apk file using dex2jar and JD-GUI to see the obfuscation.

12590_f0390644-11c7-4ae3-9c7a-5be1ba3781de

 

While the file was heavily obfuscated, it was traceable. In addition, the hashed method names seem to eventually trace calls to a native library that was referencing a hashed file in the assets directory.

Below is the redacted file in the assets directory of the target .apk.

8976_448cf2ff-01f6-430c-86a3-082f5f0e5555

The best way to watch the interaction live, apart from a debugger, was surprisingly simple - using LogCat.

By watching LogCat while the obfuscated application started up, we observed that the obfuscated file in the assets directory appeared to be the .dex file, containing the Android bytecode:

9752_6a76e13c-5b03-405b-a015-a332fa764eb4

DextOpt, which optimizes the .dex file, is operating on a .dex with the same name as the file in the asset directory. This .dex file is then written into the /data/data/{app}/files directory temporarily and then deleted as the application starts up.

This sure looks like the de-obfuscated, decrypted file. But how to get it before its deleted from the file system?

Enter the Linux inotify API, which has been in every Linux kernel since 2.6.13, including the Android kernel. Inotify allows you to monitor a file or directory and react to events such as when files are created, opened, closed, updated or deleted. And since I do all my testing on a rooted device, accessing this to monitor the /data/data/{app}/files directory of the target app would be pretty simple to do.

Based on the excellent information found here and in the code for Inotifywait-for-Android by Rohan McGovern, I was able to code a small inotify-based tool that, when run as root, would copy the .dex file to my SD card before it is deleted.

A sample of the code I used, borrowing from both of the above examples:

11204_ae2eefd7-ae66-496a-bf99-04bde6490745

I simply ran this as root on my device, then started the target app and voila, captured the unobfuscated .dex file:

8146_19c3e9b4-e5c1-4dcc-a1fd-cecddbb3fb93

After renaming this to classes.dex and repackaging the .apk using a self signed certificate, I had a DRM-free copy of the application that would run on my device.

Since then, members of my team have found at least one other way to defeat this kind of copy protection. The biggest issues appear to be that under Android, you cannot operate on a file in memory only - it has to be temporarily written to disk.

We have also used similar techniques to capture temporary cryptographic keys and credentials from iOS applications.

The moral of the story is that writing un-obfuscated data to disk, even temporarily, will always be the achilles heel of copy protection and DRM on mobile devices.

Latest SpiderLabs Blogs

Fake Dialog Boxes to Make Malware More Convincing

Let’s explore how SpiderLabs created and incorporated user prompts, specifically Windows dialog boxes into its malware loader to make it more convincing to phishing targets during a Red Team...

Read More

The Secret Cipher: Modern Data Loss Prevention Solutions

This is Part 7 in my ongoing project to cover 30 cybersecurity topics in 30 weekly blog posts. The full series can be found here. Far too many organizations place Data Loss Prevention (DLP) and Data...

Read More

CVE-2024-3400: PAN-OS Command Injection Vulnerability in GlobalProtect Gateway

Overview A command injection vulnerability has been discovered in the GlobalProtect feature within Palo Alto Networks PAN-OS software for specific versions that have distinct feature configurations...

Read More