手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

mac下的抓包工具Charles

首页 > 苹果相关 >

 在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抓包

  1. 打开Charles程序
  2. 查看Mac电脑的IP地址,如192.168.1.7
  3. 打开iOS设置,进入当前wifi连接,设置HTTP代理Group,将服务器填为上一步中获得的IP,即192.168.1.7,端口填8888
  4. iOS设备打开你要抓包的app进行网络操作
  5. Charles弹出确认框,点击Allow按钮即可

HTTPS抓包

  1. 下载Charles证书http://www.charlesproxy.com/ssl.zip,解压后导入到iOS设备中(将crt文件作为邮件附件发给自己,再在iOS设备中点击附件即可安装;也可上传至dropbox之类的网盘,通过safari下载安装)
  2. 在Charles的工具栏上点击设置按钮,选择Proxy Settings…
  3. 切换到SSL选项卡,选中Enable SSL Proxying,别急,选完先别关掉,还有下一步
  4. 这一步跟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包也不再只是一堆 乱码。黑黑




本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"易栈网-膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

Tags: charles, wireshark

« 上一篇 | 下一篇 »

2条记录访客评论

Just wanna comment on few general things, The website design and style is perfect, the content is very great :
D.

Post by Endovex on 2017, April 22, 8:02 AM 引用此文发表评论 #1

微信内的请求 szextshort.weixin.qq.com 域的包依旧是乱码,这是他们自己加密的?
-----
1、你是用ssl的抓 包吗?
2、如果是。应该是二进制包。这个就看你怎么分析他的头了。

Post by 自我 on 2015, April 12, 11:20 PM 引用此文发表评论 #2


发表评论

评论内容 (必填):