javascript
【JS 逆向百例】37网游登录接口参数逆向
文章目錄
- 聲明
- 逆向目標(biāo)
- 逆向過程
- 抓包分析
- 參數(shù)逆向
- 完整代碼
- 37_encrypt.js
- 37_login.py
聲明
本文章中所有內(nèi)容僅供學(xué)習(xí)交流,嚴(yán)禁用于商業(yè)用途和非法用途,否則由此產(chǎn)生的一切后果均與作者無關(guān),若有侵權(quán),請聯(lián)系我立即刪除!
逆向目標(biāo)
-
目標(biāo):37網(wǎng)游登錄
-
主頁:https://www.37.com/
-
接口:https://my.37.com/api/login.php
-
逆向參數(shù):
Query String Parameters:password: SlVEOThrcjgzNDNjaUYxOTQzNDM0eVM=
逆向過程
抓包分析
隨便輸入一個賬號密碼,點(diǎn)擊登陸,抓包定位到登錄接口為 https://my.37.com/api/login.php ,GET 請求,分析一下 Query String Parameters 里的主要參數(shù):
callback 是一個回調(diào)參數(shù),這個參數(shù)的值不影響請求結(jié)果,它的格式為 jQuery + 20位數(shù)字 + _ + 13位時間戳,使用 Python 很容易構(gòu)建;
login_account 是登錄的賬戶名;
password 是加密后的密碼;
_ 是13位時間戳。
參數(shù)逆向
需要我們逆向的參數(shù)就只有一個 password, 我們嘗試直接全局搜索此關(guān)鍵字,會發(fā)現(xiàn)出來的結(jié)果非常多,不利于分析,這里就有一個小技巧,加個等號,搜索 password=,這樣就極大地縮短了查找范圍,當(dāng)然也可以搜索 password:,也可以在關(guān)鍵字和符號之間加個空格,還可以搜索 var password 等,這些都是可以嘗試的,要具體情況具體分析,一種沒有結(jié)果就換另一種。
在本案例中,我們搜索 password=,在 sq.login2015.js 文件里可以看到語句 h.password = td(f),疑似密碼加密的地方,在此處埋下斷點(diǎn)進(jìn)行調(diào)試,可以看到返回的值確實(shí)是加密后的密碼:
繼續(xù)跟進(jìn) td 函數(shù),可以看到是用到了一個自寫的 RSA 加密,很簡單明了,我們直接將其復(fù)制下來使用 Python 調(diào)用即可:
完整代碼
GitHub 關(guān)注 K 哥爬蟲,持續(xù)分享爬蟲相關(guān)代碼!歡迎 star !
本案例完整代碼:https://github.com/kuaidaili/crawler/tree/main/www_37_com
37_encrypt.js
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"))37_login.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*-import time import randomimport execjs import requestslogin_url = 'https://my.37.com/api/login.php'def get_encrypted_password(password):with open('37_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()總結(jié)
以上是生活随笔為你收集整理的【JS 逆向百例】37网游登录接口参数逆向的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: REVERSE-COMPETITION-
- 下一篇: 【JS 逆向百例】复杂的登录过程,最新微