hacktricks/mobile-pentesting/android-app-pentesting/adb-commands.md
2024-02-10 13:03:23 +00:00

341 lines
12 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<details>
<summary><strong>Impara l'hacking di AWS da zero a eroe con</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
Altri modi per supportare HackTricks:
* Se vuoi vedere la tua **azienda pubblicizzata su HackTricks** o **scaricare HackTricks in PDF** Controlla i [**PIANI DI ABBONAMENTO**](https://github.com/sponsors/carlospolop)!
* Ottieni il [**merchandising ufficiale di PEASS & HackTricks**](https://peass.creator-spring.com)
* Scopri [**The PEASS Family**](https://opensea.io/collection/the-peass-family), la nostra collezione di esclusive [**NFT**](https://opensea.io/collection/the-peass-family)
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo Telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Condividi i tuoi trucchi di hacking inviando PR ai repository github di** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud).
</details>
**Adb di solito si trova in:**
```bash
#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe
#MacOS
/Users/<username>/Library/Android/sdk/platform-tools/adb
```
**Informazioni ottenute da:** [**http://adbshell.com/**](http://adbshell.com)
# Connessione
```
adb devices
```
Questo elencherà i dispositivi connessi; se appare "_**non autorizzato**_", significa che devi **sbloccare** il tuo **telefono** e **accettare** la connessione.
Questo indica al dispositivo di avviare un server adb sulla porta 5555:
```
adb tcpip 5555
```
Connettiti a quell'IP e a quella porta:
```
adb connect <IP>:<PORT>
```
Se si verifica un errore come il seguente in un software Android virtuale (come Genymotion):
```
adb server version (41) doesn't match this client (36); killing...
```
È perché stai cercando di connetterti a un server ADB con una versione diversa. Prova semplicemente a trovare il file binario adb che il software sta utilizzando (vai su `C:\Program Files\Genymobile\Genymotion` e cerca adb.exe)
## Diversi dispositivi
Ogni volta che trovi **diversi dispositivi collegati al tuo computer**, dovrai **specificare su quale** desideri eseguire il comando adb.
```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
```
## Port Tunneling
Nel caso in cui la **porta adb** sia accessibile solo da **localhost** sul dispositivo Android ma **hai accesso tramite SSH**, puoi **inoltrare la porta 5555** e connetterti tramite adb:
```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
```
# Gestore dei pacchetti
## Installa/Disinstalla
### adb install \[opzione] \<percorso>
```bash
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 uninstall \[opzioni] \<PACKAGE>
Questa opzione viene utilizzata per disinstallare un'applicazione dal dispositivo Android tramite il comando adb. Per utilizzare questo comando, è necessario specificare il nome del pacchetto dell'applicazione che si desidera disinstallare.
```bash
adb uninstall com.test.app
adb uninstall -k com.test.app Keep the data and cache directories around after package removal.
```
## Pacchetti
Stampa tutti i pacchetti, opzionalmente solo quelli il cui nome del pacchetto contiene il testo in \<FILTER>.
### adb shell pm list packages \[opzioni] \<FILTER-STR>
```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>
Stampa il percorso dell'APK del .
```bash
adb shell pm path com.android.phone
```
### adb shell pm clear \<PACKAGE>
Elimina tutti i dati associati a un pacchetto.
```bash
adb shell pm clear com.test.abc
```
# Gestore di file
### adb pull \<remote> \[locale]
Scarica un file specificato da un emulatore/dispositivo al tuo computer.
```bash
adb pull /sdcard/demo.mp4 ./
```
### adb push \<locale> \<remoto>
Carica un file specificato dal tuo computer su un emulatore/dispositivo.
```bash
adb push test.apk /sdcard
```
# Cattura schermo/Registrazione schermo
### adb shell screencap \<nomefile>
Effettua una cattura dello schermo del dispositivo.
```bash
adb shell screencap /sdcard/screen.png
```
### adb shell screenrecord \[opzioni] \<nomefile>
Registra la visualizzazione dei dispositivi che eseguono Android 4.4 (API level 19) e versioni successive.
```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
```
(premi Ctrl-C per interrompere la registrazione)
**Puoi scaricare i file (immagini e video) utilizzando **_**adb pull**_
# Shell
### adb shell
Ottieni una shell all'interno del dispositivo
```bash
adb shell
```
### adb shell \<CMD>
Esegui un comando all'interno del dispositivo
```bash
adb shell ls
```
## pm
I seguenti comandi vengono eseguiti all'interno di una 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
```
# Processi
Se desideri ottenere il PID del processo della tua applicazione, puoi eseguire:
```bash
adb shell ps
```
E cerca la tua applicazione
Oppure puoi fare
```bash
adb shell pidof com.your.application
```
E stamperà il PID dell'applicazione
# Sistema
```bash
adb root
```
Riavvia il demone adbd con i permessi di root. Successivamente, devi riconnetterti al server ADB e sarai root (se disponibile).
```bash
adb sideload <update.zip>
```
# Ripristino/aggiornamento pacchetti Android update.zip.
# Log
## Logcat
Per **filtrare i messaggi di una sola applicazione**, ottieni il PID dell'applicazione e utilizza grep (linux/macos) o findstr (windows) per filtrare l'output di logcat:
```bash
adb logcat | grep 4526
adb logcat | findstr 4526
```
### adb logcat \[opzione] \[specifiche-filtro]
Il comando `adb logcat` consente di visualizzare i log del sistema Android su un dispositivo collegato tramite ADB (Android Debug Bridge). È possibile utilizzare diverse opzioni e specifiche di filtro per personalizzare l'output dei log.
**Opzioni:**
- `-d` : Mostra i log correnti e termina.
- `-f <file>` : Salva i log in un file specificato.
- `-r <kbytes>` : Limita la dimensione del file di log a un numero specificato di kilobyte.
- `-n <count>` : Limita il numero di file di log mantenuti.
- `-v <format>` : Specifica il formato di output dei log. I formati disponibili includono brief, process, tag, thread, raw, time, threadtime e long.
**Specifiche di filtro:**
Le specifiche di filtro consentono di filtrare i log in base a determinati criteri. Alcuni esempi di specifiche di filtro includono:
- `*:S` : Mostra tutti i log con priorità di livello "silenziato" o superiore.
- `TAG:V` : Mostra tutti i log per il tag specificato con priorità di livello "verbose" o superiore.
- `TAG:D *:S` : Mostra tutti i log per il tag specificato con priorità di livello "debug" o superiore e silenzia tutti gli altri log.
È possibile combinare più specifiche di filtro utilizzando l'operatore `;`. Ad esempio, `TAG1:V TAG2:D` mostrerà i log per entrambi i tag con priorità di livello "verbose" e "debug" rispettivamente.
Per ulteriori informazioni sulle opzioni e le specifiche di filtro disponibili, consultare la documentazione ufficiale di ADB.
```bash
adb logcat
```
Note: premi Ctrl-C per interrompere il monitoraggio
```bash
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>
Il comando `adb logcat -b \<Buffer>` viene utilizzato per visualizzare i log del buffer specificato. I buffer disponibili includono `main`, `system`, `radio`, `events` e `crash`. Questo comando è utile per analizzare i log di un'applicazione Android e identificare eventuali errori o problemi.
```bash
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
esegue il dump dei dati di sistema
### adb shell dumpsys \[opzioni]
```bash
adb shell dumpsys
adb shell dumpsys meminfo
adb shell dumpsys battery
```
Note: Un dispositivo mobile con le Opzioni Sviluppatore abilitate che esegue Android 5.0 o versioni successive.
```bash
adb shell dumpsys batterystats collects battery data from your device
```
Note: [Battery Historian](https://github.com/google/battery-historian) converte quei dati in una visualizzazione HTML. **PASSO 1** _adb shell dumpsys batterystats > batterystats.txt_ **PASSO 2** _python historian.py batterystats.txt > batterystats.html_
```bash
adb shell dumpsys batterystats --reset erases old collection data
```
adb shell dumpsys activity
# Backup
Esegui il backup di un dispositivo Android tramite 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
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
```
Se vuoi ispezionare il contenuto del backup:
```bash
( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) | tar xfvz -
```
<details>
<summary><strong>Impara l'hacking di AWS da zero a eroe con</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
Altri modi per supportare HackTricks:
* Se vuoi vedere la tua **azienda pubblicizzata su HackTricks** o **scaricare HackTricks in PDF** Controlla i [**PIANI DI ABBONAMENTO**](https://github.com/sponsors/carlospolop)!
* Ottieni il [**merchandising ufficiale di PEASS & HackTricks**](https://peass.creator-spring.com)
* Scopri [**The PEASS Family**](https://opensea.io/collection/the-peass-family), la nostra collezione di esclusive [**NFT**](https://opensea.io/collection/the-peass-family)
* **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo Telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
* **Condividi i tuoi trucchi di hacking inviando PR ai repository github di** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud).
</details>