2023-06-06 18:56:34 +00:00
**Adb geralmente está localizado em:**
```bash
#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
#MacOS
/Users/< username > /Library/Android/sdk/platform-tools/adb
```
# Conexão
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
## Connect to a device over Wi-Fi
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
## Conectar a um dispositivo via Wi-Fi
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
1. Connect the device to the same Wi-Fi network as your computer.
1. Conecte o dispositivo à mesma rede Wi-Fi que o seu computador.
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
2. Connect the device to your computer with a USB cable.
2. Conecte o dispositivo ao seu computador com um cabo USB.
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
3. Open a terminal and type the following command:
3. Abra um terminal e digite o seguinte comando:
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
```
adb tcpip 5555
```
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
4. Disconnect the USB cable from the device.
4. Desconecte o cabo USB do dispositivo.
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
5. Find the IP address of the device. You can find it in Settings > About phone > Status > IP address.
5. Encontre o endereço IP do dispositivo. Você pode encontrá-lo em Configurações > Sobre o telefone > Status > Endereço IP.
2021-04-22 13:58:44 +00:00
2023-06-06 18:56:34 +00:00
6. Open a terminal and type the following command:
6. Abra um terminal e digite o seguinte comando:
2021-04-22 13:58:44 +00:00
2023-06-06 18:56:34 +00:00
```
adb connect < device-ip-address > :5555
2021-04-22 13:58:44 +00:00
```
2023-06-06 18:56:34 +00:00
7. If everything worked correctly, you should see a message saying "connected to < device-ip-address > :5555".
7. Se tudo funcionou corretamente, você deve ver uma mensagem dizendo "conectado a < device-ip-address > :5555".
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb devices
```
2023-06-06 18:56:34 +00:00
Isso irá listar os dispositivos conectados; se "_**unathorised**_" aparecer, isso significa que você tem que **desbloquear** o seu **celular** e **aceitar** a conexão.
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Isso indica ao dispositivo que ele deve iniciar um servidor adb na porta 5555:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb tcpip 5555
```
2023-06-06 18:56:34 +00:00
Conecte-se a esse IP e a essa porta:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb connect < IP > :< PORT >
```
2023-06-06 18:56:34 +00:00
Se você receber um erro como o seguinte em um software Android virtual (como o Genymotion):
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb server version (41) doesn't match this client (36); killing...
```
2023-06-06 18:56:34 +00:00
É porque você está tentando se conectar a um servidor ADB com uma versão diferente. Tente encontrar o binário adb que o software está usando (vá para `C:\Program Files\Genymobile\Genymotion` e procure por adb.exe)
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
## Vários dispositivos
2021-07-04 09:43:18 +00:00
2023-06-06 18:56:34 +00:00
Sempre que você encontrar **vários dispositivos conectados à sua máquina** , você precisará **especificar em qual** deseja executar o comando 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
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
root
```
2023-06-06 18:56:34 +00:00
## Tunelamento de Porta
2021-07-04 09:43:18 +00:00
2023-06-06 18:56:34 +00:00
Caso a **porta adb** só seja **acessível** pelo **localhost** no dispositivo android, mas **você tenha acesso via SSH** , você pode **encaminhar a porta 5555** e se conectar 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
```
2023-06-06 18:56:34 +00:00
# Gerenciador de Pacotes
2021-07-04 09:43:18 +00:00
2023-06-06 18:56:34 +00:00
## Instalar/Desinstalar
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
### adb install \[opção] \<caminho>
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install test.apk
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -l test.apk forward lock application
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -r test.apk replace existing application
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -t test.apk allow test packages
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -s test.apk install application on sdcard
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -d test.apk allow version code downgrade
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb install -p test.apk partial application install
```
2023-06-06 18:56:34 +00:00
### adb uninstall \[opções] \<PACOTE>
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb uninstall com.test.app
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb uninstall -k com.test.app Keep the data and cache directories around after package removal.
```
2023-06-06 18:56:34 +00:00
## Pacotes
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Imprime todos os pacotes, opcionalmente apenas aqueles cujo nome do pacote contém o texto em \<FILTER>.
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
### adb shell pm list packages \[opções] \<FILTER-STR>
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages < FILTER-STR >
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -f < FILTER-STR > #See their associated file.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -d < FILTER-STR > #Filter to only show disabled packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -e < FILTER-STR > #Filter to only show enabled packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -s < FILTER-STR > #Filter to only show system packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -3 < FILTER-STR > #Filter to only show third party packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -i < FILTER-STR > #See the installer for the packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages -u < FILTER-STR > #Also include uninstalled packages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm list packages --user < USER_ID > < FILTER-STR > #The user space to query.
```
2022-05-01 12:41:36 +00:00
### adb shell pm path \<PACKAGE>
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Imprime o caminho para o APK do pacote fornecido.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm path com.android.phone
```
2022-05-01 12:41:36 +00:00
### adb shell pm clear \<PACKAGE>
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Apaga todos os dados associados a um pacote.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pm clear com.test.abc
```
2023-06-06 18:56:34 +00:00
# Gerenciador de Arquivos
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
### adb pull \<remoto> \[local]
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Baixa um arquivo especificado de um emulador/dispositivo para o seu computador.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb pull /sdcard/demo.mp4 ./
```
2022-05-01 12:41:36 +00:00
### adb push \<local> \<remote>
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Envia um arquivo especificado do seu computador para um emulador/dispositivo.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb push test.apk /sdcard
```
2023-06-06 18:56:34 +00:00
# Captura de tela/Gravação de tela
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
### adb shell screencap \<filename>
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Capturando uma imagem da tela do dispositivo.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell screencap /sdcard/screen.png
```
2023-06-06 18:56:34 +00:00
### adb shell screenrecord \[opções] \<nome_do_arquivo>
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Gravando a tela de dispositivos executando o Android 4.4 (API nível 19) ou superior.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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
```
2023-06-06 18:56:34 +00:00
(pressione Ctrl-C para parar a gravação)
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
**Você pode baixar os arquivos (imagens e vídeos) usando o comando** _**adb pull**_
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
# Shell
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
### adb shell
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Obtenha um shell dentro do dispositivo.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell
```
2022-05-01 12:41:36 +00:00
### adb shell \<CMD>
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Executa um comando dentro do dispositivo.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell ls
```
2022-05-01 12:41:36 +00:00
## pm
2021-04-22 13:58:44 +00:00
2023-06-06 18:56:34 +00:00
Os seguintes comandos são executados dentro de um shell.
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
```
2023-06-06 18:56:34 +00:00
# Processos
2021-04-22 13:58:44 +00:00
2023-06-06 18:56:34 +00:00
Se você deseja obter o PID do processo do seu aplicativo, pode executar:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell ps
```
2023-06-06 18:56:34 +00:00
E pesquisar pelo seu aplicativo
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Ou você pode fazer
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell pidof com.your.application
```
2023-06-06 18:56:34 +00:00
E isso imprimirá o PID do aplicativo.
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
# System
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb root
```
2023-06-06 18:56:34 +00:00
Reinicia o daemon adbd com permissões de root. Em seguida, você deve se conectar novamente ao servidor ADB e estará como root (se disponível).
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb sideload < update.zip >
```
2023-06-06 18:56:34 +00:00
Atualizando/restaurando pacotes de atualização Android update.zip.
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
# Registros
2020-07-15 15:43:14 +00:00
2022-05-01 12:41:36 +00:00
## Logcat
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Para **filtrar as mensagens de apenas um aplicativo** , obtenha o PID do aplicativo e use grep (linux/macos) ou findstr (windows) para filtrar a saída do logcat:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat | grep 4526
adb logcat | findstr 4526
```
2023-06-06 18:56:34 +00:00
### adb logcat \[opção] \[especificações-de-filtro]
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
O comando `adb logcat` é usado para exibir o registro de eventos do sistema Android. Ele pode ser usado para depurar aplicativos e encontrar erros no sistema. O comando tem várias opções e especificações de filtro que podem ser usadas para personalizar a saída.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat
```
2023-06-06 18:56:34 +00:00
Notas: pressione Ctrl-C para parar o monitor
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:V lowest priority, filter to only show Verbose level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:D filter to only show Debug level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:I filter to only show Info level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:W filter to only show Warning level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:E filter to only show Error level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat *:F filter to only show Fatal level
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +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>
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Este comando exibe o buffer especificado. Os buffers disponíveis são:
- `main` : buffer principal do sistema.
- `radio` : buffer de rádio.
- `events` : buffer de eventos.
- `system` : buffer do sistema.
- `crash` : buffer de falhas.
Por exemplo, para exibir o buffer principal, use o comando:
```
adb logcat -b main
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -b radio View the buffer that contains radio/telephony related messages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -b event View the buffer containing events-related messages.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -b main default
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -c Clears the entire log and exits.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -d Dumps the log to the screen and exits.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -f test.logs Writes log message output to test.logs .
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -g Prints the size of the specified log buffer and exits.
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb logcat -n < count > Sets the maximum number of rotated logs to < count > .
```
2022-05-01 12:41:36 +00:00
## dumpsys
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
dumps dados do sistema
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
### adb shell dumpsys \[opções]
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell dumpsys
```
2023-06-06 18:56:34 +00:00
```
## Comando: adb shell dumpsys meminfo
O comando `adb shell dumpsys meminfo` exibe informações sobre o uso de memória do sistema e dos processos em execução no dispositivo Android. Isso pode ser útil para identificar possíveis vazamentos de memória ou para otimizar o desempenho do aplicativo.
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Para exibir as informações de memória de um processo específico, basta adicionar o nome do pacote do aplicativo ao final do comando. Por exemplo:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2023-06-06 18:56:34 +00:00
adb shell dumpsys meminfo com.exemplo.app
2020-07-15 15:43:14 +00:00
```
2023-06-06 18:56:34 +00:00
Isso exibirá as informações de memória para o aplicativo com o pacote `com.exemplo.app` .
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
É importante lembrar que o comando `adb shell dumpsys meminfo` requer permissões de root no dispositivo para exibir informações detalhadas sobre todos os processos em execução.
```
adb shell dumpsys battery
```
Notas: Um dispositivo móvel com Opções do desenvolvedor habilitadas executando o Android 5.0 ou superior.
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell dumpsys batterystats collects battery data from your device
```
2023-06-06 18:56:34 +00:00
Notas: [Battery Historian ](https://github.com/google/battery-historian ) converte esses dados em uma visualização HTML. **PASSO 1** _adb shell dumpsys batterystats > batterystats.txt_ **PASSO 2** _python historian.py batterystats.txt > batterystats.html_
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
adb shell dumpsys batterystats --reset erases old collection data
```
adb shell dumpsys activity
2022-05-01 12:41:36 +00:00
# Backup
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
Faça backup de um dispositivo Android pelo adb.
2020-07-15 15:43:14 +00:00
```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
2021-02-17 12:02:24 +00:00
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
```
2023-06-06 18:56:34 +00:00
Se você deseja inspecionar o conteúdo do backup:
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 -
2020-07-15 15:43:14 +00:00
```
2022-04-28 16:01:33 +00:00
< details >
2023-04-25 18:35:28 +00:00
< summary > < a href = "https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology" > < strong > ☁️ HackTricks Cloud ☁️< / strong > < / a > -< a href = "https://twitter.com/hacktricks_live" > < strong > 🐦 Twitter 🐦< / strong > < / a > - < a href = "https://www.twitch.tv/hacktricks_live/schedule" > < strong > 🎙️ Twitch 🎙️< / strong > < / a > - < a href = "https://www.youtube.com/@hacktricks_LIVE" > < strong > 🎥 Youtube 🎥< / strong > < / a > < / summary >
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- Você trabalha em uma **empresa de segurança cibernética** ? Você quer ver sua **empresa anunciada no HackTricks** ? ou você quer ter acesso à **última versão do PEASS ou baixar o HackTricks em PDF** ? Confira os [**PLANOS DE ASSINATURA** ](https://github.com/sponsors/carlospolop )!
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- Descubra [**A Família PEASS** ](https://opensea.io/collection/the-peass-family ), nossa coleção exclusiva de [**NFTs** ](https://opensea.io/collection/the-peass-family )
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- Adquira o [**swag oficial do PEASS & HackTricks** ](https://peass.creator-spring.com )
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- **Junte-se ao** [**💬** ](https://emojipedia.org/speech-balloon/ ) [**grupo do Discord** ](https://discord.gg/hRep4RUj7f ) ou ao [**grupo do telegram** ](https://t.me/peass ) ou **siga-me** no **Twitter** [**🐦** ](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md )[**@carlospolopm** ](https://twitter.com/hacktricks_live )**.**
2022-04-28 16:01:33 +00:00
2023-06-06 18:56:34 +00:00
- **Compartilhe seus truques de hacking enviando PRs para o [repositório hacktricks ](https://github.com/carlospolop/hacktricks ) e [repositório hacktricks-cloud ](https://github.com/carlospolop/hacktricks-cloud )**.
2022-04-28 16:01:33 +00:00
< / details >