Android App RCE via Dynamic Code Loading
The app's copyFileFromUri method used the last path segment of a URI without decoding, allowing path traversal to write files into the app's private storage. An attacker could deliver a malicious native library via a crafted intent, leading to remote code execution when the app loads it.
Published on infosecwriteups.com
The goal is to exploit a path traversal vulnerability combined with dynamic code loading to achieve remote code execution in this document viewer app. Read my previous Attacking Insecure Content Providers and Hijacking Android Notification System via PendingIntent.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the app used Uri.getLastPathSegment() without decoding or sanitising the path, allowing directory traversal when constructing the destination file path.
Impact
An attacker could write arbitrary files to the app's private storage and achieve remote code execution by loading a malicious native library.
What the attacker needed
Victim clicks a link or receives an intent; app has the vulnerable copyFileFromUri method
How it was found
- Host a file on a server that returns it for any path.
- Craft a URI with URL-encoded traversal sequences pointing to the app's private files directory.
- Send the URI to the app via an intent.
- The app downloads the file and saves it to the traversed path.
- Relaunch the app to load the malicious library.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The app had a feature that downloaded a file from a link and saved it using the last part of the link as the filename. Because it didn't clean up special characters like '../', an attacker could make it save a file anywhere in the app's private storage, including a folder where the app loads extra code from. By placing a malicious library there, the attacker could run their own commands on the device.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.