Recently made an Android networking grab kit
I've been searching the internet for a long time
There's still no clue.
So think about the Linux layer.
So the tcpdump of Linux is used to realize the function of grasping packet.
The simple definition of tcpdump is: The dump the traffic on a network, based on the user's definition of the packet interception of packets on the Data Packet Analysis tool.
As the Classic System Administrator tool on the Internet, tcpdump is one of the necessary things for each advanced system administrator to analyze the network, troubleshoot problems and so on with its powerful function and flexible interception strategy.
For tcpdump detailed can refer to http://baike.baidu.com/view/76504.htm?fr=ala0_1_1 Baidu Encyclopedia introduction
I'm here to focus on how to use Tcpdump on Android
The test machine I used was cracked version G2 and simulator
The specific thing is to execute the Linux command in the APK program.
[C-sharp]View Plaincopy
- Tcpdump-p-vv-s 0-w/sdcard/capture.pcap
This will allow you to write a capture.pcap file on the sdcard of the captured bag.
And this file can be opened with Wireshark on the PC to view very convenient
The specific source code is as follows
Mainhook.java
[C-sharp]View Plaincopy
- Package Zy.hook;
- Import java.io.IOException;
- Import android.app.Activity;
- Import Android.os.Bundle;
- Import Android.util.Log;
- Public class Mainhook extends Activity {
- /** Called when the activity is first created. * /
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- Super.oncreate (savedinstancestate);
- Setcontentview (R.layout.main);
- try {
- //runtime.getruntime (). EXEC ("su");
- //runtime.getruntime (). EXEC ("dd if=/sdcard/tcpdump of=/data/local/tcpdump");
- //runtime.getruntime (). EXEC ("chmod 6755/data/local/tcpdump");
- Runtime.getruntime (). EXEC ("tcpdump-p-vv-s 0-w/sdcard/capture.pcap");
- LOG.I ("Run","success!!!!!!!!!");
- } catch (IOException e) {
- //TODO auto-generated catch block
- E.printstacktrace ();
- LOG.I ("Run", e.tostring ());
- }
- }
- }
Androidmanifest.xml
[XHTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="Zy.hook"
- android:versioncode="1"
- android:versionname="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name" >
- <activity android:name=". Mainhook "
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="Android.intent.action.MAIN" />
- <category android:name="Android.intent.category.LAUNCHER" />
- </intent-filter>
- </Activity>
- </Application>
- <uses-sdk android:minsdkversion="7" />
- <uses-permission android:name="Android.permission.WRITE_EXTERNAL_STORAGE" />
- </manifest>
In particular, don't forget the permissions <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
The statement
Run the program so we can grab the bag.
The Capture.pcap file is generated on the SDcard
After a while, export the file from the SDcard
Then we open it with Wireshark.
can be very convenient to view the bags we have caught
Hope to be useful to everyone
The copyright of this article belongs to csdn Bo Master Zeng All
Http://blog.csdn.net/Zengyangtech/archive/2010/08/31/5853366.aspx
Reprint Please specify this sentence
Android networked surveillance capture kit maker (Tcpdump use)