charles如何抓取https数据包的?

https使用ssl加密,原理下面的连接解释的很清楚 HTTPS那些事(一)HTTPS原理 我的问题是,如果浏览器和服务器之间的通信都用浏览器随机生成…
关注者
170
被浏览
77,205
登录后你可以
不限量看优质回答私信答主深度交流精彩内容一键收藏

简单的说就是中间人攻击,也就是“man-in-the-middle attack”

先来看一下charles的document:

“Charles can be used as a man-in-the-middle HTTPS proxy, enabling you to view in plain text the communication between web browser and SSL web server.

Charles does this by becoming a man-in-the-middle. Instead of your browser seeing the server’s certificate, Charles dynamically generates a certificate for the server and signs it with its own root certificate (the Charles CA Certificate). Charles receives the server’s certificate, while your browser receives Charles’s certificate. Therefore you will see a security warning, indicating that the root authority is not trusted. If you add the Charles CA Certificate to your trusted certificates you will no longer see any warnings – see below for how to do this.”

先说一下https使用的非对称加密的原理。等等说非对称加密之前还要说下对称加密的原理。简单来说,对称加密就是加密解密使用同一个密钥。浏览器和服务器交互的话一般会动态生成一个密钥,所以密钥如何交换就成了问题。

下面引入非对称密钥,非对称加密主要用于密钥交换(也叫密钥协商),能够很好地解决这个问题。浏览器和服务器每次新建会话时都使用非对称密钥交换算法协商出对称密钥,使用这些对称密钥完成应用数据的加解密和验证,整个会话过程中的密钥只在内存中生成和保存,而且每个会话的对称密钥都不相同(除非会话复用),中间者无法窃取。

密钥交换过程:服务器的公钥是公开的,私钥是不公开的。浏览器先向服务器取得公钥,然后用公钥加密自己的私钥连同自己私钥加密的请求一并发送给服务器。服务器使用自己私钥解密得到浏览器的私钥,使用浏览器的私钥解密请求。然后再用浏览器的私钥加密response发送回服务器。

中间人攻击是先伪装服务器向浏览器发送伪造的公钥,从而取得浏览器的私钥。这样就完成的浏览器端的解密。服务器端类似。

但是!!!https是可以防止中间人攻击的,因为服务器的公钥是用证书的。charles伪造的证书一般浏览器会警告,所以我们需要将charles的证书认为可靠的。从而实现中间人。

关于iOS 9的无法使用Charles抓包的问题。

SSL Proxying with iOS 9


You need to disable App Transport Security in your app to use Charles SSL Proxying with apps running on iOS 9.

To disable ATS you need to add keys to your app's Info.plist file, as below. See this tech note from Apple for more information.

You must remember to re-enable ATS before you release your app to take advantage of the security that ATS provides.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

Note that this means that you cannot use Charles to observe SSL traffic from apps that you do not control.


ref: FAQs • Charles Web Debugging Proxy


About ATS:Cocoa Keys


简单地说,iOS的ATS是一种对安全的加强。在About ATS里面我们可以看到ATS对证书的一些限制。现在无法使用Charles,则是因为iOS 9 认为这个连接不安全,目前的解决方案是禁用ATS。长远来看,要么Charles的证书能够是ATS眼中的『安全证书』,要么ATS自己修改spec将Charles的证书认为是安全的,但是这两种方法目前看来可能还需要一段时候。



ok,over。

如满意求点赞。