Is TCP packet filtering possible on mobile platforms?

lisovaccaro

I'm interested on having my mobile app run in the background and filter TCP packets.

I know I'll face restrictions due to sandboxing, each OS privilege levels and how iOS handles background tasks so I want to confirm if it's possible to do it on iOS and Android.

Do Android and iOS allow you to analyze and modify packets going through TCP ports? If it's possible how? Could I do it while my app remains on the background?

atok

iOS

I don't think it is possible on iOS.

I didn't find a public API for network monitoring/packet filtering. There is a possibility that such API exists but it's hidden. But in that case Apple App Store review guidelines states:

2.5 Apps that use non-public APIs will be rejected

If you need one specific quote to show that it is not possible, you can use this:

iOS does not support packet tracing directly. However, if you connect your iOS device to a Mac via USB...

from official Apple Technical Q&A QA1176.

Alternatives

The next best thing is to a configure a proxy server manually in Settings and then filter the traffic on the server-side. Running the proxy locally, on the device is not an option because of limitations of iOS background tasks:

2.16 Multitasking Apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc.

Also, this post suggests it might be possible to set-up a VPN connection programmatically on iOS 8. It would also require to send the traffic of the device and I'm not sure about compliance of this method with guidelines.

Non-alternatives

Some apps provide functionality of measuring the network traffic. But they use dedicated API for network statistics: iPhone Data Usage Tracking/Monitoring.

There are also ways to packet trace on iOS via USB cable described here.

Android

On Android you can configure the device to use your app as a VPN service. But:

  • It requires you to display a dialog describing the consequences of giving a permission to act as a VPN.
  • You have to show a persistent notification while VPN is active. An example of app that does it is tPacketCapture.

To ask for user permission, you call VpnService.prepare:

public void onClick(View v) {
     Intent intent = VpnService.prepare(getApplicationContext());
     if (intent != null) {
          startActivityForResult(intent, 0);
     } else {
          onActivityResult(0, RESULT_OK, null);
     }
}

and handle the result, starting your VpnService.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Intent intent = new Intent(this, MyVpnService.class);
        startService(intent);
    }
}

Your VpnService have to implement public int onStartCommand(). The service is treated as a foreground service and should not get killed by the OS.

This question: Android VpnService to capture packets won't capture packets and it's comments shed some light on the packet handling itself.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Creating TCP packet with POX

From Dev

Parsing a TCP Packet data

From Dev

Print TCP Packet Data

From Dev

reassembly of tcp packet

From Dev

Send TCP packet in PHP

From Dev

TCP FIN in separate packet

From Dev

Is it possible to create a single socket, single thread, TCP/IP packet reader for multiple clients?

From Dev

OS X OpenVPN packet filtering

From Dev

Filtering TCPDUMP over packet length

From Dev

How to understand a packet is TCP CLOSE packet with sharPcap

From Dev

Is WebGL hardware accelerated on mobile platforms?

From Dev

Xamarin C# and Mobile Platforms

From Dev

possible packet loss

From Dev

detecting TCP/IP packet loss

From Dev

Send TCP SYN packet with payload

From Dev

TCP RST on TELNET - Packet builder

From Dev

TCP Client / Server packet loss

From Dev

Socket TCP Communication packet splitted

From Dev

What are different between these?(TCP packet)

From Dev

Controlling TCP connection at packet level

From Dev

Alternative to Iptables for packet filtering in OVS interfaces

From Dev

Filtering message packet's body in ejabberd

From Dev

Is it better to develop on both mobile platforms in parallel or sequentially?

From Dev

Unexpected whitespace after jumbotron on mobile platforms

From Dev

How to confirm the different mobile platforms with Bootstrap?

From Dev

Unexpected whitespace after jumbotron on mobile platforms

From Dev

Does TCP verify data all at once or as a packet by packet verification?

From Dev

Why TCPDUMP shows Ethernet packet when querying TCP packet?

From Dev

Is it possible to access the hexdump of a packet in PyShark?