hacktricks/mobile-pentesting/android-app-pentesting/adb-commands.md

349 lines
12 KiB
Markdown
Raw Normal View History

2022-04-28 16:01:33 +00:00
<details>
2024-02-11 02:07:06 +00:00
<summary><strong>Leer AWS-hacking van nul tot held met</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:07:06 +00:00
Ander maniere om HackTricks te ondersteun:
2022-04-28 16:01:33 +00:00
2024-02-11 02:07:06 +00:00
* As jy jou **maatskappy geadverteer wil sien in HackTricks** of **HackTricks in PDF wil aflaai**, kyk na die [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Kry die [**amptelike PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Ontdek [**The PEASS Family**](https://opensea.io/collection/the-peass-family), ons versameling eksklusiewe [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Deel jou hacking-truuks deur PR's in te dien by die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github-opslagplekke.
2022-04-28 16:01:33 +00:00
</details>
2024-02-11 02:07:06 +00:00
**Adb is gewoonlik geleë in:**
2021-04-22 13:58:44 +00:00
```bash
#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe
#MacOS
/Users/<username>/Library/Android/sdk/platform-tools/adb
```
2024-02-11 02:07:06 +00:00
**Inligting verkry vanaf:** [**http://adbshell.com/**](http://adbshell.com)
2021-04-22 13:58:44 +00:00
2024-02-11 02:07:06 +00:00
# Verbinding
```
adb devices
```
2024-02-11 02:07:06 +00:00
Hierdie sal die gekoppelde toestelle lys; as "_**ongemagtig**_" verskyn, beteken dit dat jy jou **selfoon** moet **ontblokkeer** en die verbinding **aanvaar**.
2024-02-11 02:07:06 +00:00
Dit dui die toestel aan dat dit 'n adb-bediener op poort 5555 moet begin:
```
adb tcpip 5555
```
2024-02-11 02:07:06 +00:00
Koppel aan daardie IP en daardie Poort:
```
adb connect <IP>:<PORT>
```
2024-02-11 02:07:06 +00:00
As jy 'n fout soos die volgende kry in 'n Virtuele Android-program (soos Genymotion):
```
adb server version (41) doesn't match this client (36); killing...
```
2024-02-11 02:07:06 +00:00
Dit is omdat jy probeer om te verbind met 'n ADB-bediener met 'n ander weergawe. Probeer net om die adb-binêre lêer te vind wat die sagteware gebruik (gaan na `C:\Program Files\Genymobile\Genymotion` en soek na adb.exe)
2024-02-11 02:07:06 +00:00
## Verskeie toestelle
2021-07-04 09:43:18 +00:00
2024-02-11 02:07:06 +00:00
Wanneer jy **verskeie toestelle aan jou rekenaar gekoppel** vind, sal jy moet **spesifiseer in watter een** jy die adb-opdrag wil uitvoer.
2021-07-04 09:43:18 +00:00
```bash
adb devices
List of devices attached
10.10.10.247:42135 offline
127.0.0.1:5555 device
```
```bash
2024-02-11 02:07:06 +00:00
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
2021-07-04 09:43:18 +00:00
root
```
2024-02-11 02:07:06 +00:00
## Poorttunneling
2021-07-04 09:43:18 +00:00
2024-02-11 02:07:06 +00:00
In die geval waar die **adb** **poort** slegs **toeganklik** is vanaf die **localhost** op die Android-toestel, maar **jy het toegang via SSH**, kan jy die poort 5555 **deurstuur** en verbind 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
```
2024-02-11 02:07:06 +00:00
# Pakketbestuurder
2021-07-04 09:43:18 +00:00
2024-02-11 02:07:06 +00:00
## Installeer/Deïnstalleer
2024-02-11 02:07:06 +00:00
### adb install \[opsie] \<pad>
2024-02-08 03:06:37 +00:00
```bash
adb install test.apk
2024-02-08 03:06:37 +00:00
adb install -l test.apk # forward lock application
2024-02-08 03:06:37 +00:00
adb install -r test.apk # replace existing application
2024-02-08 03:06:37 +00:00
adb install -t test.apk # allow test packages
2024-02-08 03:06:37 +00:00
adb install -s test.apk # install application on sdcard
2024-02-08 03:06:37 +00:00
adb install -d test.apk # allow version code downgrade
2024-02-08 03:06:37 +00:00
adb install -p test.apk # partial application install
```
2024-02-11 02:07:06 +00:00
### adb deïnstalleer \[opsies] \<PAKET>
2024-02-08 03:06:37 +00:00
```bash
adb uninstall com.test.app
adb uninstall -k com.test.app Keep the data and cache directories around after package removal.
```
2024-02-11 02:07:06 +00:00
## Pakkette
2024-02-11 02:07:06 +00:00
Druk alle pakkette af, opsioneel slegs dié waarvan die pakketnaam die teks in \<FILTER> bevat.
2024-02-11 02:07:06 +00:00
### adb shell pm lys pakkette \[opsies] \<FILTER-STR>
2024-02-08 03:06:37 +00:00
```bash
adb shell pm list packages <FILTER-STR>
adb shell pm list packages -f <FILTER-STR> #See their associated file.
adb shell pm list packages -d <FILTER-STR> #Filter to only show disabled packages.
adb shell pm list packages -e <FILTER-STR> #Filter to only show enabled packages.
adb shell pm list packages -s <FILTER-STR> #Filter to only show system packages.
adb shell pm list packages -3 <FILTER-STR> #Filter to only show third party packages.
adb shell pm list packages -i <FILTER-STR> #See the installer for the packages.
adb shell pm list packages -u <FILTER-STR> #Also include uninstalled packages.
adb shell pm list packages --user <USER_ID> <FILTER-STR> #The user space to query.
```
2024-02-11 02:07:06 +00:00
### adb shell pm path \<PAKKET>
2024-02-11 02:07:06 +00:00
Druk die pad na die APK van die gegewe .
2024-02-08 03:06:37 +00:00
```bash
adb shell pm path com.android.phone
```
2024-02-11 02:07:06 +00:00
### adb shell pm clear \<PAKKET>
2024-02-11 02:07:06 +00:00
Verwyder alle data wat geassosieer word met 'n pakket.
2024-02-08 03:06:37 +00:00
```bash
adb shell pm clear com.test.abc
```
2024-02-11 02:07:06 +00:00
# Lêerbestuurder
2022-05-01 12:41:36 +00:00
### adb pull \<remote> \[local]
2024-02-11 02:07:06 +00:00
Laai 'n gespesifiseerde lêer van 'n emulator/toestel af na jou rekenaar.
2024-02-08 03:06:37 +00:00
```bash
adb pull /sdcard/demo.mp4 ./
```
2024-02-11 02:07:06 +00:00
### adb push \<plaaslike> \<afgeleë>
2024-02-11 02:07:06 +00:00
Laai 'n gespesifiseerde lêer vanaf jou rekenaar na 'n emulator/toestel.
2024-02-08 03:06:37 +00:00
```bash
adb push test.apk /sdcard
```
2024-02-11 02:07:06 +00:00
# Skermvaslegging/Skermrekord
2024-02-11 02:07:06 +00:00
### adb shell screencap \<lêernaam>
2024-02-11 02:07:06 +00:00
Neem 'n skermvaslegging van 'n toestel se vertoning.
2024-02-08 03:06:37 +00:00
```bash
adb shell screencap /sdcard/screen.png
```
2024-02-11 02:07:06 +00:00
### adb shell screenrecord \[opsies] \<lêernaam>
2024-02-11 02:07:06 +00:00
Die opname van die skerm van toestelle wat Android 4.4 (API-vlak 19) en hoër hardloop.
2024-02-08 03:06:37 +00:00
```bash
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
```
2024-02-11 02:07:06 +00:00
(druk Ctrl-C om opname te stop)
2024-02-11 02:07:06 +00:00
**Jy kan die lêers (afbeeldings en videos) aflaai deur **_**adb pull**_
2022-05-01 12:41:36 +00:00
# Shell
2022-05-01 12:41:36 +00:00
### adb shell
2024-02-11 02:07:06 +00:00
Kry 'n skulp binne die toestel
2024-02-08 03:06:37 +00:00
```bash
adb shell
```
2022-05-01 12:41:36 +00:00
### adb shell \<CMD>
2024-02-11 02:07:06 +00:00
Voer 'n bevel binne die toestel uit
2024-02-08 03:06:37 +00:00
```bash
adb shell ls
```
2022-05-01 12:41:36 +00:00
## pm
2021-04-22 13:58:44 +00:00
2024-02-11 02:07:06 +00:00
Die volgende opdragte word binne 'n skul uitgevoer.
2021-04-22 13:58:44 +00:00
```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
```
2024-02-11 02:07:06 +00:00
# Prosesse
2021-04-22 13:58:44 +00:00
2024-02-11 02:07:06 +00:00
As jy die PID van die proses van jou toepassing wil kry, kan jy die volgende uitvoer:
2024-02-08 03:06:37 +00:00
```bash
adb shell ps
```
2024-02-11 02:07:06 +00:00
En soek na jou toepassing
2024-02-11 02:07:06 +00:00
Of jy kan doen
2024-02-08 03:06:37 +00:00
```bash
adb shell pidof com.your.application
```
2024-02-11 02:07:06 +00:00
En dit sal die PID van die toepassing druk
2024-02-11 02:07:06 +00:00
# Stelsel
2024-02-08 03:06:37 +00:00
```bash
adb root
```
2024-02-11 02:07:06 +00:00
Herlaai die adbd daemon met root-regte. Dan moet jy weer verbind met die ADB-bediener en jy sal root wees (indien beskikbaar).
2024-02-08 03:06:37 +00:00
```bash
adb sideload <update.zip>
```
2024-02-11 02:07:06 +00:00
# Flits/herstel Android update.zip-pakette.
2024-02-11 02:07:06 +00:00
# Logboeke
2022-05-01 12:41:36 +00:00
## Logcat
2024-02-11 02:07:06 +00:00
Om **slegs die boodskappe van een toepassing te filter**, kry die PID van die toepassing en gebruik grep (linux/macos) of findstr (windows) om die uitset van logcat te filter:
2024-02-08 03:06:37 +00:00
```bash
adb logcat | grep 4526
adb logcat | findstr 4526
```
2024-02-11 02:07:06 +00:00
### adb logcat \[opsie] \[filter-spesifikasies]
Beskrywing:
- Die `adb logcat`-bevel gee toegang tot die logboeke van 'n Android-toestel.
- Dit kan gebruik word om foutopsporing en probleemoplossing te doen tydens Android-app-pentesting.
Opsies:
- `-B` : Stel 'n buffergrootte in vir die logboek.
- `-c` : Wis die logboek.
- `-d` : Druk die logboek na die skerm en stop.
- `-f <lêernaam>` : Skryf die logboek na 'n lêer.
- `-g` : Druk geheugengebruiksinligting uit.
- `-n <aantal>` : Stel die maksimum aantal roetines in wat in die logboek gehou moet word.
- `-r <aantal>` : Stel die maksimum aantal roetines in wat in die logboek gehou moet word en draai die logboek as dit vol is.
- `-s <filter>` : Stel 'n filter in vir die logboek.
- `-t <aantal>` : Druk die laaste aantal roetines uit.
- `-v <formaat>` : Stel die uitvoervormaat van die logboek in.
- `-w <lêernaam>` : Skryf die logboek na 'n lêer en bly voortgaan.
Voorbeelde:
- `adb logcat` : Druk die volledige logboek na die skerm.
- `adb logcat -d` : Druk die volledige logboek na die skerm en stop.
- `adb logcat -f log.txt` : Skryf die volledige logboek na 'n lêer met die naam "log.txt".
- `adb logcat -s TAG` : Druk slegs die logboekinskrywings met die spesifieke tag "TAG" na die skerm.
2024-02-08 03:06:37 +00:00
```bash
adb logcat
```
2024-02-11 02:07:06 +00:00
Notas: druk Ctrl-C om moniter te stop.
2024-02-08 03:06:37 +00:00
```bash
adb logcat *:V # lowest priority, filter to only show Verbose level
2024-02-08 03:06:37 +00:00
adb logcat *:D # filter to only show Debug level
2024-02-08 03:06:37 +00:00
adb logcat *:I # filter to only show Info level
2024-02-08 03:06:37 +00:00
adb logcat *:W # filter to only show Warning level
2024-02-08 03:06:37 +00:00
adb logcat *:E # filter to only show Error level
2024-02-08 03:06:37 +00:00
adb logcat *:F # filter to only show Fatal level
2024-02-08 03:06:37 +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>
2024-02-11 02:07:06 +00:00
Hierdie opdrag word gebruik om die logboekinskrywings van 'n spesifieke buffer in die Android-toestel se logboek te sien. Die buffers sluit in `main`, `system`, `radio`, `events` en `crash`.
Gebruik die volgende sintaksis om die logboekinskrywings van 'n spesifieke buffer te sien:
```
adb logcat -b <buffer>
```
Vervang `<buffer>` met die naam van die gewenste buffer, byvoorbeeld `main`, `system`, `radio`, `events` of `crash`.
2024-02-08 03:06:37 +00:00
```bash
adb logcat -b # radio View the buffer that contains radio/telephony related messages.
2024-02-08 03:06:37 +00:00
adb logcat -b # event View the buffer containing events-related messages.
2024-02-08 03:06:37 +00:00
adb logcat -b # main default
2024-02-08 03:06:37 +00:00
adb logcat -c # Clears the entire log and exits.
2024-02-08 03:06:37 +00:00
adb logcat -d # Dumps the log to the screen and exits.
2024-02-08 03:06:37 +00:00
adb logcat -f test.logs # Writes log message output to test.logs .
2024-02-08 03:06:37 +00:00
adb logcat -g # Prints the size of the specified log buffer and exits.
2024-02-11 02:07:06 +00:00
adb logcat -n <count> # Sets the maximum number of rotated logs to <count>.
```
2022-05-01 12:41:36 +00:00
## dumpsys
2024-02-11 02:07:06 +00:00
stort stelseldata uit
2024-02-11 02:07:06 +00:00
### adb shell dumpsys \[opsies]
2024-02-08 03:06:37 +00:00
```bash
adb shell dumpsys
adb shell dumpsys meminfo
adb shell dumpsys battery
```
2024-02-11 02:07:06 +00:00
Notas: 'n mobiele toestel met Ontwikkelaarsopties wat Android 5.0 of hoër hardloop.
2024-02-08 03:06:37 +00:00
```bash
adb shell dumpsys batterystats collects battery data from your device
```
2024-02-11 02:07:06 +00:00
Notas: [Battery Historian](https://github.com/google/battery-historian) omskep daardie data na 'n HTML-visualisering. **STAP 1** _adb shell dumpsys batterystats > batterystats.txt_ **STAP 2** _python historian.py batterystats.txt > batterystats.html_
2024-02-08 03:06:37 +00:00
```bash
adb shell dumpsys batterystats --reset erases old collection data
```
2024-02-11 02:07:06 +00:00
adb skulp aktiwiteit
2024-02-11 02:07:06 +00:00
# Rugsteun
2024-02-11 02:07:06 +00:00
Maak 'n rugsteun van 'n Android-toestel vanuit 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
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
```
2024-02-11 02:07:06 +00:00
As jy die inhoud van die rugsteun wil ondersoek:
2021-02-17 12:07:55 +00:00
```bash
( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) | tar xfvz -
```
2022-04-28 16:01:33 +00:00
<details>
2024-02-11 02:07:06 +00:00
<summary><strong>Leer AWS-hacking van nul tot held met</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:07:06 +00:00
Ander maniere om HackTricks te ondersteun:
2022-04-28 16:01:33 +00:00
2024-02-11 02:07:06 +00:00
* As jy jou **maatskappy geadverteer wil sien in HackTricks** of **HackTricks in PDF wil aflaai**, kyk na die [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
* Kry die [**amptelike PEASS & HackTricks swag**](https://peass.creator-spring.com)
* Ontdek [**The PEASS Family**](https://opensea.io/collection/the-peass-family), ons versameling eksklusiewe [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Deel jou hacking-truuks deur PR's in te dien by die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github-opslagplekke.
2022-04-28 16:01:33 +00:00
</details>