跳过内容

MASTG-TECH-0002: 主机-设备数据传输

使用 adb

您可以使用 adb 命令 adb pull <remote> <local>adb push <local> <remote> 命令来复制设备中的文件。 它们的使用非常简单。 例如,以下命令将 `foo.txt` 从当前目录(本地)复制到 `sdcard` 文件夹(远程)

adb push foo.txt /sdcard/foo.txt

当您确切知道要复制什么,从哪里复制到哪里时,通常使用此方法,并且它还支持批量文件传输,例如,您可以从 Android 设备将整个目录提取(复制)到您的主机。

$ adb pull /sdcard
/sdcard/: 1190 files pulled. 14.1 MB/s (304526427 bytes in 20.566s)

使用 Android Studio Device File Explorer

Android Studio 有一个内置的设备文件浏览器,您可以通过 View -> Tool Windows -> Device File Explorer 打开它。

如果您使用的是已 root 的设备,您现在可以开始浏览整个文件系统。 但是,当使用未 root 的设备时,除非应用是可调试的,否则访问应用沙箱将不起作用,即使这样,您也只能在应用沙箱内“活动”。

使用 objection

当您正在处理特定的应用程序并且想要复制您可能在其沙箱中遇到的文件时,此选项非常有用(请注意,您只能访问目标应用程序可以访问的文件)。 这种方法有效,无需将应用程序设置为可调试,否则在使用 Android Studio 的设备文件浏览器时需要这样做。

首先,按照 objection 中的说明,使用 Objection 连接到应用程序。 然后,像在终端上一样使用 `ls` 和 `cd` 来浏览可用的文件

$ frida-ps -U | grep -i owasp
21228  sg.vp.owasp_mobile.omtg_android

$ objection -g sg.vp.owasp_mobile.omtg_android explore

...g.vp.owasp_mobile.omtg_android on (google: 8.1.0) [usb] # cd ..
/data/user/0/sg.vp.owasp_mobile.omtg_android

...g.vp.owasp_mobile.omtg_android on (google: 8.1.0)  [usb] # ls
Type       ...  Name
---------  ...  -------------------
Directory  ...  cache
Directory  ...  code_cache
Directory  ...  lib
Directory  ...  shared_prefs
Directory  ...  files
Directory  ...  app_ACRA-approved
Directory  ...  app_ACRA-unapproved
Directory  ...  databases

Readable: True  Writable: True

一旦您有了想要下载的文件,您只需运行 `file download <some_file>`。 这会将该文件下载到您的工作目录。 同样,您可以使用 `file upload` 上传文件。

...[usb] # ls
Type    ...  Name
------  ...  -----------------------------------------------
File    ...  sg.vp.owasp_mobile.omtg_android_preferences.xml

Readable: True  Writable: True
...[usb] # file download sg.vp.owasp_mobile.omtg_android_preferences.xml
Downloading ...
Streaming file from device...
Writing bytes to destination...
Successfully downloaded ... to sg.vp.owasp_mobile.omtg_android_preferences.xml

缺点是,在撰写本文时,objection 尚不支持批量文件传输,因此您只能复制单个文件。 尽管如此,这在某些情况下仍然很方便,在某些情况下,您无论如何都在使用 objection 探索应用程序,并且找到了一些有趣的文件。 例如,您可以不用记下该文件的完整路径,并从单独的终端使用 `adb pull <path_to_some_file>`,而是可以直接执行 `file download <some_file>`。