Android通過tcpdump抓包

轉自:http://www.cnblogs.com/likwo/archive/2012/09/06/2673944.html


1. 手機要有root權限

2. 下載tcpdump   http://www.strazzere.com/android/tcpdump

3. adb push c:\wherever_you_put\tcpdump /data/local/tcpdump             (注:如果無權限push,則可通過手動拷貝)

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 

 

另注:Ctrl + C可退出shell命令

示例流程:

C:\Users\r400>adb shell
shell@android:/ $ su
su
shell@android:/ # chmod 6755 /data
chmod 6755 /data/local/tcpdump
shell@android:/ # /data/local/tcpd
/data/local/tcpdump -i any -p -s 0
tcpdump: listening on any, link-ty
5 bytes
^C
C:\Users\r400>adb pull /sdcard/cap
799 KB/s (72836 bytes in 0.089s)


C:\Users\r400>adb pull /sdcard/cap
455 KB/s (72836 bytes in 0.156s)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章