Here is a quick Cheat Sheet to test the security of an Android app that AndroSecTest is doing.
You can have a quick look at how the application is pentesting an Android app on Youtube : https://youtu.be/zzyTFjnwolo
-
Build the Docker Container that has all the dependencies and tools already installed.
docker build .
-
Connect your Android Device
2.1. Be sure that the "adb server" is not running on the host machine as an android phone can only be connected to one adb server at a given time.
2.2. USB connection is not working from host device to Container on MacOS, so it is only working on a Linux host for the time being.
-
Run the Docker Container
docker run -it --privileged -v /dev/bus/usb:/dev/bus/usb "The Container ID"
3.1
-it
is here so that we can have an iteractive session.3.2.
--privileged
is required to use a USB device.3.3.
-v /dev/bus/usb:/dev/bus/usb
defines a shared volume between the host machine and the Container in order to share the USB device (the android phone) information
- Get the application from the Store,
- Pull it from the device,
- Unpackaged it,
- Look for some unsecure behavior,
- Make it debuggable,
- Repackage it and reinstall it on the device.
adb shell pm list packages | grep “hint from the app you are looking for”
adb shell pm path app.package.name.apk
adb pull app.path
Unzip the file. You now have access to the application's file system.
Run the following commands at the root of the application file system.
find . -name "*key"
find . -name "*cer*"
find . -name "*pass*"'''
If you find some files whose name contains 'key' try these commands :
hexdump ./path/to/.appkey -vC
more ./path/to/.appkey
Verify the signature :
apksigner verify --verbose Application.apk
or
jarsigner -verify -certs -verbose app.apk
and
Move to the META.INF folder and check the signature with openssl :
openssl pkcs7 -inform DER -in CERT.RSA -noout -print_certs -text
Extract CERT.RSA from the package and display the certificate with keytool.
keytool -printcert -file CERT.RSA
You can then check the type of encryption used (hint, SHA-1 is no more secure).
Now that you have the apk file from the application you want, you must disassemble the app to make it debuggable.
apktool d -o localAppFolder/ app.package.name.apk
In the "<application”
, in the manifest file, add a android:debuggable="true”
value to make the app debuggable.
In the "<application”
, in the manifest file, add a android:allowBackup="true”
value to allow backup from the app.
Edit the app Manifest to be able to intercept and decrypt encrypted requests from the app later on:
In the "<application”
node, in the manifest file, add a android:networkSecurityConfig="@xml/network_security_config"
value to be sure that the user added certificate are going to be trusted on a debug configuration.
Add a “network_security_config.xml” file in the “xml” folder with the following content or append the content to the existing file:
<!-- The "network_security_config.xml" -->
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
</trust-anchors>
</debug-overrides>
...
Download it from Burp, Charles, etc… and add it to your device following your preferred method (add push to the sdcard is the method I use). You can use Bettercap to monitor the UDP traffic.
- Repackage the app:
apk tool b -o app.package.name.apk localAppFolder/
- Generate a signing key :
keytool -genkey -v -keystore resign.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
- then sign the app with it :
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore resign.keystore app.package.name.apk alias_name
or
apksigner sign -ks resign.keystore app.package.name.apk
Run the following command to install the repackage app to the device:
adb install app.package.name.apk
I want to use some Man in the Middle attack while the user is using the application. It will jsute intercept all the requests/responses for later analysis. I plan to use Bettercap or mitmproxy to do it.
We are going to use MobSF (MobSF stands for Mobile Security Framework) to test some part of the security of the app.
As described in the Github page of the Project :
Mobile Security Framework (MobSF) is an automated, all-in-one mobile application (Android/iOS/Windows) pen-testing framework capable of performing static, dynamic and malware analysis. It can be used for effective and fast security analysis of Android, iOS and Windows mobile applications and support both binaries (APK, IPA & APPX ) and zipped source code. MobSF can do dynamic application testing at runtime for Android apps and has Web API fuzzing capabilities powered by CapFuzz, a Web API specific security scanner. MobSF is designed to make your CI/CD or DevSecOps pipeline integration seamless.
I personnaly use the Docker container to use MobSF for Android security audit.
So you could just launch that command docker run -it -p 8000:8000 -v <your_local_dir>:/root/.MobSF opensecurity/mobile-security-framework-mobsf:latest
MobSF is going to automate a lot of the process of static security analysis and deliver a report that will make it easier to start the dynamic security audit.