一、創建遠程虛擬接口Remote Virtual Interface (RVI)
iOS上抓包的方法主要有:
1. Wifi共享,然后通過fiddler、charles等可視化抓包工具。可以設置mac進行wifi共享,或者使用360隨身wifi等工具;
2. 設置wifi的HTTP代理,然后通過可視化抓包工具;
3. RVI方法;下面就介紹RVI方法,該方法適用于iOS5.0以上設備,需要mac并且安裝Xcode。
1)將iOS設備通過USB連接到Mac上;
2)通過itunes獲取iOS設備的UDID;
3)打開終端terminal,建立RVI
$ # First get the current list of interfaces.
$ ifconfig -l
lo0 gif0 stf0 en0 en1 p2p0 fw0 ppp0 utun0
$ # Then run the tool with the UDID of the device.
$ rvictl -s 74bd53c647548234ddcef0ee3abee616005051ed
Starting device 74bd53c647548234ddcef0ee3abee616005051ed [SUCCEEDED]
$ # Get the list of interfaces again, and you can see the new virtual
$ # network interface, rvi0, added by the previous command.
$ ifconfig -l
lo0 gif0 stf0 en0 en1 p2p0 fw0 ppp0 utun0 rvi0
rvi0就是Remote Virtual Interface,這也就意味著在你的Mac上虛擬了一個iOS設備接口rvi0.
二、通過tcpdump抓包
1. 運行tcpdump
sudo tcpdump -i rvi0? -w dump.pcap
參量的意義:-i rvi0 選擇需要抓取的接口為rvi0(遠程虛擬接口);-w dump.pcap 設置保存的文件名稱;
2. 在iOS app上進行操作;
3. 結束操作之后,在terminal中ctrl+c終止tcpdump;
4. 這個時候可以刪除RVI:
rvictl -x 74bd53c647548234ddcef0ee3abee616005051ed
三、處理tcpdump的抓包數據
1. 使用tcprewrite將tcpdump抓包后的數據轉換為可視化抓包工具可以解析的數據
1)通過HomeBrew安裝tcprewrite
brew install tcpreplay
2)將原始數據包轉換為以太網數據包
Tcprewrite重寫第二層以太網層:
tcprewrite --dlt=enet --enet-dmac=00:11:22:33:44:55 --enet-smac=66:77:88:99:AA:BB --infile=dump.pcap --outfile=dumpFileFinal.pcap
或者tcprewrite重寫第四層TCP、UDP層:
tcprewrite --portmap=80:8080,22:8022 --infile=dump.pcap --outfile=dumpFileFinal.pcap
3)可視化抓包工具打開dumpFileFinal.pcap,比如charles。然后進行包分析、查看統計流量等等,或者導出為csv文件進行分析。
參考網址:
https://developer.apple.com/library/mac/qa/qa1176/_index.html#//apple_ref/doc/uid/DTS10001707-CH1-SECRVI
http://blog.manbolo.com/2013/02/22/analysing-ios-app-network-performances-on-cellularwifi
http://www.cnblogs.com/wupher/archive/2013/03/25/2980161.html
屬于個人隨手筆記 不理解可以加個人qq: 2963542803