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

9.9 KiB
Raw Blame History

{% hint style="success" %} 学习与实践 AWS 黑客技术:HackTricks 培训 AWS 红队专家 (ARTE)
学习与实践 GCP 黑客技术:HackTricks 培训 GCP 红队专家 (GRTE)

支持 HackTricks
{% endhint %}

Adb 通常位于:

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

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

信息来源: http://adbshell.com/

连接

adb devices

这将列出连接的设备;如果出现“未授权”,这意味着您必须解锁您的手机接受连接。

这向设备指示它必须在端口 5555 启动 adb 服务器:

adb tcpip 5555

连接到该IP和该端口

adb connect <IP>:<PORT>

如果您在虚拟 Android 软件(如 Genymotion中遇到以下错误

adb server version (41) doesn't match this client (36); killing...

因为您尝试连接到不同版本的 ADB 服务器。只需尝试找到软件正在使用的 adb 二进制文件(转到 C:\Program Files\Genymobile\Genymotion 并搜索 adb.exe

多个设备

每当您发现 多个设备连接到您的机器 时,您需要 指定要在哪个设备上 运行 adb 命令。

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

如果 adb 端口 仅在安卓设备的 localhost可访问,但 您可以通过 SSH 访问,您可以 转发端口 5555 并通过 adb 连接:

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

包管理器

安装/卸载

adb install [option] <path>

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 [options] <PACKAGE>

adb uninstall com.test.app

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

Packages

打印所有包,选项上只打印那些包名包含<FILTER>文本的包。

adb shell pm list packages [options] <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>

打印给定 APK 的路径。

adb shell pm path com.android.phone

adb shell pm clear <PACKAGE>

删除与包相关的所有数据。

adb shell pm clear com.test.abc

文件管理器

adb pull <remote> [local]

从模拟器/设备下载指定文件到你的计算机。

adb pull /sdcard/demo.mp4 ./

adb push <local> <remote>

将指定文件从计算机上传到模拟器/设备。

adb push test.apk /sdcard

Screencapture/Screenrecord

adb shell screencap <filename>

对设备显示屏进行截图。

adb shell screencap /sdcard/screen.png

adb shell screenrecord [options] <filename>

录制运行 Android 4.4API 级别 19及更高版本的设备的显示。

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

(按 Ctrl-C 停止录制)

**您可以使用 adb pull 下载文件(图像和视频)

Shell

adb shell

获取设备内部的 shell

adb shell

adb shell <CMD>

在设备内执行命令

adb shell ls

pm

以下命令在 shell 内部执行

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

Processes

如果您想获取应用程序进程的PID可以执行

adb shell ps

并搜索您的应用程序

或者您可以这样做

adb shell pidof com.your.application

它将打印应用程序的PID

系统

adb root

重启具有root权限的adbd守护进程。然后您必须再次连接到ADB服务器您将成为root如果可用

adb sideload <update.zip>

flashing/restoring Android update.zip packages.

Logs

Logcat

仅过滤一个应用程序的消息获取该应用程序的PID并使用greplinux/macos或findstrwindows来过滤logcat的输出

adb logcat | grep 4526
adb logcat | findstr 4526

adb logcat [option] [filter-specs]

adb logcat

Notes: 按 Ctrl-C 停止监视

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>

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

转储系统数据

adb shell dumpsys [options]

adb shell dumpsys

adb shell dumpsys meminfo

adb shell dumpsys battery

Notes: 一台启用了开发者选项的移动设备运行Android 5.0或更高版本。

adb shell dumpsys batterystats collects battery data from your device

注意:Battery Historian 将这些数据转换为 HTML 可视化。 步骤 1 adb shell dumpsys batterystats > batterystats.txt 步骤 2 python historian.py batterystats.txt > batterystats.html

adb shell dumpsys batterystats --reset erases old collection data
adb shell dumpsys activity

# 备份

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

如果您想检查备份的内容:

( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) |  tar xfvz -

{% hint style="success" %} 学习与实践 AWS 黑客技术:HackTricks 培训 AWS 红队专家 (ARTE)
学习与实践 GCP 黑客技术:HackTricks 培训 GCP 红队专家 (GRTE)

支持 HackTricks
{% endhint %}