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

425 lines
16 KiB
Markdown
Raw Normal View History

2022-04-28 16:01:33 +00:00
<details>
2024-02-10 15:36:32 +00:00
<summary><strong>Lernen Sie AWS-Hacking von Null auf Held mit</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-10 15:36:32 +00:00
Andere Möglichkeiten, HackTricks zu unterstützen:
2022-04-28 16:01:33 +00:00
2024-02-10 15:36:32 +00:00
* Wenn Sie Ihr **Unternehmen in HackTricks bewerben möchten** oder **HackTricks als PDF herunterladen möchten**, überprüfen Sie die [**ABONNEMENTPLÄNE**](https://github.com/sponsors/carlospolop)!
* Holen Sie sich das [**offizielle PEASS & HackTricks-Merchandise**](https://peass.creator-spring.com)
* Entdecken Sie [**The PEASS Family**](https://opensea.io/collection/the-peass-family), unsere Sammlung exklusiver [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Treten Sie der** 💬 [**Discord-Gruppe**](https://discord.gg/hRep4RUj7f) oder der [**Telegram-Gruppe**](https://t.me/peass) bei oder **folgen** Sie uns auf **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Teilen Sie Ihre Hacking-Tricks, indem Sie PRs an die** [**HackTricks**](https://github.com/carlospolop/hacktricks) und [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) GitHub-Repositories senden.
2022-04-28 16:01:33 +00:00
</details>
2024-02-10 15:36:32 +00:00
**Adb befindet sich normalerweise 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
```
2022-04-05 18:24:52 -04:00
**Information obtained from:** [**http://adbshell.com/**](http://adbshell.com)
2024-02-10 15:36:32 +00:00
# Verbindung
2024-02-10 15:36:32 +00:00
## ADB over USB
To establish a connection between your computer and an Android device using ADB over USB, follow these steps:
1. Enable USB debugging on the Android device.
2. Connect the Android device to your computer using a USB cable.
3. Open a terminal or command prompt on your computer.
4. Navigate to the directory where the ADB executable is located.
5. Run the following command to check if the device is connected:
```bash
adb devices
```
2024-02-10 15:36:32 +00:00
6. If the device is listed, you can proceed with executing ADB commands.
## ADB over Wi-Fi
2024-02-10 15:36:32 +00:00
To establish a connection between your computer and an Android device using ADB over Wi-Fi, follow these steps:
2024-02-10 15:36:32 +00:00
1. Connect the Android device to your computer using a USB cable.
2. Enable USB debugging on the Android device.
3. Open a terminal or command prompt on your computer.
4. Navigate to the directory where the ADB executable is located.
5. Run the following command to check if the device is connected:
```bash
adb devices
```
2024-02-10 15:36:32 +00:00
6. If the device is listed, run the following command to enable ADB over Wi-Fi:
```bash
adb tcpip 5555
```
2024-02-10 15:36:32 +00:00
7. Disconnect the USB cable from the Android device.
8. Find the IP address of the Android device. You can check it in the device settings or by running the following command:
2024-02-10 15:36:32 +00:00
```bash
adb shell ip -f inet addr show wlan0
```
2024-02-10 15:36:32 +00:00
9. Run the following command to connect to the Android device over Wi-Fi:
```bash
adb connect <device_ip_address>:5555
```
10. If the connection is successful, you can proceed with executing ADB commands.
## ADB over TCP/IP
To establish a connection between your computer and an Android device using ADB over TCP/IP, follow these steps:
1. Connect the Android device to your computer using a USB cable.
2. Enable USB debugging on the Android device.
3. Open a terminal or command prompt on your computer.
4. Navigate to the directory where the ADB executable is located.
5. Run the following command to check if the device is connected:
```bash
adb devices
```
2024-02-10 15:36:32 +00:00
6. If the device is listed, run the following command to enable ADB over TCP/IP:
2024-02-10 15:36:32 +00:00
```bash
adb tcpip <port_number>
```
2024-02-10 15:36:32 +00:00
7. Disconnect the USB cable from the Android device.
8. Run the following command to connect to the Android device over TCP/IP:
```bash
adb connect <device_ip_address>:<port_number>
```
2024-02-10 15:36:32 +00:00
9. If the connection is successful, you can proceed with executing ADB commands.
```
adb devices
```
Dies listet die verbundenen Geräte auf; wenn "_**unauthorisiert**_" angezeigt wird, bedeutet dies, dass Sie Ihr **Mobilgerät** **entsperren** und die Verbindung **akzeptieren** müssen.
2024-02-10 15:36:32 +00:00
Dies gibt dem Gerät an, dass es einen adb-Server auf Port 5555 starten muss:
```
adb tcpip 5555
```
Verbinde mit dieser IP und diesem Port:
```
adb connect <IP>:<PORT>
```
Wenn Sie einen Fehler wie den folgenden in einer virtuellen Android-Software (wie Genymotion) erhalten:
```
adb server version (41) doesn't match this client (36); killing...
```
Es liegt daran, dass du versuchst, dich mit einem ADB-Server mit einer anderen Version zu verbinden. Versuche einfach, die adb-Binärdatei zu finden, die die Software verwendet (gehe zu `C:\Program Files\Genymobile\Genymotion` und suche nach adb.exe).
2021-07-04 09:43:18 +00:00
2024-02-10 15:36:32 +00:00
## Mehrere Geräte
2021-07-04 09:43:18 +00:00
2024-02-10 15:36:32 +00:00
Immer wenn du **mehrere Geräte mit deinem Computer verbunden** findest, musst du angeben, auf welchem Gerät du den adb-Befehl ausführen möchtest.
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-10 15:36:32 +00:00
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
2021-07-04 09:43:18 +00:00
root
```
2024-02-10 15:36:32 +00:00
## Port-Tunneling
2021-07-04 09:43:18 +00:00
2024-02-10 15:36:32 +00:00
Falls der **adb-Port** auf dem Android-Gerät nur von **localhost** aus **zugänglich** ist, Sie jedoch über SSH-Zugriff verfügen, können Sie den Port 5555 **weiterleiten** und eine Verbindung über adb herstellen:
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-10 15:36:32 +00:00
# Paketmanager
2021-07-04 09:43:18 +00:00
2024-02-10 15:36:32 +00:00
## Installieren/Deinstallieren
2024-02-10 15:36:32 +00:00
### adb install \[Option] \<Pfad>
2024-02-08 04:06:37 +01:00
```bash
adb install test.apk
2024-02-08 04:06:37 +01:00
adb install -l test.apk # forward lock application
2024-02-08 04:06:37 +01:00
adb install -r test.apk # replace existing application
2024-02-08 04:06:37 +01:00
adb install -t test.apk # allow test packages
2024-02-08 04:06:37 +01:00
adb install -s test.apk # install application on sdcard
2024-02-08 04:06:37 +01:00
adb install -d test.apk # allow version code downgrade
2024-02-08 04:06:37 +01:00
adb install -p test.apk # partial application install
```
2024-02-10 15:36:32 +00:00
### adb deinstallieren \[Optionen] \<PAKET>
2024-02-10 15:36:32 +00:00
Dieser Befehl wird verwendet, um eine Android-App von einem Gerät zu deinstallieren. Das \<PAKET> Argument gibt den Paketnamen der App an, die deinstalliert werden soll. Es können auch verschiedene Optionen angegeben werden, um das Verhalten des Befehls anzupassen.
2024-02-08 04:06:37 +01: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-10 15:36:32 +00:00
## Pakete
2024-02-10 15:36:32 +00:00
Gibt alle Pakete aus, optional nur diejenigen, deren Paketname den Text in \<FILTER> enthält.
2024-02-10 15:36:32 +00:00
### adb shell pm list packages \[Optionen] \<FILTER-STR>
2024-02-08 04:06:37 +01: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.
```
2022-05-01 13:41:36 +01:00
### adb shell pm path \<PACKAGE>
2024-02-10 15:36:32 +00:00
Gibt den Pfad zur APK der angegebenen \<PACKAGE> aus.
2024-02-08 04:06:37 +01:00
```bash
adb shell pm path com.android.phone
```
2022-05-01 13:41:36 +01:00
### adb shell pm clear \<PACKAGE>
2024-02-10 15:36:32 +00:00
Löscht alle Daten, die mit einer Anwendung verknüpft sind.
2024-02-08 04:06:37 +01:00
```bash
adb shell pm clear com.test.abc
```
2024-02-10 15:36:32 +00:00
# Dateimanager
2022-05-01 13:41:36 +01:00
### adb pull \<remote> \[local]
2024-02-10 15:36:32 +00:00
Laden Sie eine bestimmte Datei von einem Emulator/Gerät auf Ihren Computer herunter.
2024-02-08 04:06:37 +01:00
```bash
adb pull /sdcard/demo.mp4 ./
```
2022-05-01 13:41:36 +01:00
### adb push \<local> \<remote>
2024-02-10 15:36:32 +00:00
Laden Sie eine bestimmte Datei von Ihrem Computer auf einen Emulator/ein Gerät hoch.
2024-02-08 04:06:37 +01:00
```bash
adb push test.apk /sdcard
```
2022-05-01 13:41:36 +01:00
# Screencapture/Screenrecord
2024-02-10 15:36:32 +00:00
### adb shell screencap \<Dateiname>
2024-02-10 15:36:32 +00:00
Erstellen eines Screenshots des Gerätedisplays.
2024-02-08 04:06:37 +01:00
```bash
adb shell screencap /sdcard/screen.png
```
2024-02-10 15:36:32 +00:00
### adb shell screenrecord \[Optionen] \<Dateiname>
2024-02-10 15:36:32 +00:00
Aufzeichnen der Anzeige von Geräten mit Android 4.4 (API-Level 19) und höher.
2024-02-08 04:06:37 +01: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
```
(press Ctrl-C to stop recording)
2024-02-10 15:36:32 +00:00
**Sie können die Dateien (Bilder und Videos) mit dem Befehl** _**adb pull**_ **herunterladen**
2022-05-01 13:41:36 +01:00
# Shell
2022-05-01 13:41:36 +01:00
### adb shell
2024-02-10 15:36:32 +00:00
Erhalten Sie eine Shell innerhalb des Geräts
2024-02-08 04:06:37 +01:00
```bash
adb shell
```
2022-05-01 13:41:36 +01:00
### adb shell \<CMD>
2024-02-10 15:36:32 +00:00
Führe einen Befehl innerhalb des Geräts aus.
2024-02-08 04:06:37 +01:00
```bash
adb shell ls
```
2022-05-01 13:41:36 +01:00
## pm
2021-04-22 13:58:44 +00:00
2024-02-10 15:36:32 +00:00
Die folgenden Befehle werden innerhalb einer Shell ausgeführt.
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-10 15:36:32 +00:00
# Prozesse
2021-04-22 13:58:44 +00:00
2024-02-10 15:36:32 +00:00
Wenn Sie die PID des Prozesses Ihrer Anwendung erhalten möchten, können Sie Folgendes ausführen:
2024-02-08 04:06:37 +01:00
```bash
adb shell ps
```
2024-02-10 15:36:32 +00:00
Und suche nach deiner Anwendung
2024-02-10 15:36:32 +00:00
Oder du kannst auch
2024-02-08 04:06:37 +01:00
```bash
adb shell pidof com.your.application
```
2024-02-10 15:36:32 +00:00
Und es wird die PID der Anwendung ausgeben
2022-05-01 13:41:36 +01:00
# System
2024-02-08 04:06:37 +01:00
```bash
adb root
```
2024-02-10 15:36:32 +00:00
Startet den adbd-Daemon mit Root-Berechtigungen neu. Anschließend musst du dich erneut mit dem ADB-Server verbinden und du wirst Root-Zugriff haben (falls verfügbar).
2024-02-08 04:06:37 +01:00
```bash
adb sideload <update.zip>
```
2024-02-10 15:36:32 +00:00
# Protokolle
2022-05-01 13:41:36 +01:00
## Logcat
2024-02-10 15:36:32 +00:00
Um die Nachrichten nur einer Anwendung zu filtern, erhalten Sie die PID der Anwendung und verwenden Sie grep (Linux/MacOS) oder findstr (Windows), um die Ausgabe von logcat zu filtern:
2024-02-08 04:06:37 +01:00
```bash
adb logcat | grep 4526
adb logcat | findstr 4526
```
2024-02-10 15:36:32 +00:00
### adb logcat \[Option] \[Filter-Spezifikationen]
Die `adb logcat`-Befehl ermöglicht es, die Logcat-Meldungen von einem Android-Gerät abzurufen. Logcat ist ein Systemprotokoll, das Informationen über verschiedene Ereignisse und Fehler auf dem Gerät protokolliert. Mit diesem Befehl können verschiedene Optionen und Filter-Spezifikationen angegeben werden, um die Art der abgerufenen Logcat-Meldungen zu steuern.
#### Optionen:
- `-v <Format>`: Gibt das gewünschte Format für die Logcat-Meldungen an. Mögliche Werte sind `brief`, `process`, `tag`, `thread`, `raw`, `time`, `threadtime` und `long`.
- `-d`: Gibt die letzten Logcat-Meldungen aus und beendet den Befehl.
- `-f <Datei>`: Speichert die Logcat-Meldungen in einer Datei.
- `-r <Anzahl>`: Rotiert die Logcat-Ausgabe nach einer bestimmten Anzahl von Bytes.
- `-n <Anzahl>`: Behält nur eine bestimmte Anzahl von rotierten Logcat-Dateien.
- `-c`: Löscht die Logcat-Puffer vor dem Abrufen der Meldungen.
- `-s <Filter-Spezifikation>`: Filtert die Logcat-Meldungen basierend auf einer bestimmten Filter-Spezifikation.
- `-e <Filter-Spezifikation>`: Filtert die Logcat-Meldungen aus, die der angegebenen Filter-Spezifikation entsprechen.
- `-i`: Ignoriert alle Meldungen, die nicht mit dem angegebenen Filter übereinstimmen.
- `-p`: Gibt die PID (Prozess-ID) in den Logcat-Meldungen aus.
- `-t <Anzahl>`: Gibt nur die letzten N Logcat-Meldungen aus.
2024-02-10 15:36:32 +00:00
#### Filter-Spezifikationen:
2024-02-10 15:36:32 +00:00
Die Filter-Spezifikationen ermöglichen es, die Logcat-Meldungen basierend auf verschiedenen Kriterien zu filtern. Hier sind einige Beispiele für Filter-Spezifikationen:
- `*:S`: Zeigt alle Meldungen mit dem Tag "S" an.
- `MyApp:D *:S`: Zeigt alle Debug-Meldungen der App "MyApp" und alle Meldungen mit dem Tag "S" an.
- `*:W | MyApp:E`: Zeigt alle Warnungen und Fehler der App "MyApp" an.
- `*:I MyApp:V`: Zeigt alle Informationen der App "MyApp" an.
Es gibt viele weitere Optionen und Filter-Spezifikationen, die verwendet werden können, um die Logcat-Meldungen nach Bedarf anzupassen.
2024-02-08 04:06:37 +01:00
```bash
adb logcat
```
2024-02-10 15:36:32 +00:00
Notizen: Drücken Sie Strg-C, um die Überwachung zu stoppen.
2024-02-08 04:06:37 +01:00
```bash
adb logcat *:V # lowest priority, filter to only show Verbose level
2024-02-08 04:06:37 +01:00
adb logcat *:D # filter to only show Debug level
2024-02-08 04:06:37 +01:00
adb logcat *:I # filter to only show Info level
2024-02-08 04:06:37 +01:00
adb logcat *:W # filter to only show Warning level
2024-02-08 04:06:37 +01:00
adb logcat *:E # filter to only show Error level
2024-02-08 04:06:37 +01:00
adb logcat *:F # filter to only show Fatal level
2024-02-08 04:06:37 +01:00
adb logcat *:S # Silent, highest priority, on which nothing is ever printed
```
2022-05-01 13:41:36 +01:00
### adb logcat -b \<Buffer>
2024-02-10 15:36:32 +00:00
Dieser Befehl ermöglicht es, den Logcat-Puffer auf einem Android-Gerät abzurufen. Der Parameter \<Buffer> gibt an, welcher Puffer abgerufen werden soll.
2024-02-08 04:06:37 +01:00
```bash
adb logcat -b # radio View the buffer that contains radio/telephony related messages.
2024-02-08 04:06:37 +01:00
adb logcat -b # event View the buffer containing events-related messages.
2024-02-08 04:06:37 +01:00
adb logcat -b # main default
2024-02-08 04:06:37 +01:00
adb logcat -c # Clears the entire log and exits.
2024-02-08 04:06:37 +01:00
adb logcat -d # Dumps the log to the screen and exits.
2024-02-08 04:06:37 +01:00
adb logcat -f test.logs # Writes log message output to test.logs .
2024-02-08 04:06:37 +01:00
adb logcat -g # Prints the size of the specified log buffer and exits.
2024-02-10 15:36:32 +00:00
adb logcat -n <count> # Sets the maximum number of rotated logs to <count>.
```
2022-05-01 13:41:36 +01:00
## dumpsys
dumps system data
2024-02-10 15:36:32 +00:00
### adb shell dumpsys \[Optionen]
2024-02-08 04:06:37 +01:00
```bash
adb shell dumpsys
adb shell dumpsys meminfo
adb shell dumpsys battery
```
2024-02-10 15:36:32 +00:00
Notizen: Ein mobiles Gerät mit aktivierten Entwickleroptionen, das Android 5.0 oder höher ausführt.
2024-02-08 04:06:37 +01:00
```bash
adb shell dumpsys batterystats collects battery data from your device
```
2024-02-10 15:36:32 +00:00
Notizen: [Battery Historian](https://github.com/google/battery-historian) wandelt diese Daten in eine HTML-Visualisierung um. **SCHRITT 1** _adb shell dumpsys batterystats > batterystats.txt_ **SCHRITT 2** _python historian.py batterystats.txt > batterystats.html_
2024-02-08 04:06:37 +01:00
```bash
adb shell dumpsys batterystats --reset erases old collection data
```
adb shell dumpsys activity
2022-05-01 13:41:36 +01:00
# Backup
2024-02-10 15:36:32 +00:00
Sichern Sie ein Android-Gerät über 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-10 15:36:32 +00:00
Wenn Sie den Inhalt des Backups inspizieren möchten:
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-10 15:36:32 +00:00
<summary><strong>Lernen Sie AWS-Hacking von Null auf Held mit</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-10 15:36:32 +00:00
Andere Möglichkeiten, HackTricks zu unterstützen:
2022-04-28 16:01:33 +00:00
2024-02-10 15:36:32 +00:00
* Wenn Sie Ihr **Unternehmen in HackTricks bewerben möchten** oder **HackTricks als PDF herunterladen möchten**, überprüfen Sie die [**ABONNEMENTPLÄNE**](https://github.com/sponsors/carlospolop)!
* Holen Sie sich das [**offizielle PEASS & HackTricks-Merchandise**](https://peass.creator-spring.com)
* Entdecken Sie [**The PEASS Family**](https://opensea.io/collection/the-peass-family), unsere Sammlung exklusiver [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Treten Sie der** 💬 [**Discord-Gruppe**](https://discord.gg/hRep4RUj7f) oder der [**Telegram-Gruppe**](https://t.me/peass) bei oder **folgen** Sie uns auf **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Teilen Sie Ihre Hacking-Tricks, indem Sie PRs an die** [**HackTricks**](https://github.com/carlospolop/hacktricks) und [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) GitHub-Repositories senden.
2022-04-28 16:01:33 +00:00
</details>