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

318 lines
10 KiB
Markdown
Raw Normal View History

{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Wsparcie HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Sprawdź [**plany subskrypcyjne**](https://github.com/sponsors/carlospolop)!
* **Dołącz do** 💬 [**grupy Discord**](https://discord.gg/hRep4RUj7f) lub [**grupy telegramowej**](https://t.me/peass) lub **śledź** nas na **Twitterze** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Dziel się trikami hackingowymi, przesyłając PR-y do** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repozytoriów github.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}
2022-04-28 16:01:33 +00:00
2024-02-11 01:46:25 +00:00
**Adb zazwyczaj znajduje się w:**
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 01:46:25 +00:00
**Informacje uzyskane z:** [**http://adbshell.com/**](http://adbshell.com)
2021-04-22 13:58:44 +00:00
2024-02-11 01:46:25 +00:00
# Połączenie
```
adb devices
```
To będzie lista podłączonych urządzeń; jeśli "_**nieautoryzowane**_" się pojawi, oznacza to, że musisz **odblokować** swój **telefon** i **zaakceptować** połączenie.
To wskazuje urządzeniu, że musi uruchomić serwer adb na porcie 5555:
```
adb tcpip 5555
```
Połącz się z tym adresem IP i tym portem:
```
adb connect <IP>:<PORT>
```
Jeśli otrzymasz błąd podobny do poniższego w wirtualnym oprogramowaniu Android (takim jak Genymotion):
```
adb server version (41) doesn't match this client (36); killing...
```
To dlatego, że próbujesz połączyć się z serwerem ADB o innej wersji. Po prostu spróbuj znaleźć binarkę adb, której używa oprogramowanie (przejdź do `C:\Program Files\Genymobile\Genymotion` i wyszukaj adb.exe)
## Kilka urządzeń
2021-07-04 09:43:18 +00:00
Kiedy znajdziesz **kilka urządzeń podłączonych do twojego komputera**, będziesz musiał **określić, na którym** chcesz uruchomić polecenie adb.
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 01:46:25 +00:00
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
2021-07-04 09:43:18 +00:00
root
```
## Port Tunneling
2021-07-04 09:43:18 +00:00
W przypadku, gdy **port** **adb** jest dostępny tylko z **localhost** na urządzeniu z androidem, ale **masz dostęp przez SSH**, możesz **przekierować port 5555** i połączyć się przez 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
```
# Menedżer Pakietów
2021-07-04 09:43:18 +00:00
## Instalacja/Deinstalacja
2024-02-11 01:46:25 +00:00
### adb install \[opcja] \<ścieżka>
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
```
### adb uninstall \[options] \<PACKAGE>
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-11 01:46:25 +00:00
## Pakiety
Wyświetla wszystkie pakiety, opcjonalnie tylko te, których nazwa pakietu zawiera tekst w \<FILTER>.
### adb shell pm list packages \[options] \<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.
```
### adb shell pm path \<PACKAGE>
Wyświetla ścieżkę do APK podanego .
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-11 01:46:25 +00:00
Usuń wszystkie dane związane z pakietem.
2024-02-08 04:06:37 +01:00
```bash
adb shell pm clear com.test.abc
```
# File Manager
### adb pull \<remote> \[local]
2024-02-11 01:46:25 +00:00
Pobierz określony plik z emulatora/urządzenia na swój komputer.
2024-02-08 04:06:37 +01:00
```bash
adb pull /sdcard/demo.mp4 ./
```
### adb push \<local> \<remote>
Prześlij określony plik z komputera do emulatora/urządzenia.
2024-02-08 04:06:37 +01:00
```bash
adb push test.apk /sdcard
```
# Screencapture/Screenrecord
### adb shell screencap \<filename>
Robienie zrzutu ekranu wyświetlacza urządzenia.
2024-02-08 04:06:37 +01:00
```bash
adb shell screencap /sdcard/screen.png
```
### adb shell screenrecord \[options] \<filename>
Nagrywanie wyświetlacza urządzeń działających na Androidzie 4.4 (poziom API 19) i wyższych.
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)
**Możesz pobrać pliki (obrazy i filmy) używając **_**adb pull**_
# Shell
2022-05-01 13:41:36 +01:00
### adb shell
Uzyskaj dostęp do powłoki wewnątrz urządzenia
2024-02-08 04:06:37 +01:00
```bash
adb shell
```
2022-05-01 13:41:36 +01:00
### adb shell \<CMD>
2024-02-11 01:46:25 +00:00
Wykonaj polecenie wewnątrz urządzenia
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
Następujące polecenia są wykonywane w obrębie powłoki
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 01:46:25 +00:00
# Procesy
2021-04-22 13:58:44 +00:00
Jeśli chcesz uzyskać PID procesu swojej aplikacji, możesz wykonać:
2024-02-08 04:06:37 +01:00
```bash
adb shell ps
```
2024-02-11 01:46:25 +00:00
I wyszukaj swoją aplikację
2024-02-11 01:46:25 +00:00
Lub możesz zrobić
2024-02-08 04:06:37 +01:00
```bash
adb shell pidof com.your.application
```
2024-02-11 01:46:25 +00:00
I wydrukuje PID aplikacji
2022-05-01 13:41:36 +01:00
# System
2024-02-08 04:06:37 +01:00
```bash
adb root
```
Restartuje demona adbd z uprawnieniami roota. Następnie musisz ponownie połączyć się z serwerem ADB i będziesz rootem (jeśli dostępny).
2024-02-08 04:06:37 +01:00
```bash
adb sideload <update.zip>
```
flashing/restoring Android update.zip packages.
# Logs
2022-05-01 13:41:36 +01:00
## Logcat
Aby **filtrować wiadomości tylko jednej aplikacji**, uzyskaj PID aplikacji i użyj grep (linux/macos) lub findstr (windows), aby filtrować wyjście logcat:
2024-02-08 04:06:37 +01:00
```bash
adb logcat | grep 4526
adb logcat | findstr 4526
```
### adb logcat \[option] \[filter-specs]
2024-02-08 04:06:37 +01:00
```bash
adb logcat
```
Notes: naciśnij Ctrl-C, aby zatrzymać monitor
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
```
### adb logcat -b \<Buffer>
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-11 01:46:25 +00:00
adb logcat -n <count> # Sets the maximum number of rotated logs to <count>.
```
2022-05-01 13:41:36 +01:00
## dumpsys
zrzut danych systemowych
### adb shell dumpsys \[options]
2024-02-08 04:06:37 +01:00
```bash
adb shell dumpsys
adb shell dumpsys meminfo
adb shell dumpsys battery
```
Notes: Urządzenie mobilne z włączonymi Opcjami dewelopera działające na Androidzie 5.0 lub wyższym.
2024-02-08 04:06:37 +01:00
```bash
adb shell dumpsys batterystats collects battery data from your device
```
Notatki: [Battery Historian](https://github.com/google/battery-historian) przekształca te dane w wizualizację HTML. **KROK 1** _adb shell dumpsys batterystats > batterystats.txt_ **KROK 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-11 01:46:25 +00:00
Zrób kopię zapasową urządzenia z systemem Android za pomocą 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 01:46:25 +00:00
Jeśli chcesz sprawdzić zawartość kopii zapasowej:
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 -
```
{% hint style="success" %}
Ucz się i ćwicz Hacking AWS:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Ucz się i ćwicz Hacking GCP: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Wsparcie dla HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Sprawdź [**plany subskrypcyjne**](https://github.com/sponsors/carlospolop)!
* **Dołącz do** 💬 [**grupy Discord**](https://discord.gg/hRep4RUj7f) lub [**grupy telegramowej**](https://t.me/peass) lub **śledź** nas na **Twitterze** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Dziel się sztuczkami hackingowymi, przesyłając PR-y do** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repozytoriów github.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}