ADB Commands

Lernen Sie AWS-Hacking von Null auf Held mit htARTE (HackTricks AWS Red Team Expert)!

Andere Möglichkeiten, HackTricks zu unterstützen:

Adb befindet sich normalerweise in:

#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe

#MacOS
/Users/<username>/Library/Android/sdk/platform-tools/adb

Information obtained from: http://adbshell.com/

Verbindung

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:

adb devices
  1. If the device is listed, you can proceed with executing ADB commands.

ADB over Wi-Fi

To establish a connection between your computer and an Android device using ADB over Wi-Fi, 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:

adb devices
  1. If the device is listed, run the following command to enable ADB over Wi-Fi:

adb tcpip 5555
  1. Disconnect the USB cable from the Android device.

  2. Find the IP address of the Android device. You can check it in the device settings or by running the following command:

adb shell ip -f inet addr show wlan0
  1. Run the following command to connect to the Android device over Wi-Fi:

adb connect <device_ip_address>:5555
  1. 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:

adb devices
  1. If the device is listed, run the following command to enable ADB over TCP/IP:

adb tcpip <port_number>
  1. Disconnect the USB cable from the Android device.

  2. Run the following command to connect to the Android device over TCP/IP:

adb connect <device_ip_address>:<port_number>
  1. 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.

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).

Mehrere Geräte

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.

adb devices
List of devices attached
10.10.10.247:42135	offline
127.0.0.1:5555	device
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
root

Port-Tunneling

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:

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

Paketmanager

Installieren/Deinstallieren

adb install [Option] <Pfad>

adb install test.apk

adb install -l test.apk # forward lock application

adb install -r test.apk # replace existing application

adb install -t test.apk # allow test packages

adb install -s test.apk # install application on sdcard

adb install -d test.apk # allow version code downgrade

adb install -p test.apk # partial application install

adb deinstallieren [Optionen] <PAKET>

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.

adb uninstall com.test.app

adb uninstall -k com.test.app Keep the data and cache directories around after package removal.

Pakete

Gibt alle Pakete aus, optional nur diejenigen, deren Paketname den Text in <FILTER> enthält.

adb shell pm list packages [Optionen] <FILTER-STR>

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.

adb shell pm path <PACKAGE>

Gibt den Pfad zur APK der angegebenen <PACKAGE> aus.

adb shell pm path com.android.phone

adb shell pm clear <PACKAGE>

Löscht alle Daten, die mit einer Anwendung verknüpft sind.

adb shell pm clear com.test.abc

Dateimanager

adb pull <remote> [local]

Laden Sie eine bestimmte Datei von einem Emulator/Gerät auf Ihren Computer herunter.

adb pull /sdcard/demo.mp4 ./

adb push <local> <remote>

Laden Sie eine bestimmte Datei von Ihrem Computer auf einen Emulator/ein Gerät hoch.

adb push test.apk /sdcard

Screencapture/Screenrecord

adb shell screencap <Dateiname>

Erstellen eines Screenshots des Gerätedisplays.

adb shell screencap /sdcard/screen.png

adb shell screenrecord [Optionen] <Dateiname>

Aufzeichnen der Anzeige von Geräten mit Android 4.4 (API-Level 19) und höher.

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)

Sie können die Dateien (Bilder und Videos) mit dem Befehl adb pull herunterladen

Shell

adb shell

Erhalten Sie eine Shell innerhalb des Geräts

adb shell

adb shell <CMD>

Führe einen Befehl innerhalb des Geräts aus.

adb shell ls

pm

Die folgenden Befehle werden innerhalb einer Shell ausgeführt.

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

Prozesse

Wenn Sie die PID des Prozesses Ihrer Anwendung erhalten möchten, können Sie Folgendes ausführen:

adb shell ps

Und suche nach deiner Anwendung

Oder du kannst auch

adb shell pidof com.your.application

Und es wird die PID der Anwendung ausgeben

System

adb root

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).

adb sideload <update.zip>

Protokolle

Logcat

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:

adb logcat | grep 4526
adb logcat | findstr 4526

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.

Filter-Spezifikationen:

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.

adb logcat

Notizen: Drücken Sie Strg-C, um die Überwachung zu stoppen.

adb logcat *:V # lowest priority, filter to only show Verbose level

adb logcat *:D # filter to only show Debug level

adb logcat *:I # filter to only show Info level

adb logcat *:W # filter to only show Warning level

adb logcat *:E # filter to only show Error level

adb logcat *:F # filter to only show Fatal level

adb logcat *:S # Silent, highest priority, on which nothing is ever printed

adb logcat -b <Buffer>

Dieser Befehl ermöglicht es, den Logcat-Puffer auf einem Android-Gerät abzurufen. Der Parameter <Buffer> gibt an, welcher Puffer abgerufen werden soll.

adb logcat -b # radio View the buffer that contains radio/telephony related messages.

adb logcat -b # event View the buffer containing events-related messages.

adb logcat -b # main default

adb logcat -c # Clears the entire log and exits.

adb logcat -d # Dumps the log to the screen and exits.

adb logcat -f test.logs # Writes log message output to test.logs .

adb logcat -g # Prints the size of the specified log buffer and exits.

adb logcat -n <count> # Sets the maximum number of rotated logs to <count>.

dumpsys

dumps system data

adb shell dumpsys [Optionen]

adb shell dumpsys

adb shell dumpsys meminfo

adb shell dumpsys battery

Notizen: Ein mobiles Gerät mit aktivierten Entwickleroptionen, das Android 5.0 oder höher ausführt.

adb shell dumpsys batterystats collects battery data from your device

Notizen: 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

adb shell dumpsys batterystats --reset erases old collection data

adb shell dumpsys activity

Backup

Sichern Sie ein Android-Gerät über adb.

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
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

Wenn Sie den Inhalt des Backups inspizieren möchten:

( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) |  tar xfvz -
Lernen Sie AWS-Hacking von Null auf Held mit htARTE (HackTricks AWS Red Team Expert)!

Andere Möglichkeiten, HackTricks zu unterstützen:

Last updated