Android下使用TCPDUMP实现数据抓包教程
作者:junjie 时间:2021-12-08 07:58:42
如果想分析Android下 某个APP的网络数据交互,需要在Android手机上抓包,最常用的抓包工具非tcpdump莫属,用tcpdump生成Wireshark识别的 pcap文件,然后将pcap文件下载到电脑上,用电脑上的Wireshark加载pcap文件,通过Wireshark分析tcpdump抓取的数据。
一、安装tcpdump
为Android手机安装tcpdump,首先必须将Android手机root,现在市面上常用的root工具都很傻瓜很强大,推荐使用root精灵,将手机root以后,我们就可以为手机安装tcpdump了。
先下载tcpdump文件, 下载地址:http://xiazai.jb51.net/201502/other/tcpdump.rar
adb push tcpdump /sdcard/
adb Shell
su
cat /sdcard/tcpdump > /system/bin/tcpdump
上一条命令如果提示没有权限,接着执行如下命令尝试给 /system 目录增加写权限
su
mount
在mount结果中找到包含/system的一行,类似如下:
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,seclabel,relatime,data=ordered 0 0
去处/system前半行,即/dev/block/platform/msm_sdcc.1/by-name/system,执行如下命令:
mount -o remount /dev/block/platform/msm_sdcc.1/by-name/system /system
这个时候/system就拥有写权限了,继续执行:
cat /sdcard/tcpdump > /system/bin/tcpdump
chmod 777 /system/bin/tcpdump
到此为止,tcpdump就成功安装到了/system/bin/目录下,接着用如下命令还是抓包
二、使用tcpdump抓包
tcpdump -i wlan0 -s 0 -w /sdcard/1.pcap
可以结束时使用Ctrl+c快捷键让tcpdump结束抓包,抓到数据会存到/sdcard/1.pcap文件内
重新打开一个终端(Terminal),执行如下命令
adb pull /sdcard/1.pcap .
1.pcap文件被下载到了终端上的当前目录下
三、安装Wireshark并分析pcap文件
从Wireshark官网https://www.wireshark.org/下 载适合你系统的Wireshark,然后点击你下载后的Wireshark安装包安装好Wireshark,找到刚刚下载好的1.pcap文件,双击 1.pcap文件,1.pcap文件会自动被Wireshark打开。在Wireshark的Filter内输入如下一些过滤条件,可以更加方便地分析数 据来源。
tcp.port == 80 //过滤来自80端口的TCP数据
udp.port == 12345 //过滤来自12345端口的UDP数据
ip.src == 192.168.0.1 //过滤源IP为192.168.0.1的数据
ip.dst == 192.168.0.1 //过目的IP为192.168.0.1的数据
以上过滤条件可以用and跟or相互组合,例如
tcp.port == 80 and ip.src == 192.168.0.1 //过滤来自80端口,源IP为192.168.0.1的TCP数
udp.port == 12345 or ip.dst == 192.168.0.1 //过滤来自12345端口的UDP数据,或者目的IP为192.168.0.1的数据
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解Java高并发编程之AtomicReference
![](https://img.aspxhome.com/file/2023/4/99924_0s.jpg)
Mybatis使用@Select注解sql中使用in问题
IDEA实用好用插件推荐及使用方法教程详解(必看)
![](https://img.aspxhome.com/file/2023/1/62041_0s.jpg)
grails不能运行fork模式解决方法
dubbo整合springboot新手入门教程详解
![](https://img.aspxhome.com/file/2023/2/106142_0s.png)
详解Spring Boot Profiles 配置和使用
Android学习教程之日历控件使用(7)
![](https://img.aspxhome.com/file/2023/6/123326_0s.jpg)
Android 图片切换器(dp、sp、px) 的单位转换器
![](https://img.aspxhome.com/file/2023/3/138913_0s.jpg)
解决SpringBoot加载application.properties配置文件的坑
![](https://img.aspxhome.com/file/2023/5/85435_0s.png)
Eclipse 开发java 出现Failed to create the Java Virtual Machine错误解决办法
灵活使用Android中ActionBar和ViewPager切换页面
![](https://img.aspxhome.com/file/2023/5/137395_0s.gif)
Java Bean Validation使用示例详解
mybatis如何实现saveOrUpdate
Android中基于XMPP协议实现IM聊天程序与多人聊天室
![](https://img.aspxhome.com/file/2023/6/123366_0s.jpg)
C++利用ImGUI绘制D3D外部菜单
![](https://img.aspxhome.com/file/2023/0/127550_0s.jpg)
Android仿QQ微信实时监测网络状态
![](https://img.aspxhome.com/file/2023/3/120173_0s.jpg)
C#实现DataTable转TXT、CSV文件
C#异常执行重试的实现方法
android 大图片拖拽并缩放实现原理
![](https://img.aspxhome.com/file/2023/6/100596_0s.png)
Springboot通过run启动web应用的方法
![](https://img.aspxhome.com/file/2023/7/64527_0s.png)