0x00 抓包分析 簡單的搜索之後發現,很多參數都是登陸上面這個請求返回的值,這個請求在輸入完賬號游標到達密碼框時就會生成! 0x01 加密邏輯分析 搜索su=可以很快找到加密的位置,上圖看到e.su和e.sp都是由sinaSSOEncoder這個函數生成的,搜索sinaSSOEncoder發現就是 ...
0x00 抓包分析

簡單的搜索之後發現,很多參數都是登陸上面這個請求返回的值,這個請求在輸入完賬號游標到達密碼框時就會生成!

0x01 加密邏輯分析
搜索su=可以很快找到加密的位置,上圖看到e.su和e.sp都是由sinaSSOEncoder這個函數生成的,搜索sinaSSOEncoder發現就是這個js,也就是說把當前js全部拷貝下來就可用

這裡可以得知su是由賬號加密得到
function getSu(user) { return sinaSSOEncoder.base64.encode((user)) }

me.rsaPubkey,me.servertime,me.noce這三個值都是由伺服器返回的值,不多做解釋!

最後這個b則是我們的密碼,e.sp也就是處理完後的b值
function getSp(me,pwd) { var f = new sinaSSOEncoder.RSAKey; f.setPublic(me.pubkey, "10001"); b = f.encrypt([me.servertime, me.nonce].join("\t") + "\n" + pwd); return b }

在當前js文件中搜索prelt得知是由preloginTime生成

preloginTime就是一個時間戳減一個停頓後的時間戳,其實可以設置為一個隨機數
function getPrelt() { exectime = Math.floor(Math.random() * (20 ‐ 300 + 1) + 300) return exectime }
0x02 代碼編寫
1.獲取nonce、rsakv等參數
import json import re import requests import execjs session = requests.session() prelogin_url = 'https://login.sina.com.cn/sso/prelogin.php' login_url = 'https://login.sina.com.cn/sso/login.php' username = 'username' password = 'password' with open('login.js','r',encoding='utf‐8') as f: login_js = execjs.compile(f.read()) su = login_js.call('getSu',username) params = { 'entry': 'weibo', 'callback': 'sinaSSOController.preloginCallBack', 'su': su, 'rsakt': 'mod', 'checkpin': '1', 'client': 'ssologin.js(v1.4.19)', '_': '1578127327125', } prelogin_resp = requests.get(prelogin_url,params=params) result = re.search(r'sinaSSOController.preloginCallBack\((.*?)\)',prelogin_resp.text).group(1) result_json = json.loads(result) print(result_json)

2.獲取跳轉鏈接
data = { 'entry': 'weibo', 'gateway': '1', 'from':'', 'savestate': '7', 'qrcode_flag': 'false', 'useticket': '1', 'pagerefer': '', 'vsnf': '1', 'su': su, 'service': 'miniblog', 'servertime': result_json['servertime'], 'nonce': result_json['nonce'], 'pwencode': 'rsa2', 'rsakv': result_json['rsakv'], 'sp': login_js.call('getSp',result_json,self.password), 'sr': '1920*1080', 'encoding': 'UTF‐8', 'prelt': login_js.call('getPrelt'), 'url': 'https://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack', 'returntype': 'META', } resp = session.post(login_url,data=data) print(resp.text)

3.獲取跳轉鏈接
location = re.search(r'replace\("(.*?)"\);',resp.text).group(1) resp = session.get(location) print(resp.text)

4.最後請求
location = re.search(r'replace\(\'(.*?)\'\);', resp.text).group(1) resp = self.session.get(location) print(resp.text)
5.登陸驗證
到此為止已經是成功登陸了,最後再請求一下主頁,如果返回的源代碼中有自己的用戶名,那麼說明我們已經登陸成功了
#Python學習群592539176 resp = self.session.get('https://weibo.com/') print(resp.text)
