爬虫+RPC+js逆向---直接获取加密值

免责声明:本文仅做技术交流与学习,请勿用于其它违法行为;如果造成不便,请及时联系...

目录

爬虫+RPC+js逆向---直接获取加密值

target网址:

抓包

下断点

找到加密函数

分析参数

RPC流程

一坨:

二坨:

运行py,拿到加密值


爬虫+RPC+js逆向---直接获取加密值


target网址:

优志愿_2024高考志愿填报系统-新高考志愿填报选科指南

数据往下滑,发现是异步加载数据.

抓包

找到XHR,都清空,刷新一下.

这里返回了几个包,我们单个看一下他返回(响应)的数据,发现其中一个包的响应就是我们想要的数据.

复制代码
"/youzy.dms.basiclib.api.college.query"
#这个包里就是我们想要的数据.

--分析这些数据包,发现这个参数U-Sign每次都在变.(不简单)

--所以我们直接关键字搜索,U-Sign

找到关键字加密的位置,

下断点

刷新

--断住了

找到加密函数

这里我们看一下整个o函数,发现o函数出来就是个加密值了.

分析参数

--接着看里面的参数, e.url

发现就是我们要获取数据的接口的url(对照着右面的值看)

这里的 e.data 是一个定值,那我们直接在控制台copy一下就行.

--这样就是复制成功了.

复制代码
{
    "keyword": "",
    "provinceNames": [],
    "natureTypes": [],
    "eduLevel": "",
    "categories": [],
    "features": [],
    "pageIndex": 1,
    "pageSize": 20,
    "sort": 11
}
#这就是第二个参数的值.

RPC流程

打开工具RPC

先断点

控制台赋值 --给加密函数赋值.

取消(禁用)断点--跑完

最后甩那两坨.(第二坨注意要改值.)

运行py代码.

一坨:

javascript 复制代码
function Hlclient(wsURL) {
    this.wsURL = wsURL;
    this.handlers = {
        _execjs: function (resolve, param) {
            var res = eval(param)
            if (!res) {
                resolve("没有返回值")
            } else {
                resolve(res)
            }
​
        }
    };
    this.socket = {};
    if (!wsURL) {
        throw new Error('wsURL can not be empty!!')
    }
    this.connect()
    this.socket["ySocket"].addEventListener('close', (event) => {
        console.log('rpc已关闭');
    });
}
​
Hlclient.prototype.connect = function () {
    console.log('begin of connect to wsURL: ' + this.wsURL);
    var _this = this;
    try {
        this.socket["ySocket"] = new WebSocket(this.wsURL);
        this.socket["ySocket"].onmessage = function (e) {
            try {
                let blob = e.data
                blob.text().then(data => {
                    _this.handlerRequest(data);
                })
            } catch {
                console.log("not blob")
                _this.handlerRequest(blob)
            }
​
        }
    } catch (e) {
        console.log("connection failed,reconnect after 10s");
        setTimeout(function () {
            _this.connect()
        }, 10000)
    }
    this.socket["ySocket"].onclose = function () {
        console.log("connection failed,reconnect after 10s");
        setTimeout(function () {
            _this.connect()
        }, 10000)
    }
    this.socket["ySocket"].addEventListener('open', (event) => {
        console.log("rpc连接成功");
    });
    this.socket["ySocket"].addEventListener('error', (event) => {
        console.error('rpc连接出错,请检查是否打开服务端:', event.error);
    });
​
};
Hlclient.prototype.send = function (msg) {
    this.socket["ySocket"].send(msg)
}
​
Hlclient.prototype.regAction = function (func_name, func) {
    if (typeof func_name !== 'string') {
        throw new Error("an func_name must be string");
    }
    if (typeof func !== 'function') {
        throw new Error("must be function");
    }
    console.log("register func_name: " + func_name);
    this.handlers[func_name] = func;
    return true
​
}
​
//收到消息后这里处理,
Hlclient.prototype.handlerRequest = function (requestJson) {
    var _this = this;
    var result = JSON.parse(requestJson);
    //console.log(result)
    if (!result['action']) {
        this.sendResult('', 'need request param {action}');
        return
    }
    var action = result["action"]
    var theHandler = this.handlers[action];
    if (!theHandler) {
        this.sendResult(action, 'action not found');
        return
    }
    try {
        if (!result["param"]) {
            theHandler(function (response) {
                _this.sendResult(action, response);
            })
        } else {
            var param = result["param"]
            try {
                param = JSON.parse(param)
            } catch (e) {
                console.log("")
            }
            theHandler(function (response) {
                _this.sendResult(action, response);
            }, param)
        }
​
    } catch (e) {
        console.log("error: " + e);
        _this.sendResult(action , e);
    }
}
​
Hlclient.prototype.sendResult = function (action, e) {
    this.send(action + atob("aGxeX14") + e);
}
demo = new Hlclient("ws://127.0.0.1:12080/ws?group=o&name=sign");

--rpc连接成功.

二坨:

javascript 复制代码
demo.regAction("get_sign", function (resolve,param) {
    //这里还是param参数 param里面的key 是先这里写,但到时候传接口就必须对应的上
    //注意这里的接口要和py里面的接口一致.   函数名称.
    res=o(param["url"],param["data"])
    resolve(res);
})

--true

运行py,拿到加密值

注意: 最后这里写爬虫获取数据时,浏览器不能刷新.
RPC那个工具在github上直接搜进行了...

RPC是什么?

http://t.csdnimg.cn/3FcRJ

相关推荐
前端大白话几秒前
前端必看!90% 工程师踩过的状态管理坑,useReducer 如何一招化解?
前端·javascript·react.js
前端大白话几秒前
揭秘 HTML 可拖动元素及拖放功能:HTML5 API 大起底
前端·javascript·html
灏瀚星空2 分钟前
从基础到实战的量化交易全流程学习:1.3 数学与统计学基础——概率与统计基础 | 基础概念
笔记·python·学习·金融·概率论
一夜沐白7 分钟前
Linux用户管理
linux·运维·服务器·笔记
Hellohistory7 分钟前
HOTP 算法与实现解析
后端·python
伊织code9 分钟前
cached-property - 类属性缓存装饰器
python·缓存·cache·装饰器·ttl·property·cached-property
Moment18 分钟前
通过爬取 B 站热门视频来带你彻底了解 Playwright 🤷🏿‍♂️🤷🏿‍♂️🤷🏿‍♂️
前端·javascript·后端
明明跟你说过25 分钟前
深度学习常见框架:TensorFlow 与 PyTorch 简介与对比
人工智能·pytorch·python·深度学习·自然语言处理·tensorflow
搏博27 分钟前
专家系统的基本概念解析——基于《人工智能原理与方法》的深度拓展
人工智能·python·深度学习·算法·机器学习·概率论
yzx99101327 分钟前
决策树随机深林
人工智能·python·算法·决策树·机器学习