衡陽的房地產(chǎn)網(wǎng)站建設(shè)打開百度搜索網(wǎng)站
前言
嗨嘍~大家好呀,這里是魔王吶 ? ~!
目錄標(biāo)題
- 前言
- 開發(fā)環(huán)境:
- 模塊使用:
- 逆向目標(biāo)
- 逆向過程
- 參數(shù) JS 加密關(guān)鍵代碼
- Python 登錄關(guān)鍵代碼
- 尾語 💝
開發(fā)環(huán)境:
-
Python 3.8
-
Pycharm
模塊使用:
-
time >>> 時(shí)間模塊,屬于內(nèi)置,無需安裝
-
re >>> 用于生成隨機(jī)數(shù),屬于內(nèi)置,無需安裝
-
requests >>> 主要用來發(fā) 送 HTTP 請求,屬于內(nèi)置,無需安裝
-
execjs >>> 用來在python中運(yùn)行js代碼的庫,第三方,需要安裝
第三方模塊安裝:
win + R 輸入cmd 輸入安裝命令 或 在pycharm中點(diǎn)擊Terminal(終端) 輸入安裝命令
如果出現(xiàn)爆紅, 可能是因?yàn)?網(wǎng)絡(luò)連接超時(shí), 可切換國內(nèi)鏡像源,命令如下:
pip install -i https://pypi.doubanio.com/simple/ requests
逆向目標(biāo)
目標(biāo):某 7 網(wǎng)游登錄
主頁:aHR0cHM6Ly93d3cuMzcuY29tLw==
接口:aHR0cHM6Ly9teS4zNy5jb20vYXBpL2xvZ2luLnBocA==
逆向參數(shù):Query String Parameters:password: SlVEOThrcjgzNDNjaUYxOTQzNDM0eVM=
逆向過程
抓包分析
來到某 7 網(wǎng)游首頁,隨便輸入一個(gè)賬號密碼,點(diǎn)擊登陸,
抓包定位到登錄接口為 aHR0cHM6Ly9teS4zNy5jb20vYXBpL2xvZ2luLnBocA== ,GET 請求:
分析一下 Query String Parameters 里的主要參數(shù):
callback 是一個(gè)回調(diào)參數(shù),這個(gè)參數(shù)的值不影響請求結(jié)果,它的格式為 jQuery + 20位數(shù)字 + _ + 13位時(shí)間戳,使用 Python 很容易構(gòu)建:
import time
import randomtimestamp = str(int(time.time() * 1000))
jsonp = ''
for _ in range(20):jsonp += str(random.randint(0, 9))
callback = 'jQuery' + jsonp + '_' + timestamp
print(callback)
login_account 是登錄的賬戶名;
password 是加密后的密碼;
_ 是13位時(shí)間戳。
參數(shù)逆向
需要我們逆向的參數(shù)就只有一個(gè) password,
我們嘗試直接全局搜索此關(guān)鍵字,會(huì)發(fā)現(xiàn)出來的結(jié)果非常多,不利于分析,
這里就有一個(gè)小技巧,加個(gè)等號,搜索 password=,這樣就極大地縮短了查找范圍,當(dāng)然也可以搜索 password:,
也可以在關(guān)鍵字和符號之間加個(gè)空格,還可以搜索 var password 等,這些都是可以嘗試的,要具體情況具體分析,一種沒有結(jié)果就換另一種。
在本案例中,我們搜索 password=,在 sq.login2015.js 文件里可以看到語句 h.password = td(f),
疑似密碼加密的地方,在此處埋下斷點(diǎn)進(jìn)行調(diào)試,可以看到返回的值確實(shí)是加密后的密碼:
繼續(xù)跟進(jìn) td 函數(shù),可以看到是用到了一個(gè)自寫的 RSA 加密,很簡單明了,我們直接將其復(fù)制下來使用 Python 調(diào)用即可:
完整代碼直接文末名片自取即可
參數(shù) JS 加密關(guān)鍵代碼
var ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function __rsa(str) {var out, i, len;var c1, c2, c3;len = str.length;i = 0;out = "";while (i < len) {c1 = str.charCodeAt(i++) & 0xff;if (i == len) {out += ch.charAt(c1 >> 2);out += ch.charAt((c1 & 0x3) << 4);out += "==";break}c2 = str.charCodeAt(i++);if (i == len) {out += ch.charAt(c1 >> 2);out += ch.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));out += ch.charAt((c2 & 0xF) << 2);out += "=";break}c3 = str.charCodeAt(i++);out += ch.charAt(c1 >> 2);out += ch.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));out += ch.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));out += ch.charAt(c3 & 0x3F)}return out
}function getEncryptedPassword(a) {var maxPos = ch.length - 2, w = [];for (i = 0; i < 15; i++) {w.push(ch.charAt(Math.floor(Math.random() * maxPos)));if (i === 7) {w.push(a.substr(0, 3))}if (i === 12) {w.push(a.substr(3))}}return __rsa(w.join(""))
}// 測試樣例
// console.log(getEncryptedPassword("34343434"))
Python 登錄關(guān)鍵代碼
#!/usr/bin/env python3
# -*- coding: utf-8 -*-import time
import randomimport execjs
import requestslogin_url = '脫敏處理,完整代碼領(lǐng)取V:Pytho8987'def get_encrypted_password(password):with open('encrypt.js', 'r', encoding='utf-8') as f:www_37_js = f.read()encrypted_pwd = execjs.compile(www_37_js).call('getEncryptedPassword', password)return encrypted_pwddef login(username, encrypted_password):timestamp = str(int(time.time() * 1000))jsonp = ''for _ in range(20):jsonp += str(random.randint(0, 9))callback = 'jQuery' + jsonp + '_' + timestampparams = {'callback': callback,'action': 'login','login_account': username,'password': encrypted_password,'ajax': 0,'remember_me': 1,'save_state': 1,'ltype': 1,'tj_from': 100,'s': 1,'tj_way': 1,'_': timestamp}headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36','sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"'}response = requests.post(url=login_url, headers=headers, params=params)print(response.text)def main():username = input('請輸入登錄賬號: ')password = input('請輸入登錄密碼: ')encrypted_password = get_encrypted_password(password)login(username, encrypted_password)if __name__ == '__main__':main()
尾語 💝
要成功,先發(fā)瘋,下定決心往前沖!
學(xué)習(xí)是需要長期堅(jiān)持的,一步一個(gè)腳印地走向未來!
未來的你一定會(huì)感謝今天學(xué)習(xí)的你。
—— 心靈雞湯
本文章到這里就結(jié)束啦~感興趣的小伙伴可以復(fù)制代碼去試試哦 😝