使用httprequesJson-Handle cpdumpwireshark工具进行,抓取手机访问网络的包,分析request及response请求,通过httprequester来实现模拟发包及接收.
对于手机开发,分析手机访问网络数据,十分必要!
1.使用tcpdump包抓取网络数据包,手机要root,抓取过程请看:
1. 手机要有root权限
2. 下载tcpdump http://www.strazzere.com/android/tcpdump
3. adb push c:wherever_you_put cpdump /data/local/tcpdump
4. adb shell chmod 6755 /data/local/tcpdump
5, adb shell, su获得root权限
6, cd /data/local
7, ./tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
命令参数:
# "-i any": listen on any network interface
# "-p": disable promiscuous mode (doesn't work anyway)
# "-s 0": capture the entire packet
# "-w": write packets to a file (rather than printing to stdout)
... do whatever you want to capture, then ^C to stop it ...
8, adb pull /sdcard/capture.pcap d:/
9, 在电脑上用wireshark打开capture.pcap即可分析log
Execute the following if you would like to watch packets go by rather than capturing them to a file (-n skips DNS lookups. -s 0 captures the entire packet rather than just the header):
adb shell tcpdump -n -s 0
Typical tcpdump options apply. For example, if you want to see HTTP traffic:
只监听http
adb shell tcpdump -X -n -s 0 port 80
根据以上的信息,写一个bat去执行(tcpdump文件必须在当前目录里)。
开始tcpdump
adb push tcpdump /data/local/tcpdump
adb shell chmod 6755 /data/local/tcpdump
adb shell rm -r /sdcard/capture.pcap
adb shell /data/local/tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
pause
下载tcpdump文件到电脑
adb pull /sdcard/capture.pcap capture.pcap
问题:有些机器root后通过adb shell 后,默认不是root用户,需要输入 su才能切换到root,这样在执行批处理会有问题,解决方法如下
adb shell "su -c 'sleep 1'"
adb start-server
adb push tcpdump /data/local/tcpdump
2.通过wireshark工具打开刚才抓取的数据包,可通过http&&ip.addr==119.161.212.35(手机网络访问的目标IP地址)这样的语句过滤,准确得到有用的数据
3.定位到具体的某一个包,双击打开后找出请求的http地址,以及Json数据,本例中的数据为,些请求是更用户所设置的学校及院系信息,地址可用,可试着修下Json中的内容.
http://kechengbiao.me/popular.json
{"from_app":true,"department_name":"EECS","school_name":"北京大学","token":"EHFWUCVRRSKATAOHAGTBSR","user":{"grade":2011,"sex":1,"name":"mingyong"},"locale":"ch"}
4.打开Firefox使用其插件HttpRequester及Json-handle来模拟手机提交post请求,并查年返回数据
将上面得到的http地址及json输入到httprequest中,如图:
5.第四步是在本例中实际更新学校的post请求,根据已知的http请求,查看是否更新成功:
http://kechengbiao.me/popular.json?token=EHFWUCVRRSKATAOHAGTBSR&locale=ch&from_app=true&version=1.51
如图:
由于Firefox安装了Json-handle,打开网页后默认解析Json数据.