Android模拟器:如何监控网络流量?
如何监控从 Android 模拟器发送和接收的网络流量?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何监控从 Android 模拟器发送和接收的网络流量?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(14)
有两种方法可以直接从 Android 模拟器捕获网络流量:
复制并运行 ARM 兼容的 tcpdump 二进制文件 在模拟器上,将输出写入 SD 卡,也许(例如
tcpdump -s0 -w /sdcard/emulator.cap)。
运行
emulator -tcpdump emulator.cap -avd my_avd
将所有模拟器的流量写入 PC 上的本地文件在这两种情况下,您都可以像平常一样使用 tcpdump 或 Wireshark 分析 pcap 文件。
There are two ways to capture network traffic directly from an Android emulator:
Copy and run an ARM-compatible tcpdump binary on the emulator, writing output to the SD card, perhaps (e.g.
tcpdump -s0 -w /sdcard/emulator.cap
).Run
emulator -tcpdump emulator.cap -avd my_avd
to write all the emulator's traffic to a local file on your PCIn both cases you can then analyse the pcap file with tcpdump or Wireshark as normal.
还可以使用 http 代理来监视来自模拟器的 http 请求。您可以在启动新模拟器时传递
-http-proxy
标志来设置代理(示例 burp) 来监控 Android 流量。使用示例./emulator -http-proxy localhost:8080 -avd android2.2
。请注意,在我的示例中,我使用的是 Burp,它正在侦听端口 8080。更多信息可以找到 此处。It is also possible to use http proxy to monitor http requests from emulator. You can pass
-http-proxy
flag when starting a new emulator to set proxy (Example burp) to monitor Android traffic. Example usage./emulator -http-proxy localhost:8080 -avd android2.2
. Note that in my example I'm using Burp, and it is listening port 8080. More info can be found here.对于 OS X,您可以使用 Charles,它简单易用。
有关更多信息,请查看 Android 模拟器和 Charles Proxy 博客文章。
For OS X you can use Charles, it's simple and easy to use.
For more information, please have a look at Android Emulator and Charles Proxy blog post.
现在可以直接使用Wireshark来捕获Android模拟器流量。有一个名为 extcap 插件>androiddump 这使得它成为可能。您需要在模拟器上运行的系统映像中具有
tcpdump
可执行文件(大多数当前映像都具有该可执行文件,并使用 API 24 和 API 27 映像进行测试),并以 root 身份运行adbd
在主机上(只需运行adb root
)。在 Wireshark 中的可用接口列表(仅限 Qt 版本,已弃用的 GTK+ 没有)或使用 tshark -D 显示的列表中,应该有几个允许嗅探蓝牙、Logcat 的 Android 接口,或 Wifi 流量,例如:android-wifi-tcpdump-emulator-5554 (Android WiFi Android_SDK_built_for_x86 emulator-5554)
It is now possible to use Wireshark directly to capture Android emulator traffic. There is an extcap plugin called androiddump which makes it possible. You need to have a
tcpdump
executable in the system image running on the emulator (most current images have it, tested with API 24 and API 27 images) andadbd
running as root on the host (just runadb root
). In the list of the available interfaces in Wireshark (Qt version only, the deprecated GTK+ doesn't have it) or the list shown withtshark -D
there should be several Android interfaces allowing to sniff Bluetooth, Logcat, or Wifi traffic, e.g.:android-wifi-tcpdump-emulator-5554 (Android WiFi Android_SDK_built_for_x86 emulator-5554)
是的,wireshark 可以工作。
我认为没有任何简单的方法可以过滤掉单独的模拟器流量,因为它来自相同的源 IP。
也许最好的方法是建立一个非常裸露的VMware环境并只在其中运行模拟器,至少这样不会有太多的后台流量。
Yes, wireshark will work.
I don't think there is any easy way to filter out solely emulator traffic, since it is coming from the same src IP.
Perhaps the best way would be to set up a very bare VMware environment and only run the emulator in there, at least that way there wouldn't be too much background traffic.
虽然 Android Studio 的应用检查的网络检查器菜单有助于跟踪网络请求,但我注意到它并不能跟踪所有请求。这是文档。
据我所知,跟踪 Android 模拟器网络请求的最简单方法是 HTTP Toolkit。它的设置速度非常快,并且有一个漂亮的 UI(类似于 Chrome 开发工具的“网络”选项卡)来跟踪请求。
只需安装它,单击“通过 ADB 的 Android 设备”选项,然后接受模拟器中显示的提示即可 (文档)。
While Android Studio's App Inspection's Network Inspector menu is helpful for tracking network requests, I've noticed that it doesn't track all requests. Here's the documentation.
The easiest way to track network requests for the android emulator that I know and use is HTTP Toolkit. It really quick to set up, and has a nice UI (similar to Chrome Dev Tools' Networks tab) for tracking the requests.
Just install it, click on the "Android device via ADB" option, and accept the prompts shown in the emulator (docs).
当前版本的 Android Studio 未正确应用
-tcpdump
参数。我仍然能够通过将相关参数传递给 qemu 来捕获转储,如下所示:A current release of Android Studio did not correctly apply the
-tcpdump
argument. I was still able to capture a dump by passing the related parameter to qemu as follows:我建议您使用 Wireshark。
您可以利用此处提到的其他过滤技术来获取特定流量。
I would suggest you use Wireshark.
You can make use of other filtering techniques mentioned here to get specific traffic.
您可以使用 Fiddler 监控 http 流量:
http://auir.wordpress.com/2010/03/22/tutorial- getting-android-emulator-working-with-fiddler-http-proxy-tool/
您还可以使用 Fiddler2 此处。
You can use Fiddler to monitor http traffic:
http://aurir.wordpress.com/2010/03/22/tutorial-getting-android-emulator-working-with-fiddler-http-proxy-tool/
You can also use Fiddler2 here.
您可以从 Android Studio 监控网络流量。
转到 Android 监视器并打开网络选项卡。
http://developer.android.com/tools/debugging/ddms.html
更新: ⚠️ Android Device Monitor 在 Android Studio 3.1 中已弃用。在 https://developer.android.com/studio/profile/monitor 中查看更多信息
You can monitor network traffic from Android Studio.
Go to Android Monitor and open Network tab.
http://developer.android.com/tools/debugging/ddms.html
UPDATE: ⚠️ Android Device Monitor was deprecated in Android Studio 3.1. See more in https://developer.android.com/studio/profile/monitor
您可以使用命令
-avd Adfmf -http-proxy http://SYSTEM_IP:PORT
启动模拟器。我使用了 HTTP 分析器,但它应该适用于其他任何东西。更多详细信息可以在这里找到:
http://stick2code.blogspot.in/2014 /04/intercept-http-requests-sent-from-app.html
You can start the emulator with the command
-avd Adfmf -http-proxy http://SYSTEM_IP:PORT
.I used HTTP Analyzer, but it should work for anything else. More details can be found here:
http://stick2code.blogspot.in/2014/04/intercept-http-requests-sent-from-app.html
您可以使用
http://docs.mitmproxy.org/en/stable/install.html
它易于设置,不需要任何额外的调整。
我使用了各种工具,但发现它非常好用且简单。
You can use
http://docs.mitmproxy.org/en/stable/install.html
Its easy to setup and won't require any extra tweaks.
I go through various tool but found it to be really good and easy.
我认为通过 HTTP 代理运行流量是最好的解决方案。
我在尝试将 MITM HTTP 代理连接到 Android 模拟器时遇到的主要问题之一是检查 SSL 流量。
在模拟设备上安装根证书比我想象的要复杂。
我的一位同事创建了一份关于捕获 SSL 流量的更新分步指南模拟的 Android 设备。
I think running the traffic through an HTTP proxy is the best solution.
One of the main problems I encountered when trying to connect a MITM HTTP proxy to an Android emulator was inspecting SSL traffic.
Installing a root certificate on an emulated device was more trick than I expected.
One of my colleagues created an updated step-by-step guide on capturing SSL traffic on an emulated Android device.
Requestly 现在支持一键连接到 Android 模拟器,不仅可以让您查看网络请求,还可以修改它们如果需要的话。
步骤
就是这样。现在您可以查看所有网络请求并根据需要进行修改。以下是相同的文档
Requestly now has one click support to connect to Android Emulators which can not only let you view your network requests but also can modify them if needed.
Steps
That's it. Now you can see all your network requests and modify them if needed. Here are the docs for same