2024-07-19 04:39:11 +00:00
{% hint style="success" %}
Aprende y practica Hacking en 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" > \
Aprende y practica Hacking en 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)
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
< details >
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
< summary > Apoya a HackTricks< / summary >
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
* Revisa los [**planes de suscripción** ](https://github.com/sponsors/carlospolop )!
* **Únete al** 💬 [**grupo de Discord** ](https://discord.gg/hRep4RUj7f ) o al [**grupo de telegram** ](https://t.me/peass ) o **síguenos** en **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **Comparte trucos de hacking enviando PRs a los** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) y [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) repositorios de github.
2023-06-05 18:33:24 +00:00
2024-01-06 23:35:21 +00:00
< / details >
2024-07-19 04:39:11 +00:00
{% endhint %}
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
**Adb generalmente se encuentra en:**
2024-01-06 23:35:21 +00:00
```bash
#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe
2023-06-05 18:33:24 +00:00
2024-01-06 23:35:21 +00:00
#MacOS
/Users/< username > /Library/Android/sdk/platform-tools/adb
```
**Información obtenida de:** [**http://adbshell.com/** ](http://adbshell.com )
2023-06-05 18:33:24 +00:00
2024-01-06 23:35:21 +00:00
# Conexión
2023-06-05 18:33:24 +00:00
```
adb devices
```
2024-07-19 04:39:11 +00:00
Esto enumerará los dispositivos conectados; si aparece "_**no autorizado**_", esto significa que debes **desbloquear** tu **móvil** y **aceptar** la conexión.
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
Esto indica al dispositivo que debe iniciar un servidor adb en el puerto 5555:
2023-06-05 18:33:24 +00:00
```
adb tcpip 5555
```
2024-07-19 04:39:11 +00:00
Conéctate a esa IP y ese Puerto:
2023-06-05 18:33:24 +00:00
```
adb connect < IP > :< PORT >
```
2024-07-19 04:39:11 +00:00
Si obtienes un error como el siguiente en un software de Android Virtual (como Genymotion):
2023-06-05 18:33:24 +00:00
```
adb server version (41) doesn't match this client (36); killing...
```
2024-07-19 04:39:11 +00:00
Es porque estás intentando conectarte a un servidor ADB con una versión diferente. Solo intenta encontrar el binario adb que el software está utilizando (ve a `C:\Program Files\Genymobile\Genymotion` y busca adb.exe)
2024-02-08 03:51:52 +00:00
2023-06-05 18:33:24 +00:00
## Varios dispositivos
2024-07-19 04:39:11 +00:00
Siempre que encuentres **varios dispositivos conectados a tu máquina** necesitarás **especificar en cuál** deseas ejecutar el comando adb.
2023-06-05 18:33:24 +00:00
```bash
adb devices
List of devices attached
10.10.10.247:42135 offline
127.0.0.1:5555 device
```
```bash
2024-01-06 23:35:21 +00:00
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
2023-06-05 18:33:24 +00:00
root
```
2024-07-19 04:39:11 +00:00
## Port Tunneling
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
En caso de que el **puerto** **adb** solo sea **accesible** desde **localhost** en el dispositivo android pero **tienes acceso a través de SSH** , puedes **redirigir el puerto 5555** y conectarte a través de adb:
2023-06-05 18:33:24 +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-07-19 04:39:11 +00:00
# Administrador de Paquetes
2023-06-05 18:33:24 +00:00
## Instalar/Desinstalar
### adb install \[opción] \<ruta>
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb install test.apk
2024-02-08 03:51:52 +00:00
adb install -l test.apk # forward lock application
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb install -r test.apk # replace existing application
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb install -t test.apk # allow test packages
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb install -s test.apk # install application on sdcard
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb install -d test.apk # allow version code downgrade
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb install -p test.apk # partial application install
2023-06-05 18:33:24 +00:00
```
2024-07-19 04:39:11 +00:00
### adb uninstall \[options] \<PACKAGE>
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb uninstall com.test.app
adb uninstall -k com.test.app Keep the data and cache directories around after package removal.
```
## Paquetes
2024-07-19 04:39:11 +00:00
Imprime todos los paquetes, opcionalmente solo aquellos cuyo nombre de paquete contiene el texto en \<FILTER>.
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
### adb shell pm list packages \[options] \<FILTER-STR>
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
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.
```
2024-01-06 23:35:21 +00:00
### adb shell pm path \<PACKAGE>
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
Imprime la ruta al APK del dado.
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell pm path com.android.phone
```
2024-07-19 04:39:11 +00:00
### adb shell pm clear \<PACKAGE>
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
Elimina todos los datos asociados con un paquete.
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell pm clear com.test.abc
```
2024-07-19 04:39:11 +00:00
# File Manager
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
### adb pull \<remoto> \[local]
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
Descarga un archivo especificado de un emulador/dispositivo a tu computadora.
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb pull /sdcard/demo.mp4 ./
```
### adb push \<local> \<remote>
Sube un archivo especificado desde tu computadora a un emulador/dispositivo.
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb push test.apk /sdcard
```
# Captura de pantalla/Grabación de pantalla
2024-07-19 04:39:11 +00:00
### adb shell screencap \<filename>
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
Tomando una captura de pantalla de la pantalla del dispositivo.
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell screencap /sdcard/screen.png
```
2024-07-19 04:39:11 +00:00
### adb shell screenrecord \[options] \<filename>
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
Grabando la pantalla de dispositivos que ejecutan Android 4.4 (nivel de API 19) y superior.
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +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
```
2024-07-19 04:39:11 +00:00
(press Ctrl-C to stop recording)
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
**Puedes descargar los archivos (imágenes y videos) usando **_**adb pull**_
2023-06-05 18:33:24 +00:00
# Shell
### adb shell
2024-07-19 04:39:11 +00:00
Obtén un shell dentro del dispositivo
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell
```
### adb shell \<CMD>
2024-01-06 23:35:21 +00:00
Ejecuta un comando dentro del dispositivo
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell ls
```
## pm
2024-07-19 04:39:11 +00:00
Los siguientes comandos se ejecutan dentro de un shell
2023-06-05 18:33:24 +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-07-19 04:39:11 +00:00
# Processes
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
Si deseas obtener el PID del proceso de tu aplicación, puedes ejecutar:
```bash
2023-06-05 18:33:24 +00:00
adb shell ps
```
2024-02-09 01:28:22 +00:00
Y busca tu aplicación
2023-06-05 18:33:24 +00:00
O puedes hacer
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell pidof com.your.application
```
2024-07-19 04:39:11 +00:00
Y imprimirá el PID de la aplicación
2024-01-06 23:35:21 +00:00
# Sistema
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb root
```
2024-07-19 04:39:11 +00:00
Reinicia el demonio adbd con permisos de root. Luego, debes conectarte nuevamente al servidor ADB y serás root (si está disponible).
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb sideload < update.zip >
```
2024-07-19 04:39:11 +00:00
flashear/restaurar paquetes de actualización Android update.zip.
# Registros
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
## Logcat
2023-06-05 18:33:24 +00:00
2024-01-06 23:35:21 +00:00
Para **filtrar los mensajes de solo una aplicación** , obtén el PID de la aplicación y usa grep (linux/macos) o findstr (windows) para filtrar la salida de logcat:
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb logcat | grep 4526
adb logcat | findstr 4526
```
2024-02-08 03:51:52 +00:00
### adb logcat \[opción] \[especificaciones-de-filtro]
```bash
2023-06-05 18:33:24 +00:00
adb logcat
```
Notas: presiona Ctrl-C para detener el monitor
2024-02-08 03:51:52 +00:00
```bash
adb logcat *:V # lowest priority, filter to only show Verbose level
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat *:D # filter to only show Debug level
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat *:I # filter to only show Info level
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat *:W # filter to only show Warning level
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat *:E # filter to only show Error level
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat *:F # filter to only show Fatal level
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat *:S # Silent, highest priority, on which nothing is ever printed
2023-06-05 18:33:24 +00:00
```
### adb logcat -b \<Buffer>
2024-02-08 03:51:52 +00:00
```bash
adb logcat -b # radio View the buffer that contains radio/telephony related messages.
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat -b # event View the buffer containing events-related messages.
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat -b # main default
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat -c # Clears the entire log and exits.
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat -d # Dumps the log to the screen and exits.
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat -f test.logs # Writes log message output to test.logs .
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat -g # Prints the size of the specified log buffer and exits.
2023-06-05 18:33:24 +00:00
2024-02-08 03:51:52 +00:00
adb logcat -n < count > # Sets the maximum number of rotated logs to < count > .
2023-06-05 18:33:24 +00:00
```
## dumpsys
2024-07-19 04:39:11 +00:00
dumps datos del sistema
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
### adb shell dumpsys \[options]
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell dumpsys
2024-02-08 03:51:52 +00:00
2024-01-06 23:35:21 +00:00
adb shell dumpsys meminfo
2024-02-08 03:51:52 +00:00
2023-06-05 18:33:24 +00:00
adb shell dumpsys battery
```
2024-02-09 01:28:22 +00:00
Notas: Un dispositivo móvil con las Opciones de Desarrollador habilitadas que ejecute Android 5.0 o superior.
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell dumpsys batterystats collects battery data from your device
```
Notas: [Battery Historian ](https://github.com/google/battery-historian ) convierte esos datos en una visualización HTML. **PASO 1** _adb shell dumpsys batterystats > batterystats.txt_ **PASO 2** _python historian.py batterystats.txt > batterystats.html_
2024-02-08 03:51:52 +00:00
```bash
2023-06-05 18:33:24 +00:00
adb shell dumpsys batterystats --reset erases old collection data
```
adb shell dumpsys activity
2024-07-19 04:39:11 +00:00
# Respaldo
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
Respalda un dispositivo android desde adb.
2023-06-05 18:33:24 +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
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
```
2024-02-08 03:51:52 +00:00
Si deseas inspeccionar el contenido de la copia de seguridad:
2023-06-05 18:33:24 +00:00
```bash
( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) | tar xfvz -
```
2024-07-19 04:39:11 +00:00
{% hint style="success" %}
Aprende y practica Hacking en 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" > \
Aprende y practica Hacking en 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)
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
< details >
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
< summary > Apoya a HackTricks< / summary >
2023-06-05 18:33:24 +00:00
2024-07-19 04:39:11 +00:00
* Revisa los [**planes de suscripción** ](https://github.com/sponsors/carlospolop )!
* **Únete al** 💬 [**grupo de Discord** ](https://discord.gg/hRep4RUj7f ) o al [**grupo de telegram** ](https://t.me/peass ) o **síguenos** en **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **Comparte trucos de hacking enviando PRs a los** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) y [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) repositorios de github.
2023-06-05 18:33:24 +00:00
< / details >
2024-07-19 04:39:11 +00:00
{% endhint %}