Android模拟器:如何监控网络流量?

发布于 2024-08-25 06:47:38 字数 35 浏览 10 评论 0 原文

如何监控从 Android 模拟器发送和接收的网络流量?

How do I monitor network traffic sent and received from my android emulator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

一指流沙 2024-09-01 06:47:38

有两种方法可以直接从 Android 模拟器捕获网络流量:

  1. 复制并运行 ARM 兼容的 tcpdump 二进制文件 在模拟器上,将输出写入 SD 卡,也许(例如 tcpdump -s0 -w /sdcard/emulator.cap)。

  2. 运行 emulator -tcpdump emulator.cap -avd my_avd 将所有模拟器的流量写入 PC 上的本地文件

在这两种情况下,您都可以像平常一样使用 tcpdump 或 Wireshark 分析 pcap 文件。

There are two ways to capture network traffic directly from an Android emulator:

  1. 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).

  2. Run emulator -tcpdump emulator.cap -avd my_avd to write all the emulator's traffic to a local file on your PC

In both cases you can then analyse the pcap file with tcpdump or Wireshark as normal.

风柔一江水 2024-09-01 06:47:38

还可以使用 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.

幻梦 2024-09-01 06:47:38

对于 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.

☆獨立☆ 2024-09-01 06:47:38

现在可以直接使用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) and adbd running as root on the host (just run adb root). In the list of the available interfaces in Wireshark (Qt version only, the deprecated GTK+ doesn't have it) or the list shown with tshark -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)

本王不退位尔等都是臣 2024-09-01 06:47:38

是的,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.

牵你手 2024-09-01 06:47:38

虽然 Android Studio 的应用检查的网络检查器菜单有助于跟踪网络请求,但我注意到它并不能跟踪所有请求。这是文档

据我所知,跟踪 Android 模拟器网络请求的最简单方法是 HTTP Toolkit。它的设置速度非常快,并且有一个漂亮的 UI(类似于 Chrome 开发工具的“网络”选项卡)来跟踪请求。

只需安装它,单击“通过 ADB 的 Android 设备”选项,然后接受模拟器中显示的提示即可 (文档)。

HTTP 工具包用户界面

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).

HTTP Toolkit UI

如痴如狂 2024-09-01 06:47:38

当前版本的 Android Studio 未正确应用 -tcpdump 参数。我仍然能够通过将相关参数传递给 qemu 来捕获转储,如下所示:

tools/emulator -engine classic -tcpdump dump.cap -avd myAvd

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:

tools/emulator -engine classic -tcpdump dump.cap -avd myAvd
甩你一脸翔 2024-09-01 06:47:38

我建议您使用 Wireshark

步骤:

  1. 安装 Wireshark。
  2. 选择您用于通话的网络连接(例如,如果您正在使用 Wifi,请选择它)
  3. 将会有很多请求和响应,请关闭多余的应用程序。
  4. 通常请求为绿色,一旦您发现请求,请复制目标地址并使用顶部的过滤器
    通过输入目标地址输入 ip.dst==52.187.182.185

您可以利用此处提到的其他过滤技术来获取特定流量。

I would suggest you use Wireshark.

Steps:

  1. Install Wireshark.
  2. Select the network connection that you are using for the calls(for eg, select the Wifi if you are using it)
  3. There will be many requests and responses, close extra applications.
  4. Usually the requests are in green color, once you spot your request, copy the destination address and use the filter on top by
    typing ip.dst==52.187.182.185 by putting the destination address.

You can make use of other filtering techniques mentioned here to get specific traffic.

醉生梦死 2024-09-01 06:47:38

您可以从 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

溺渁∝ 2024-09-01 06:47:38

您可以使用命令 -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

傲世九天 2024-09-01 06:47:38

您可以使用
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.

天冷不及心凉 2024-09-01 06:47:38

我认为通过 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.

迟到的我 2024-09-01 06:47:38

Requestly 现在支持一键连接到 Android 模拟器,不仅可以让您查看网络请求,还可以修改它们如果需要的话。

步骤

  1. 此处下载Requestly桌面应用程序。
  2. 启动您的 Android 模拟器。
  3. 转到移动应用程序和浏览器选项卡。
  4. 单击要连接的模拟器的“连接”按钮。

请求 Android模拟器调试器

您可能需要信任 CA 证书

就是这样。现在您可以查看所有网络请求并根据需要进行修改。以下是相同的文档

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

  1. Download Requestly Desktop App from here.
  2. Start your Android Emulator.
  3. Go to Mobile Apps & Browsers tab.
  4. Click on Connect button of emulator you want to connect to.

Requestly Android Emulator Debugger

You might need to trust CA certificate if SSL pinning is enabled for your app.

That's it. Now you can see all your network requests and modify them if needed. Here are the docs for same

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文