在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抓包一样了
---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/):
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.
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包也不再只是一堆 乱码。黑黑