charles 為什么能抓https的包吓歇?原理是什么?
原創(chuàng)?2016年10月18日 19:44:48
標(biāo)簽:
眾所周知,http明文傳輸檬输,https加密就是為了在傳輸層禁止暴露明文照瘾,但是為什么抓包工具又能抓到? 豈不是和https的設(shè)計(jì)矛盾了??
簡(jiǎn)單的說(shuō)就是中間人攻擊,也就是“man-in-the-middle attack”
先來(lái)看一下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.”
先說(shuō)一下https使用的非對(duì)稱(chēng)加密的原理丧慈。等等說(shuō)非對(duì)稱(chēng)加密之前還要說(shuō)下對(duì)稱(chēng)加密的原理析命。簡(jiǎn)單來(lái)說(shuō),對(duì)稱(chēng)加密就是加密解密使用同一個(gè)密鑰逃默。瀏覽器和服務(wù)器交互的話(huà)一般會(huì)動(dòng)態(tài)生成一個(gè)密鑰鹃愤,所以密鑰如何交換就成了問(wèn)題。
下面引入非對(duì)稱(chēng)密鑰完域,非對(duì)稱(chēng)加密主要用于密鑰交換(也叫密鑰協(xié)商)软吐,能夠很好地解決這個(gè)問(wèn)題。瀏覽器和服務(wù)器每次新建會(huì)話(huà)時(shí)都使用非對(duì)稱(chēng)密鑰交換算法協(xié)商出對(duì)稱(chēng)密鑰吟税,使用這些對(duì)稱(chēng)密鑰完成應(yīng)用數(shù)據(jù)的加解密和驗(yàn)證凹耙,整個(gè)會(huì)話(huà)過(guò)程中的密鑰只在內(nèi)存中生成和保存,而且每個(gè)會(huì)話(huà)的對(duì)稱(chēng)密鑰都不相同(除非會(huì)話(huà)復(fù)用)肠仪,中間者無(wú)法竊取肖抱。
密鑰交換過(guò)程:服務(wù)器的公鑰是公開(kāi)的,私鑰是不公開(kāi)的异旧。瀏覽器先向服務(wù)器取得公鑰意述,然后用公鑰加密自己的私鑰連同自己私鑰加密的請(qǐng)求一并發(fā)送給服務(wù)器。服務(wù)器使用自己私鑰解密得到瀏覽器的私鑰,使用瀏覽器的私鑰解密請(qǐng)求荤崇。然后再用瀏覽器的私鑰加密response發(fā)送回瀏覽器(此處之前筆誤寫(xiě)成服務(wù)器了)拌屏。
中間人攻擊是先偽裝服務(wù)器向?yàn)g覽器發(fā)送偽造的公鑰,從而取得瀏覽器的私鑰术荤。這樣就完成的瀏覽器端的解密倚喂。服務(wù)器端類(lèi)似。
但是O裁俊N裉啤雳攘!https是可以防止中間人攻擊的带兜,因?yàn)榉?wù)器的公鑰是用證書(shū)的。charles偽造的證書(shū)一般瀏覽器會(huì)警告吨灭,所以我們需要將charles的證書(shū)認(rèn)為可靠的刚照。從而實(shí)現(xiàn)中間人。
關(guān)于iOS 9的無(wú)法使用Charles抓包的問(wèn)題喧兄。
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 thistech note from Applefor more information.
You must remember to re-enable ATS before you release your app to take advantage of the security that ATS provides.
NSAppTransportSecurity
? NSAllowsArbitraryLoads
?
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
簡(jiǎn)單地說(shuō)无畔,iOS的ATS是一種對(duì)安全的加強(qiáng)。在About ATS里面我們可以看到ATS對(duì)證書(shū)的一些限制》驮現(xiàn)在無(wú)法使用Charles浑彰,則是因?yàn)閕OS 9 認(rèn)為這個(gè)連接不安全,目前的解決方案是禁用ATS拯辙。長(zhǎng)遠(yuǎn)來(lái)看郭变,要么Charles的證書(shū)能夠是ATS眼中的『安全證書(shū)』,要么ATS自己修改spec將Charles的證書(shū)認(rèn)為是安全的涯保,但是這兩種方法目前看來(lái)可能還需要一段時(shí)候诉濒。
ok,over夕春。
如滿(mǎn)意求轉(zhuǎn)載注明出處