轉載
原文地址:http://www.neatstudio.com/show-2454-1.shtml
在mac下面,居然沒有好的抓包工具,這讓我十分糾結,畢竟不可能為了抓一個http包就跑到win下折騰。或許有人說tcpdump這么好的工具,你怎么不用。說實話,tcpdump太復雜了,我還沒有細看,再加上不是所見所得,所以,用起來不是那么習慣
又有人說,wireshark怎么不用?好吧,其實我是有裝wireshark,只是啟動的時候會啟動XQuartz,有點慢,當然這不是主要的,而是wireshark功能太強大了,以至於都不會寫過濾器。
也有人說,圖方便的話,完全可以用chrome自帶的抓包工具啊?在沒有找到這個工具之前,你可以嘗試在地址欄輸入:chrome://chrome-urls/,你會發現chrome原來有這么多的隱藏工具,嗯。我要說的就是其中的一個:chrome://net-internals/ ,在Events中,你可以進行過濾,不過,針對https的包,內容沒法顯示
越來越懷念windows下面,smartsniff完全就是wireshark的簡化版,抓起包來刷刷的,過濾數據也很方便。
當然,mac下面的charles就真心不錯了,試用了一下,果然對於https的包也能夠抓取。
這里有一個簡單的教程(實際操作略有出入):
在Mac下做開發,用Fiddler抓包由於離不開Windows比較痛苦,還好有Charles,到官網http://www.charlesproxy.com/可下載到最新版本(若不支持rMBP可拖到Retinizer中把文字變清晰)
HTTP抓包
- 打開Charles程序
- 查看Mac電腦的IP地址,如192.168.1.7
- 打開iOS設置,進入當前wifi連接,設置HTTP代理Group,將服務器填為上一步中獲得的IP,即192.168.1.7,端口填8888
- iOS設備打開你要抓包的app進行網絡操作
- Charles彈出確認框,點擊Allow按鈕即可
HTTPS抓包
- 下載Charles證書http://www.charlesproxy.com/ssl.zip,解壓后導入到iOS設備中(將crt文件作為郵件附件發給自己,再在iOS設備中點擊附件即可安裝;也可上傳至dropbox之類的網盤,通過safari下載安裝)
- 在Charles的工具欄上點擊設置按鈕,選擇Proxy Settings…
- 切換到SSL選項卡,選中Enable SSL Proxying,別急,選完先別關掉,還有下一步
- 這一步跟Fiddler不同,Fiddler安裝證書后就可以抓HTTPS網址的包了,Charles則麻煩一些,需要在上一步的SSL選項卡的Locations表單填寫要抓包的域名和端口,點擊Add按鈕,在彈出的表單中Host填寫域名,比如填api.instagram.com,Port填443
接下來就跟HTTP抓包一樣了
---EOF---
上文中的一些操作,其實是有點出入的(HTTPS)抓包
1、如果沒有設置ssl的話,那么你看到的ssl的接口中,會有一個報錯:SSL Proxying not enabled for this host: enable in Proxy Settings, SSL locations,這個時候,在左側的域名上點右鍵:enable ssl,就OK了。(其實就是上面的第4部,不過這個操作是簡化操作,上面的第4步太麻煩了)
2、如果這樣還是不能抓包,那么官方會有一個說明(http://www.charlesproxy.com/documentation/using-charles/ssl-certificates/):
MAC OS X
Download and unzip the Charles CA Certificate bundle. The bundle contains the Charles CA Certificate file.
Run the Keychain Access utility from the Applications/Utilities folder. This tool enables you to manage your certificates.
Choose the "login" keychain then go to the File menu and choose Import. Choose the .crt file you downloaded above, and ensure that the login keychain is chosen in the dropdown menu.
Complete the import and the Charles CA SSL Certificate will now be trusted for your login account.
Move the Charles Proxy SSL Proxying certificate from your login keychain to the System keychain by drag-and-drop if you want all users on the machine to trust it.
You will need to quit and reopen Safari to see the change.
GOOGLE CHROME
On Mac OS X, please follow the instructions for Mac OS X above. These instructions only apply on Windows.
Open the Options dialog, go to the "Under the Hood" tab, then click the "Manage certificates" button.
Go to the Trusted Root Certification Authorities tab and click Import.
Find the charles-proxy-ssl-proxying-certificate.crt file. On Windows and Linux it is in the docs directory in your Charles installation directory. On Mac OS X (or if you can’t find it) you can download and unzip ssl.zip.
Choose the charles-proxy-ssl-proxying-certificate.crt file, then click Next and Finish, leaving the default options, until you complete the import. Chrome will now always trust certificates signed by Charles.
After importing you can delete the charles-proxy-ssl-proxying-certificate.crt file if you downloaded it.
---如果用chrome,那就直接可以使用/如果firefox,會有插件提示你安裝/如果是safari,則需要打開證書管理器,將剛才導入的證書把login改為system(這樣所有用戶就都能使用了,不過都是自己的電腦,無所謂了),safari可能需要重啟下瀏覽器
經此,我終於可以抓包了。而且https包也不再只是一堆 亂碼。黑黑