點擊「Python編程與實戰」,選擇「置頂公衆號」node
第一時間獲取 Python 技術乾貨!git
![](http://static.javashuo.com/static/loading.gif)
今天給你們來分析並還原某驗的 JS 加密,作過爬蟲的應該都知道遇到過這個驗證碼,若是你還沒遇到之後你會碰到的相信我github
話很少說,時間寶貴,進入正題!web
抓包
進入官網,點擊選擇今天的主題滑動驗證,其餘驗證類型的加密大同小異,只要你掌握了下面的方法!編程
![](http://static.javashuo.com/static/loading.gif)
點擊按鈕抓包,隨意拖動一下,請求數據包以下數組
![](http://static.javashuo.com/static/loading.gif)
能夠看到一堆請求參數,其實你要作的就是實現 w 的加密瀏覽器
![](http://static.javashuo.com/static/loading.gif)
點擊進去,就能看到加密的 JS 文件,爲便於分析將其保存到本地。微信
AST 還原
經過調試能夠看到有大量的 unicode 格式的編碼以及數組名稱的混淆babel
![](http://static.javashuo.com/static/loading.gif)
傳統解決方法是在瀏覽器 console 端輸入就能看到它的廬山真面目,可是這種方法太麻煩了,接下來咱們用 AST 來將其還原!app
首先還原 unicode 編碼,打開 AST 在線解析網站(https://blogz.gitee.io/ast/[1])
將待還原的代碼放進去
![](http://static.javashuo.com/static/loading.gif)
能夠看到只須要把 extra 屬性刪掉就能還原原來的值。遍歷代碼以下:
const parser = require("@babel/parser");
const traverse = require("@babel/traverse").default;
const t = require("@babel/types"); //操做節點的函數,好比判斷節點類型,生成新的節點等:
const generator = require("@babel/generator").default; //生成還原後的代碼
const fs = require('fs');
var jscode = fs.readFileSync("./slide.js", {
encoding: "utf-8"
});
const visitor = {
StringLiteral(path) {
delete path.node.extra
}
}
let ast = parser.parse(jscode);
traverse(ast, visitor);
let {code} = generator(ast, opts = {jsescOption: {"minimal": true}});
fs.writeFile('decode_slide.js', code, (err)=>{});
注意 jscode 就是以前扣下來的 JS 代碼, 最後將還原後的代碼寫入到 decode_slide.js 文件中
接下來是混淆數組的還原。觀察調試代碼,全部的數組都是基於 JS 文件中開頭的大數組 KBBji.$_Co,同時將該數組賦值給不少變量,這些變量名都是隨機生成的。
因此接下來咱們要作的找出這些變量名稱,而後將其替換成對應的字符串值!
AST 在線解析一下
![](http://static.javashuo.com/static/loading.gif)
根據解析結果,編寫相應的遍歷代碼
const visitor = {
VariableDeclaration(path){
const {declarations} = path.node;
if(!t.isMemberExpression(declarations[0].init))return;
if(declarations[0].init.property.name !== "$_Co")return;
if(declarations.length !==3 || declarations[0].init.property === undefined)return;
let value1 = declarations[0].id.name;
let value2 = declarations[2].id.name;
new_array.push(value1, value2);
}
};
上面就將全部的變量名找出來了,找到以後就能將全部的這種形式 $_DFCB(66) 代碼還原了,這樣代碼就能有個直觀感覺!
![](http://static.javashuo.com/static/loading.gif)
相信聰明的你很快就能寫出還原的代碼。通過上面幾步總體還原後的代碼是這樣的
![](http://static.javashuo.com/static/loading.gif)
根據關鍵詞很快就能搜索到加密所在位置,清晰可見!若是不還原你是搜不到的.. 還原後在網站上咱們也能很快定位到加密位置,打上斷點
![](http://static.javashuo.com/static/loading.gif)
一樣的代碼可讀性相差多大,相信你一眼就能看到。你覺得這樣就完了?No!
Reres 替換
既然代碼已經還原了,可是咱們在網站上調試的時候仍是混淆的代碼,那怎麼辦呢?
接下來上另外一個神器 Reres, 它的做用是將請求映射到本地,即你能夠用本地 JS 來代替遠程 JS 文件。
用法直接參考它的 github https://github.com/annnhan/ReRes[2]
好了有了這個東西,咱們就能在網站上用還原後的 JS 來進行調試,太強了把!
效果以下:
![](http://static.javashuo.com/static/loading.gif)
tql,這下加密參數扣起來就沒壓力了吧!
後臺回覆 tql 獲取相關代碼!
參考資料
https://blogz.gitee.io/ast/: https://blogz.gitee.io/ast/
[2]https://github.com/annnhan/ReRes: https://github.com/annnhan/ReRes
推薦閱讀
THANKS
- End -
點個「在看」必升職加薪喔!
本文分享自微信公衆號 - Python編程與實戰(GoPy1024)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。