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

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.



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.


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:


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:


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


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

Welcome to Adventures in Cybersecurity: The Defender Series

I’m happy to say I’m done chasing Microsoft certifications (AZ104/AZ500/SC100), and as a result, I’ve had the time to put some effort into a blog series that hopefully will entertain and inform you...

Read More

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