Android emulator: How to monitor network traffic? - android

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

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 PC
In both cases you can then analyse the pcap file with tcpdump or Wireshark as normal.

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.

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.

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.

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)

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

I would suggest you use Wireshark.
Steps:
Install Wireshark.
Select the network connection that you are using for the calls(for eg, select the Wifi if you are using it)
There will be many requests and responses, close extra applications.
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.

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.

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

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

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.

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

Related

Is there a way to fake the ADB device, or modify adb.exe/build tools?

I am doing some investigation of a closed-source app using ADB. I would like to log the commands this app is making, the ADB binaries it uses are in the same directory. Would I be able to sniff the commands by faking an ADB device or maybe modding the source code of the build tools to include a log?
Best regards.
I tried using some apps on a physical android device to log the incoming packets, though I got nowhere. I expect to be able to know what this closed source app is doing on my device.
PS: I am sorry if this sounds dumb, I know ADB is open source, part of the Android Open Source Project, but I made this post to make sure I am not missing some small detail. I am not an expert in the ADB protocol so excuse my clumsiness.
Answer:
Copied from this answer to How to fetch ADB shell traffic?
It is as simple as listening on the ADB server's port through Wireshark (TCP port 5037) since all the commands pass through the adb server/daemon before going to USB.
It is also possible to sniff the USB traffic using USBPcap, as it also is unencrypted.

Simulate poor network connection on android [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I would like to test my application for cases of low network connectivity. Except standing in the elevator, what is the best way to do this? I've tried wrapping my phone in an aluminum foil, but it didn't help much.
I need to test it on a real device, not in an emulator.
This may sound a little crazy, but a microwave oven serves as a microwave shield. Therefore, putting your device inside a microwave oven (DO NOT turn on the microwave oven while your device is inside!) will cause your signal strength to drop significantly. It definitely beats standing inside an elevator...
You can use emulator for this. Take a look at this page: Android Emulator. Pay attention to next two arguments:
-netdelay <delay>
Set network latency emulation to . Default value is none. See
the table in Network Delay Emulation for supported values.
-netspeed <speed>
Set network speed emulation to . Default value is full. See
the table in Network Speed Emulation for supported values.
Speeds for reference in increasing kbps:
UP DOWN
-------- ----------
gsm GSM/CSD 14.4 14.4
hscsd HSCSD 14.4 57.6
gprs GPRS 28.8 57.6
umts UMTS/3G 384.0 384.0
edge EDGE/EGPRS 473.6 473.6
hsdpa HSDPA 5760.0 13,980.0
lte LTE 58,000.0 173,000.0
evdo EVDO 75,000.0 280,000.0
full No limit ∞ ∞
Since iPhones developer option apply on wifi tethering, you can get an iPhone which has iOS 6 and above (and has been set to use for developments with the xcode), set it to emulate the desired network profile, connect your Android device to its hotspot
Update for Android Studio v 1.5 or greater
As #LouMorda mentioned in a comment below that the Emulator tab mentioned in original post has been removed in Android Studio v 1.5.
Now They've placed these settings in Simulator Settings in AVD Manager.
To access these settings:
Select Tools -> Android -> AVD Manager
Click the Edit AVD button (pencil icon)
The Network Settings can be accessed after clicking the Show Advanced Settings button
Here is a screenshot of how it may appear:
Original Post
For anyone using Android Studio IDE:
Go to Run -> Edit Configurations
Select Android Application -> [Your App]
Select Emulator tab
Here you can change different values for Network Speed(internet speed) and Network Latency (delay) to simulate different speeds and latencies etc
Alternatively, you can enter various arguments in Additional command line options text field as mentioned in #inazaruk's answer.
The screenshot below describes how this Run Configuration screen looks like:
I know its a bit late to answer to this question, but i hope this helps others facing similar issues!
Edit
For anyone using eclipse, see #Abhi's answer below.
I know it's an old question but...
Some phones nowadays have a setting to utilize 2G only. It's perfect for simulating slow internet on a real device.
Years old but hey, I'll chime in with my foolproof method with Genymotion.
Download the Charles free trial: http://www.charlesproxy.com/download/
Install it
ClickProxy -> Throttle Settings
Set up your HTTP throttled speeds
Close that window
Click Proxy -> Throttling to enable the throttle
Open up a Genymotion emulator
Open the wifi settings
Long press the enabled wifi connection
Click Modify Network
Click Show Advanced Options
Set Proxy to Manual
Set the Proxy hostname to 10.0.3.2
Set the Port to 8888
Click Save
And now your network will be throttled!
I have one strategy to settle your problem. You can use the application of proxy to modify or monitor your net status. e.g, Charles.
You ought to change the default config of the Charles like the following picture I posted.
And finally, you will discover the net status has been shaped into lower pace.
You are also able to test slow internet connectivity on an real android device:
Tested with Samsung Galaxy S8 + Android 8.0.0
Go to Settings -> Connection -> Mobile Network -> and under networkmode you can choose to only use 2G or 3G connections
In Android Studio, while running an emulator:
1- Hit settings button at the bottom of the emulator sidebar
2- Go to Cellular
3- Set Network Type
Easy way to test your application with low/bad connection in emulator:
Go Run > Run configurations, select your Android Application, and there go to Target tab.
Look Emulator launch parameters. Here, you can easy modify Network Speed and Network Latency.
There's a simple way of testing low speeds on a real device that seems to have been overlooked. It does require a Mac and an ethernet (or other wired) network connection.
Turn on Wifi sharing on the Mac, turning your computer into a Wifi hotspot, connect your device to this. Use Netlimiter/Charles Proxy or Network Link Conditioner (which you may have already installed) to control the speeds.
For more details and to understand what sort of speeds you should test on check out: http://opensignal.com/blog/2016/02/05/go-slow-how-why-to-test-apps-on-poor-connections/
I'm surprised nobody mentioned this. You can tether via Bluetooth, and separate them by ten+ meters(or less with obstacles). You've got a real bad connection. No microwave, no elevator, no software needed.
Or on an actual device you can go to Settings -> Mobile Networks -> Preferred network types and chose the slowest available...
Of course this is very limited, but for some test- purposes it might be enough.
Facebook built something called Augmented Traffic Control. A brief summary from their GitHub page:
Augmented Traffic Control (ATC) is a tool to simulate network conditions. It allows controlling the connection that a device has to the internet. Developers can use ATC to test their application across varying network conditions, easily emulating high speed, mobile, and even severely impaired networks. Aspects of the connection that can be controlled include:
bandwidth
latency
packet loss
corrupted packets
packets ordering
In order to be able to shape the network traffic, ATC must be running on a device that routes the traffic and sees the real IP address of the device, like your network gateway for instance. This also allows any devices that route through ATC to be able to shape their traffic. Traffic can be shaped/unshaped using a web interface allowing any devices with a web browser to use ATC without the need for a client application.
You can find it here on GitHub: https://github.com/facebook/augmented-traffic-control
They have also written a blog post about it: https://code.facebook.com/posts/1561127100804165/augmented-traffic-control-a-tool-to-simulate-network-conditions/
UPDATE on the Android studio AVD:
open AVD manager
create/edit AVD
click advanced settings
select your preferred connectivity setting
No microwaves or elevators :)
for and mac OS user you can use Network Link Conditioner which could be downloaded from apple. set it as a AP on mac and any divices could connected it.
you can either use facebook open source tools ATC
http://facebook.github.io/augmented-traffic-control/
Go Run > Run configurations, select your Android Application, and there go to Target tab. Do changes as shown in the figure.
I was struggling with this problem for half a day, finally I came to this solution:
Testing on a real device doesn't make much sense overall as you have to go through a lot to make it work. The only logical way to achieve real testing is to make your phone connect to a low quality cellular network, like EDGE, if your phone company provides it. You can try to do this by dialing *#*#4636#*#* in the phone app
The original Android emulator is way too slow for testing and doesn't achieve more than the solution above.
The best way to do this is using Genymotion. It's an Android emulator with much better performance than the original AVDs and the version for personal use is free.
After you created your virtual device in Genymotion, just go through this tutorial to set a proxy for the device.
Run a proxy server on your host machine that simulates bad network conditions, like Crapify or Toxiproxy (I only tested the former) and you're good to go.
Update:
I just realized you can pick the very same strategy with real devices too. I feel like an idiot for not realizing it sooner. Just start a Crapify proxy on your computer, set your phone proxy to your computer's local address and voila, you've got crappy internet on your phone.
Do you want to test for no network connection, or just a slow network connection? If the former, you can go to Settings > Wireless & networks > Airplane mode and turn Airplane mode on. That will let you test network unavailability on an actual device.
as suggested by #VicVu Charles (or any other proxy tool) is an easier way to go. But I would Like to add that you can do this with your device also, not just genymotion or other emulators. Process will be the same:
Modify your device/emulator's wifi setting to use manual proxy. And then Set the Proxy hostname & port
a. set the hostname as ip of your system (get the ip of your pc/mac using ifconfig/ifconfig)
b. set the port number of genymotion (check the proxy settings in charles)
PS: Your device/emulator MUST be using the same wifi since the ip you are using will most probably be the private ip.
Open terminal inAndroid Studio and Go to ../../Android/sdk/tools. 'emulator' executable should be available here.
Run ./emulator -netdelay "delay_in_millis" -avd "emulator_device_name"
Ex: ./emulator -netdelay 60000 -avd Nexus_5_API_21
Now build your app and install it in emulator.
Run your scenario in app.
Make sure you have your code changes in app that sets timeout to your request and handles that.
Just go to Android device monitor from Android studio , then DDMS -> Emulator Control.There will be Speed and Latency properties.
I found netlimiter4 to be the best solution for throttling data to emulators.
It provides for granular control through a decent gui and gives you graphical feedback on the data throughput to each process. Currently in a free beta.
screenshot
http://www.netlimiter.com/products/nl4
There are apps available on the play store to throttle to actual devices but they require root(I cant provide any advice as to how well they work, if at at all - YMMV.)
search for bradybound on the play store, I can't post more than one link..
have you tried this?
Settings - Networks - More - Mobile Networks - Network mode - Select preferred network (2G for example).
Another method i used was mentioned above. Connect via iPhone hot spot.
Hope this helps.
I'm using mitmproxy HTTPS proxy. https://mitmproxy.org/
Mitmproxy is an open source proxy application that allows intercepting HTTP and HTTPS connections between any HTTP(S) client. It allows to monitor, capture and alter these connections in realtime. Change request, response, header, ...
Additionally you can intercept different requests.
e.g. response_delay.py:
from mitmproxy import http
from time import sleep
def response(flow: http.HTTPFlow) -> None:
sleep(5.0)
Then executing this comment delays all responses from the server:
mitmproxy --cert \*.asdf.at=./cert.pem --scripts response_delay.py
In my app I'm using certificate pinning, so you need to add the certificate (private + public)
cat private.key public.key > cert.pem
You can find a simple Tutorial here.
You can find other scripting examples here.
Very old post but I'll add my two cents. I have been VERY happy with this hardware product ( https://apposite-tech.com/products/linktropy-mini/ ) which has enabled us to simulate a lot of real-world conditions. For a long time we had challenges troubleshooting various things that would work in emulator or with airplane mode.
We have several different profiles setup from zero-connectivity to various stages of marginal connectivity, with different degrees of latency, packet loss, and bit-errors. The great thing about it is we can change these on the fly without having to relaunch the app in an emulator. The price has been entirely worth it for our shop, and it's dead simple to use.
I needed to throttle low internet on AndroidTV native device and based on what I have read, the most suitable solution was to limit the internet access directly in my router.
Go to router settings (locally it is smth like 192.168.0.1) -> set up DHCP server (if it's not running) -> choose IP address of a device and set the restriction;

Host Unresolved Android

In Android emulator I encounter "Connection is lost.Host is Unresolved" error while communicating with server (creating websocket) if URL string is used. instead if IP address and port number is used it works fine.
I have configured it in host file of my ubuntu powered pc. It pings and all from the desktop.
any ideas?
Since the emulator skips the systems hosts file, change the etc/hosts file of the emulator, follow this link
http://eclecticdreams.com/blog/getting-a-hosts-file-onto-an-android-emulator
This is one of the common problems appear in android's native emulator. To resolve this, you need to restart the emulator. Or debug your application on a real device.
As an alternate, I would also like to draw your attention towards Genymotion which offers very stable, reliable and fast android emulators ranging from different device profiles and API versions.

Simulate low network connectivity for Android [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I would like to test my application for cases of low network connectivity. Except standing in the elevator, what is the best way to do this? I've tried wrapping my phone in an aluminum foil, but it didn't help much.
I need to test it on a real device, not in an emulator.
This may sound a little crazy, but a microwave oven serves as a microwave shield. Therefore, putting your device inside a microwave oven (DO NOT turn on the microwave oven while your device is inside!) will cause your signal strength to drop significantly. It definitely beats standing inside an elevator...
You can use emulator for this. Take a look at this page: Android Emulator. Pay attention to next two arguments:
-netdelay <delay>
Set network latency emulation to . Default value is none. See
the table in Network Delay Emulation for supported values.
-netspeed <speed>
Set network speed emulation to . Default value is full. See
the table in Network Speed Emulation for supported values.
Speeds for reference in increasing kbps:
UP DOWN
-------- ----------
gsm GSM/CSD 14.4 14.4
hscsd HSCSD 14.4 57.6
gprs GPRS 28.8 57.6
umts UMTS/3G 384.0 384.0
edge EDGE/EGPRS 473.6 473.6
hsdpa HSDPA 5760.0 13,980.0
lte LTE 58,000.0 173,000.0
evdo EVDO 75,000.0 280,000.0
full No limit ∞ ∞
Since iPhones developer option apply on wifi tethering, you can get an iPhone which has iOS 6 and above (and has been set to use for developments with the xcode), set it to emulate the desired network profile, connect your Android device to its hotspot
Update for Android Studio v 1.5 or greater
As #LouMorda mentioned in a comment below that the Emulator tab mentioned in original post has been removed in Android Studio v 1.5.
Now They've placed these settings in Simulator Settings in AVD Manager.
To access these settings:
Select Tools -> Android -> AVD Manager
Click the Edit AVD button (pencil icon)
The Network Settings can be accessed after clicking the Show Advanced Settings button
Here is a screenshot of how it may appear:
Original Post
For anyone using Android Studio IDE:
Go to Run -> Edit Configurations
Select Android Application -> [Your App]
Select Emulator tab
Here you can change different values for Network Speed(internet speed) and Network Latency (delay) to simulate different speeds and latencies etc
Alternatively, you can enter various arguments in Additional command line options text field as mentioned in #inazaruk's answer.
The screenshot below describes how this Run Configuration screen looks like:
I know its a bit late to answer to this question, but i hope this helps others facing similar issues!
Edit
For anyone using eclipse, see #Abhi's answer below.
I know it's an old question but...
Some phones nowadays have a setting to utilize 2G only. It's perfect for simulating slow internet on a real device.
Years old but hey, I'll chime in with my foolproof method with Genymotion.
Download the Charles free trial: http://www.charlesproxy.com/download/
Install it
ClickProxy -> Throttle Settings
Set up your HTTP throttled speeds
Close that window
Click Proxy -> Throttling to enable the throttle
Open up a Genymotion emulator
Open the wifi settings
Long press the enabled wifi connection
Click Modify Network
Click Show Advanced Options
Set Proxy to Manual
Set the Proxy hostname to 10.0.3.2
Set the Port to 8888
Click Save
And now your network will be throttled!
I have one strategy to settle your problem. You can use the application of proxy to modify or monitor your net status. e.g, Charles.
You ought to change the default config of the Charles like the following picture I posted.
And finally, you will discover the net status has been shaped into lower pace.
You are also able to test slow internet connectivity on an real android device:
Tested with Samsung Galaxy S8 + Android 8.0.0
Go to Settings -> Connection -> Mobile Network -> and under networkmode you can choose to only use 2G or 3G connections
In Android Studio, while running an emulator:
1- Hit settings button at the bottom of the emulator sidebar
2- Go to Cellular
3- Set Network Type
Easy way to test your application with low/bad connection in emulator:
Go Run > Run configurations, select your Android Application, and there go to Target tab.
Look Emulator launch parameters. Here, you can easy modify Network Speed and Network Latency.
There's a simple way of testing low speeds on a real device that seems to have been overlooked. It does require a Mac and an ethernet (or other wired) network connection.
Turn on Wifi sharing on the Mac, turning your computer into a Wifi hotspot, connect your device to this. Use Netlimiter/Charles Proxy or Network Link Conditioner (which you may have already installed) to control the speeds.
For more details and to understand what sort of speeds you should test on check out: http://opensignal.com/blog/2016/02/05/go-slow-how-why-to-test-apps-on-poor-connections/
I'm surprised nobody mentioned this. You can tether via Bluetooth, and separate them by ten+ meters(or less with obstacles). You've got a real bad connection. No microwave, no elevator, no software needed.
Or on an actual device you can go to Settings -> Mobile Networks -> Preferred network types and chose the slowest available...
Of course this is very limited, but for some test- purposes it might be enough.
Facebook built something called Augmented Traffic Control. A brief summary from their GitHub page:
Augmented Traffic Control (ATC) is a tool to simulate network conditions. It allows controlling the connection that a device has to the internet. Developers can use ATC to test their application across varying network conditions, easily emulating high speed, mobile, and even severely impaired networks. Aspects of the connection that can be controlled include:
bandwidth
latency
packet loss
corrupted packets
packets ordering
In order to be able to shape the network traffic, ATC must be running on a device that routes the traffic and sees the real IP address of the device, like your network gateway for instance. This also allows any devices that route through ATC to be able to shape their traffic. Traffic can be shaped/unshaped using a web interface allowing any devices with a web browser to use ATC without the need for a client application.
You can find it here on GitHub: https://github.com/facebook/augmented-traffic-control
They have also written a blog post about it: https://code.facebook.com/posts/1561127100804165/augmented-traffic-control-a-tool-to-simulate-network-conditions/
UPDATE on the Android studio AVD:
open AVD manager
create/edit AVD
click advanced settings
select your preferred connectivity setting
No microwaves or elevators :)
for and mac OS user you can use Network Link Conditioner which could be downloaded from apple. set it as a AP on mac and any divices could connected it.
you can either use facebook open source tools ATC
http://facebook.github.io/augmented-traffic-control/
Go Run > Run configurations, select your Android Application, and there go to Target tab. Do changes as shown in the figure.
I was struggling with this problem for half a day, finally I came to this solution:
Testing on a real device doesn't make much sense overall as you have to go through a lot to make it work. The only logical way to achieve real testing is to make your phone connect to a low quality cellular network, like EDGE, if your phone company provides it. You can try to do this by dialing *#*#4636#*#* in the phone app
The original Android emulator is way too slow for testing and doesn't achieve more than the solution above.
The best way to do this is using Genymotion. It's an Android emulator with much better performance than the original AVDs and the version for personal use is free.
After you created your virtual device in Genymotion, just go through this tutorial to set a proxy for the device.
Run a proxy server on your host machine that simulates bad network conditions, like Crapify or Toxiproxy (I only tested the former) and you're good to go.
Update:
I just realized you can pick the very same strategy with real devices too. I feel like an idiot for not realizing it sooner. Just start a Crapify proxy on your computer, set your phone proxy to your computer's local address and voila, you've got crappy internet on your phone.
Do you want to test for no network connection, or just a slow network connection? If the former, you can go to Settings > Wireless & networks > Airplane mode and turn Airplane mode on. That will let you test network unavailability on an actual device.
as suggested by #VicVu Charles (or any other proxy tool) is an easier way to go. But I would Like to add that you can do this with your device also, not just genymotion or other emulators. Process will be the same:
Modify your device/emulator's wifi setting to use manual proxy. And then Set the Proxy hostname & port
a. set the hostname as ip of your system (get the ip of your pc/mac using ifconfig/ifconfig)
b. set the port number of genymotion (check the proxy settings in charles)
PS: Your device/emulator MUST be using the same wifi since the ip you are using will most probably be the private ip.
Open terminal inAndroid Studio and Go to ../../Android/sdk/tools. 'emulator' executable should be available here.
Run ./emulator -netdelay "delay_in_millis" -avd "emulator_device_name"
Ex: ./emulator -netdelay 60000 -avd Nexus_5_API_21
Now build your app and install it in emulator.
Run your scenario in app.
Make sure you have your code changes in app that sets timeout to your request and handles that.
Just go to Android device monitor from Android studio , then DDMS -> Emulator Control.There will be Speed and Latency properties.
I found netlimiter4 to be the best solution for throttling data to emulators.
It provides for granular control through a decent gui and gives you graphical feedback on the data throughput to each process. Currently in a free beta.
screenshot
http://www.netlimiter.com/products/nl4
There are apps available on the play store to throttle to actual devices but they require root(I cant provide any advice as to how well they work, if at at all - YMMV.)
search for bradybound on the play store, I can't post more than one link..
have you tried this?
Settings - Networks - More - Mobile Networks - Network mode - Select preferred network (2G for example).
Another method i used was mentioned above. Connect via iPhone hot spot.
Hope this helps.
I'm using mitmproxy HTTPS proxy. https://mitmproxy.org/
Mitmproxy is an open source proxy application that allows intercepting HTTP and HTTPS connections between any HTTP(S) client. It allows to monitor, capture and alter these connections in realtime. Change request, response, header, ...
Additionally you can intercept different requests.
e.g. response_delay.py:
from mitmproxy import http
from time import sleep
def response(flow: http.HTTPFlow) -> None:
sleep(5.0)
Then executing this comment delays all responses from the server:
mitmproxy --cert \*.asdf.at=./cert.pem --scripts response_delay.py
In my app I'm using certificate pinning, so you need to add the certificate (private + public)
cat private.key public.key > cert.pem
You can find a simple Tutorial here.
You can find other scripting examples here.
Very old post but I'll add my two cents. I have been VERY happy with this hardware product ( https://apposite-tech.com/products/linktropy-mini/ ) which has enabled us to simulate a lot of real-world conditions. For a long time we had challenges troubleshooting various things that would work in emulator or with airplane mode.
We have several different profiles setup from zero-connectivity to various stages of marginal connectivity, with different degrees of latency, packet loss, and bit-errors. The great thing about it is we can change these on the fly without having to relaunch the app in an emulator. The price has been entirely worth it for our shop, and it's dead simple to use.
I needed to throttle low internet on AndroidTV native device and based on what I have read, the most suitable solution was to limit the internet access directly in my router.
Go to router settings (locally it is smth like 192.168.0.1) -> set up DHCP server (if it's not running) -> choose IP address of a device and set the restriction;

Monitor network activity in Android Phones

I would like to monitor network traffic of my Android Phone. I was thinking using tcpdump for Android, but I'm not sure if I have to cross-compile for the phone.
Another question is the following, If I want to monitor the trafic data for a certain application, there's any command for doing that?
TCPDUMP is one of my favourite tools for analyzing network, but if you find difficult to cross-compile tcpdump for android, I'd recomend you to use some applications from the market.
These are the applications I was talking about:
Shark: Is small version of wireshark for Android phones). This program will create a *.pcap and you can read the file on PC with wireshark.
Shark Reader : This program allows you to read the *.pcap directly in your Android phone.
Shark app works with rooted devices, so if you want to install it, be sure that you have your device already rooted.
Good luck ;)
If you are doing it from the emulator you can do it like this:
Run emulator -tcpdump emulator.cap -avd my_avd to write all the emulator's traffic to a local file on your PC and then open it in wireshark
There is a similar post that might help HERE
Note: tcpdump requires root privileges, so you'll have to root your phone if not done already. Here's an ARM binary of tcpdump (this works for my Samsung Captivate). If you prefer to build your own binary, instructions are here (yes, you'd likely need to cross compile).
Also, check out Shark For Root (an Android packet capture tool based on tcpdump).
I don't believe tcpdump can monitor traffic by specific process ID. The strace method that Chris Stratton refers to seems like more effort than its worth. It would be simpler to monitor specific IPs and ports used by the target process. If that info isn't known, capture all traffic during a period of process activity and then sift through the resulting pcap with Wireshark.
For Android Phones(Without Root):- you can use this application tPacketCapture this will capture the network trafic for your device when you enable the capture.
See this url for more details about network sniffing without rooting your device.
Once you have the file which is in .pcap format you can use this file and analyze the traffic using any traffic analyzer like Wireshark.
Also see this post for further ideas on Capturing mobile phone traffic on wireshark
The DDMS tool included in the Android SDK includes a tool for monitoring network traffic. It does not provide the kind of detail you get from tcpdump and similar low level tools, but it is still very useful.
Oficial documentation: http://developer.android.com/tools/debugging/ddms.html#network
Preconditions: adb and wireshark are installed on your computer and you have a rooted android device.
Download tcpdump to ~/Downloads
adb push ~/Downloads/tcpdump /sdcard/
adb shell
su root
mv /sdcard/tcpdump /data/local/
cd /data/local/
chmod +x tcpdump
./tcpdump -vv -i any -s 0 -w /sdcard/dump.pcap
Ctrl+C once you've captured enough data.
exit
exit
adb pull /sdcard/dump.pcap ~/Downloads/
Now you can open the pcap file using Wireshark.
As for your question about monitoring specific processes, find the bundle id of your app, let's call it com.android.myapp
ps | grep com.android.myapp
copy the first number you see from the output. Let's call it 1234. If you see no output, you need to start the app. If you still don't see the app via ps try using top.
Download strace to ~/Downloads and put into /data/local using the same way you did for tcpdump above.
cd /data/local
./strace -p 1234 -f -e trace=network -o /sdcard/strace.txt
Now you can look at strace.txt for ip addresses, and filter your wireshark log for those IPs.
You would need to root the phone and cross compile tcpdump or use someone else's already compiled version.
You might find it easier to do these experiments with the emulator, in which case you could do the monitoring from the hosting pc. If you must use a real device, another option would be to put it on a wifi network hanging off of a secondary interface on a linux box running tcpdump.
I don't know off the top of my head how you would go about filtering by a specific process. One suggestion I found in some quick googling is to use strace on the subject process instead of tcpdump on the system.
Without root, you can use debug proxies like Charlesproxy&Co.
Packet Capture is the best tool to track network data on the android.
DOesnot need any root access and easy to read and save the calls based on application.
Check this out
Try this application
https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture
We can view all networking communications .. even SSL encrypted communications.
The common approach is to call "cat /proc/net/netstat" as described here:
Android network stats

Categories

Resources