What is adb?
The Android Debug Bridge (adb) is a programming tool used for the debugging of Android-based devices. The daemon on the Android device connects with the server on the host PC over USB or TCP, which connects to the client that is used by the end user over TCP. For hackers, this means we can interact with Android devices to add and remove packages, access debug logs and interact with either physical or virtual Android instances for mobile web app security testing.
- What is adb?
- adb Installation
- adb Example Commands
- adb print text
- adb key events
- Useful file system paths
- Conclusion
- Sources
adb Installation
How to install adb on MacOS:
adb Example Commands
adb start / restart
adb reboot
adb reboot with root
The following restarts the android device with root permissions:
adb list devices:
Show adb devices:
adb show devices with full information (product/model)
adb connect to a device:
adb shell
Run commands on the android device shell via an adb shell:
adb android version
Return the running Android version of the connected adb device:
adb Logcat
Commands related to adb logcat, allowing access to Android logs via adb.
adb view logs:
adb clear logs on device:
adb dump log output to file on the local system:
adb full log dump (dumpstate, dumpsys and logcat output):
adb copy files
adb copy files from your system to your android phone:
adb copy files from phone to system:
adb install package
COMMAND |
DESCRIPTION |
---|---|
-d |
directs command to the only connected USB device |
-e |
directs command to the only running emulator |
-s |
serial number |
-p |
product name or path |
Note the flag needs to come before the command.
Uninstalling app with adb
COMMAND | DESCRIPTION |
---|---|
adb uninstall com.myAppPackage |
Uninstalls the app with the package name com.myAppPackage. |
adb uninstall <app .apk name> |
Uninstalls the app with the specified .apk file name. |
adb uninstall -k <app .apk name> |
Uninstalls the .apk file without deleting its data. |
adb update app
COMMAND | DESCRIPTION |
---|---|
adb install -r app-name.apk |
reinstall the app and keep its data on the device |
adb install –k app-name.apk /local/path/ |
Installs the app and retains its data without deleting it |
adb home button press
adb take screenshot
adb screen record
ShPref
adb restart app
adb emulate device
How to emulate device in adb:
adb reset to default:
adb print text
Potentially useful for input validation based attacks:
adb key events
COMMAND | DESCRIPTION |
---|---|
|
home btn |
|
back btn |
|
call |
|
end call |
|
turn android device on and off. it will toggle device to on/off status. |
|
camera |
|
open browser |
|
enter |
|
delete (backspace) |
|
contacts |
|
brightness down/up |
|
cut/copy/paste |
Useful file system paths
PATH |
DESCRIPTION |
---|---|
/data/data/<package>/databases |
App databases |
/data/data/<package>/shared_prefs/ |
Shared preferences |
/data/app |
APK installed by user |
/system/app |
Pre-installed APK files |
/mmt/asec |
Encrypted apps (App2SD) |
/mmt/emmc |
Internal SD Card |
/mmt/adcard |
External/Internal SD Card |
/mmt/adcard/external_sd |
External SD Card |
adb show device information
COMMAND | DESCRIPTION |
---|---|
adb get-state |
Print device state |
adb get-serialno |
Get the serial number |
adb shell dumpsys iphonesybinfo |
Get the IMEI |
adb shell netstat |
List TCP connectivity |
adb shell pwd |
Print current working directory |
adb shell dumpsys battery |
Battery status |
adb shell pm list features |
List phone features |
adb shell service list |
List all services |
adb shell dumpsys activity <package>/<activity> |
Activity info |
adb shell ps |
Print process status |
adb shell wm size |
Displays the current screen resolution |
dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' |
Print current app's opened activity |
adb show package info
COMMAND | DESCRIPTION |
---|---|
adb shell list packages |
List package names |
adb shell list packages -r |
List package name + path to APKs |
adb shell list packages -3 |
List third-party package names |
adb shell list packages -s |
List only system packages |
adb shell list packages -u |
List package names + uninstalled |
adb shell dumpsys package packages |
List info on all apps |
adb shell dump <name> |
List info on one package |
adb shell path <package> |
Path to the APK file |
adb system settings
e.g., adjust battery level, resolution etc
COMMAND | DESCRIPTION |
---|---|
adb shell dumpsys battery set level <n> |
Change the battery level from 0 to 100 |
adb shell dumpsys battery set status <n> |
Change the battery status to unknown, charging, discharging, not charging, or full |
adb shell dumpsys battery reset |
Reset the battery |
adb shell dumpsys battery set usb <n> |
Change the status of USB connection to ON or OFF |
adb shell wm size WxH |
Sets the resolution to WxH |
adb device commands
COMMAND | DESCRIPTION |
---|---|
adb reboot-recovery |
Reboot device into recovery mode |
adb reboot fastboot |
Reboot device into fastboot mode |
adb shell screencap -p "/tmp/screenshot.png" |
Capture screenshot |
adb shell screenrecord "/tmp/record.mp4" |
Record device screen |
adb backup -apk -all -f backup.ab |
Backup settings and apps |
adb backup -apk -shared -all -f backup.ab |
Backup settings, apps, and shared storage |
adb backup -apk -nosystem -all -f backup.ab |
Backup only non-system apps |
adb restore backup.ab |
Restore a previous backup |
adb shell am start|startservice|broadcast <INTENT>[<COMPONENT>] -a <ACTION> |
Start activity intent |
adb shell am start -a android.intent.action.VIEW -d URL |
Open URL |
adb shell am start -t image/* -a android.intent.action.VIEW |
Opens gallery |
adb backup
Conclusion
We hope this ADB cheat sheet was useful in covering the usage of the ADB tool for performing mobile app security testing against Android Apps.