2022-04-28 16:01:33 +00:00
< details >
2023-04-25 18:35:28 +00:00
< summary > < a href = "https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology" > < strong > ☁️ HackTricks Cloud ☁️< / strong > < / a > -< a href = "https://twitter.com/hacktricks_live" > < strong > 🐦 Twitter 🐦< / strong > < / a > - < a href = "https://www.twitch.tv/hacktricks_live/schedule" > < strong > 🎙️ Twitch 🎙️< / strong > < / a > - < a href = "https://www.youtube.com/@hacktricks_LIVE" > < strong > 🎥 Youtube 🎥< / strong > < / a > < / summary >
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Do you work in a **cybersecurity company** ? Do you want to see your **company advertised in HackTricks** ? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF** ? Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2022-04-28 16:01:33 +00:00
2023-04-25 18:35:28 +00:00
- **Join the** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** me on **Twitter** [**🐦** ](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md )[**@carlospolopm** ](https://twitter.com/hacktricks_live )**.**
2022-04-28 16:01:33 +00:00
2022-12-05 22:29:21 +00:00
- **Share your hacking tricks by submitting PRs to the [hacktricks repo ](https://github.com/carlospolop/hacktricks ) and [hacktricks-cloud repo ](https://github.com/carlospolop/hacktricks-cloud )**.
2022-04-28 16:01:33 +00:00
< / details >
2021-04-22 13:58:44 +00:00
**Adb is usually located in:**
```bash
#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe
#MacOS
/Users/< username > /Library/Android/sdk/platform-tools/adb
```
2022-04-05 22:24:52 +00:00
**Information obtained from:** [**http://adbshell.com/** ](http://adbshell.com )
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
# Connection
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb devices
```
2021-11-30 16:46:07 +00:00
This will list the connected devices; if "_**unathorised**_" appears, this means that you have to **unblock** your **mobile** and **accept** the connection.
2020-07-15 15:43:14 +00:00
This indicates to the device that it has to start and adb server in port 5555:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb tcpip 5555
```
Connect to that IP and that Port:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb connect < IP > :< PORT >
```
2021-10-18 11:21:18 +00:00
If you get an error like the following in a Virtual Android software (like Genymotion):
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb server version (41) doesn't match this client (36); killing...
```
2021-10-18 11:21:18 +00:00
It's because you are trying to connect to an ADB server with a different version. Just try to find the adb binary the software is using (go to `C:\Program Files\Genymobile\Genymotion` and search for adb.exe)
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
## Several devices
2021-07-04 09:43:18 +00:00
Whenever you find **several devices connected to your machine** you will need to **specify in which one** you want to run the adb command.
```bash
adb devices
List of devices attached
10.10.10.247:42135 offline
127.0.0.1:5555 device
```
```bash
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
root
```
2022-05-01 12:41:36 +00:00
## Port Tunneling
2021-07-04 09:43:18 +00:00
2021-11-30 16:46:07 +00:00
In case the **adb** **port** is only **accessible** from **localhost** in the android device but **you have access via SSH** , you can **forward the port 5555** and connect via adb:
2021-07-04 09:43:18 +00:00
```bash
ssh -i ssh_key username@10.10.10.10 -L 5555:127.0.0.1:5555 -p 2222
adb connect 127.0.0.1:5555
```
2022-05-01 12:41:36 +00:00
# Packet Manager
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
## Install/Uninstall
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
### adb install \[option] \<path>
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install test.apk
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -l test.apk forward lock application
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -r test.apk replace existing application
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -t test.apk allow test packages
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -s test.apk install application on sdcard
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -d test.apk allow version code downgrade
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -p test.apk partial application install
```
2022-05-01 12:41:36 +00:00
### adb uninstall \[options] \<PACKAGE>
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb uninstall com.test.app
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb uninstall -k com.test.app Keep the data and cache directories around after package removal.
```
2022-05-01 12:41:36 +00:00
## Packages
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Prints all packages, optionally only those whose package name contains the text in \<FILTER>.
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
### adb shell pm list packages \[options] \<FILTER-STR>
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages < FILTER-STR >
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -f < FILTER-STR > #See their associated file.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -d < FILTER-STR > #Filter to only show disabled packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -e < FILTER-STR > #Filter to only show enabled packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -s < FILTER-STR > #Filter to only show system packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -3 < FILTER-STR > #Filter to only show third party packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -i < FILTER-STR > #See the installer for the packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -u < FILTER-STR > #Also include uninstalled packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages --user < USER_ID > < FILTER-STR > #The user space to query.
```
2022-05-01 12:41:36 +00:00
### adb shell pm path \<PACKAGE>
2020-07-15 15:43:14 +00:00
Print the path to the APK of the given .
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm path com.android.phone
```
2022-05-01 12:41:36 +00:00
### adb shell pm clear \<PACKAGE>
2020-07-15 15:43:14 +00:00
Delete all data associated with a package.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm clear com.test.abc
```
2022-05-01 12:41:36 +00:00
# File Manager
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
### adb pull \<remote> \[local]
2020-07-15 15:43:14 +00:00
Download a specified file from an emulator/device to your computer.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb pull /sdcard/demo.mp4 ./
```
2022-05-01 12:41:36 +00:00
### adb push \<local> \<remote>
2020-07-15 15:43:14 +00:00
Upload a specified file from your computer to an emulator/device.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb push test.apk /sdcard
```
2022-05-01 12:41:36 +00:00
# Screencapture/Screenrecord
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
### adb shell screencap \<filename>
2020-07-15 15:43:14 +00:00
Taking a screenshot of a device display.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell screencap /sdcard/screen.png
```
2022-05-01 12:41:36 +00:00
### adb shell screenrecord \[options] \<filename>
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Recording the display of devices running Android 4.4 (API level 19) and higher.
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell screenrecord /sdcard/demo.mp4
adb shell screenrecord --size < WIDTHxHEIGHT >
adb shell screenrecord --bit-rate < RATE >
adb shell screenrecord --time-limit < TIME > #Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
adb shell screenrecord --rotate # Rotates 90 degrees
adb shell screenrecord --verbose
```
2021-10-18 11:21:18 +00:00
(press Ctrl-C to stop recording)
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
**You can download the files (images and videos) using **_**adb pull**_
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
# Shell
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
### adb shell
2020-07-15 15:43:14 +00:00
Get a shell inside the device
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell
```
2022-05-01 12:41:36 +00:00
### adb shell \<CMD>
2020-07-15 15:43:14 +00:00
Execute a command inside the device
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell ls
```
2022-05-01 12:41:36 +00:00
## pm
2021-04-22 13:58:44 +00:00
The following commands are executed inside of a shell
```bash
pm list packages #List installed packages
pm path < package name > #Get the path to the apk file of tha package
am start [< options > ] #Start an activity. Whiout options you can see the help menu
am startservice [< options > ] #Start a service. Whiout options you can see the help menu
am broadcast [< options > ] #Send a broadcast. Whiout options you can see the help menu
input [text|keyevent] #Send keystrokes to device
```
2022-05-01 12:41:36 +00:00
# Processes
2020-07-15 15:43:14 +00:00
If you want to get the PID of the process of your application you can execute:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell ps
```
And search for your application
Or you can do
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pidof com.your.application
```
And it will print the PID of the application
2022-05-01 12:41:36 +00:00
# System
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb root
```
2021-10-18 11:21:18 +00:00
Restarts the adbd daemon with root permissions. Then, you have to conenct again to the ADB server and you will be root (if available)
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb sideload < update.zip >
```
flashing/restoring Android update.zip packages.
2022-05-01 12:41:36 +00:00
# Logs
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
## Logcat
2020-07-15 15:43:14 +00:00
2021-11-30 16:46:07 +00:00
To **filter the messages of only one application** , get the PID of the application and use grep (linux/macos) or findstr (windows) to filter the output of logcat:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat | grep 4526
adb logcat | findstr 4526
```
2022-05-01 12:41:36 +00:00
### adb logcat \[option] \[filter-specs]
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat
```
Notes: press Ctrl-C to stop monitor
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:V lowest priority, filter to only show Verbose level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:D filter to only show Debug level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:I filter to only show Info level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:W filter to only show Warning level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:E filter to only show Error level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:F filter to only show Fatal level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:S Silent, highest priority, on which nothing is ever printed
```
2022-05-01 12:41:36 +00:00
### adb logcat -b \<Buffer>
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -b radio View the buffer that contains radio/telephony related messages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -b event View the buffer containing events-related messages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -b main default
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -c Clears the entire log and exits.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -d Dumps the log to the screen and exits.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -f test.logs Writes log message output to test.logs .
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -g Prints the size of the specified log buffer and exits.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -n < count > Sets the maximum number of rotated logs to < count > .
```
2022-05-01 12:41:36 +00:00
## dumpsys
2020-07-15 15:43:14 +00:00
dumps system data
2022-05-01 12:41:36 +00:00
### adb shell dumpsys \[options]
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell dumpsys
```
adb shell dumpsys meminfo
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell dumpsys battery
```
Notes: A mobile device with Developer Options enabled running Android 5.0 or higher.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell dumpsys batterystats collects battery data from your device
```
2021-10-18 11:21:18 +00:00
Notes: [Battery Historian ](https://github.com/google/battery-historian ) converts that data into an HTML visualization. **STEP 1** _adb shell dumpsys batterystats > batterystats.txt_ **STEP 2** _python historian.py batterystats.txt > batterystats.html_
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell dumpsys batterystats --reset erases old collection data
```
adb shell dumpsys activity
2022-05-01 12:41:36 +00:00
# Backup
2020-07-15 15:43:14 +00:00
Backup an android device from adb.
```bash
adb backup [-apk] [-shared] [-system] [-all] -f file.backup
# -apk -- Include APK from Third partie's applications
# -shared -- Include removable storage
# -system -- Include system Applciations
# -all -- Include all the applications
2021-02-17 12:02:24 +00:00
adb shell pm list packages -f -3 #List packages
2021-02-17 12:07:55 +00:00
adb backup -f myapp_backup.ab -apk com.myapp # backup on one device
adb restore myapp_backup.ab # restore to the same or any other device
```
If you want to inspect the content of the backup:
```bash
( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) | tar xfvz -
2020-07-15 15:43:14 +00:00
```
2022-04-28 16:01:33 +00:00
< details >
2023-04-25 18:35:28 +00:00
< summary > < a href = "https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology" > < strong > ☁️ HackTricks Cloud ☁️< / strong > < / a > -< a href = "https://twitter.com/hacktricks_live" > < strong > 🐦 Twitter 🐦< / strong > < / a > - < a href = "https://www.twitch.tv/hacktricks_live/schedule" > < strong > 🎙️ Twitch 🎙️< / strong > < / a > - < a href = "https://www.youtube.com/@hacktricks_LIVE" > < strong > 🎥 Youtube 🎥< / strong > < / a > < / summary >
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Do you work in a **cybersecurity company** ? Do you want to see your **company advertised in HackTricks** ? or do you want to have access to the **latest version of the PEASS or download HackTricks in PDF** ? Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2022-04-28 16:01:33 +00:00
2022-09-09 11:28:04 +00:00
- Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2022-04-28 16:01:33 +00:00
2023-04-25 18:35:28 +00:00
- **Join the** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** me on **Twitter** [**🐦** ](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md )[**@carlospolopm** ](https://twitter.com/hacktricks_live )**.**
2022-04-28 16:01:33 +00:00
2022-12-05 22:29:21 +00:00
- **Share your hacking tricks by submitting PRs to the [hacktricks repo ](https://github.com/carlospolop/hacktricks ) and [hacktricks-cloud repo ](https://github.com/carlospolop/hacktricks-cloud )**.
2022-04-28 16:01:33 +00:00
< / details >