0
点赞
收藏
分享

微信扫一扫

JsRpc实战-猿人学-反混淆刷题平台第20题(wasm)

爱情锦囊 2022-02-25 阅读 92

前言

现在网站的反爬越来越多了,很多网站的请求都有加密参数,这个时候就需要去逆向,但是逆向耗时耗力,有时候由于当前水平问题一时半会儿还破解不了,头发掉了一大把,还没有任何成果,头大哦。今天给大家分享一个不需要做任何逆向就能拿到网页请求的加密参数,直接拿到数据的方法,对,没错,就是标题中说的Jsrpc,话不多说,直接开始。


基本介绍

jsRpc:在网站的控制台新建一个WebScoket客户端链接到服务器通信,调用服务器的接口 服务器会发送信息给客户端客户端接收到要执行的方法执行完js代码后把获得想要的内容发回给服务器 服务器接收到后再显示出来

项目地址

https://github.com/jxhczhl/JsRpc#jsrpc-hliang

使用方法

提示:为了让大家能详细了解,建议大家完整的看看整个项目介绍

本次我们只需要用到两个文件内容,一个是resouces里的js代码,另一个是作者编译好的文件,点击releases直接跳转到对应页面。
在这里插入图片描述
在这里插入图片描述
根据自己的系统下载即可,我是windows版本的,所以下载的是圈起来的这个。

resouces中js代码如下:

function Hlclient(wsURL) {
    this.wsURL = wsURL;
    this.handlers = {};
    this.socket = {};

    if (!wsURL) {
        throw new Error('wsURL can not be empty!!')
    }
    this.connect()
}

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) {
            console.log("send func", e.data);
            _this.handlerRequest(e.data);
        }
    } 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)
    }

};
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;

}
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
}
    action=result["action"]
    var theHandler = this.handlers[action];
    if (!theHandler ||theHandler==undefined){
	    this.sendResult(action,'action not found');
	    return
    }
    try {
		if (!result["param"]){
			theHandler(function (response) {
				_this.sendResult(action, response);
			})
		}else{
			theHandler(function (response) {
				_this.sendResult(action, response);
			},result["param"])
		}
		
    } catch (e) {
        console.log("error: " + e);
        _this.sendResult(action+e);
    }
}

Hlclient.prototype.sendResult = function (action, e) {
    this.send(action + atob("aGxeX14") + e);
}

到这里需要用到的东西已经准备好了,接下来就开始去实操一下。

本次实操链接:猿人学-反混淆刷题平台第20题(wasm)

第一步:老规矩F12,点击下一页,出现请求,根据请求直接跳转到请求的位置,如下图所示:
在这里插入图片描述
在这里插入图片描述
直接就能看到发起请求携带的参数,今天的我们的目的不是破解,而是直接去拿这个生成的参数。这里我们先在自己的项目文件中创建一个js文件然后将下面的代码复制进去(提示:因为根据作者的js代码,对返回的结果不太友好,所以这里稍微做了改动)

function Hlclient(wsURL) {
    this.wsURL = wsURL;
    this.handlers = {};
    this.socket = {};

    if (!wsURL) {
        throw new Error('wsURL can not be empty!!')
    }
    this.connect()
}

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) {
            console.log("send func", e.data);
            _this.handlerRequest(e.data);
        }
    } 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)
    }

};
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 this;

}
Hlclient.prototype.handlerRequest = function (requestJson) {
    var _this = this;
    var result = JSON.parse(requestJson);
    if (!result['action']) {
        this.sendResult('', 'need request param {action}');
        return
    }
    action = result["action"]
    var theHandler = this.handlers[action];
    if (!theHandler || theHandler == undefined) {
        this.sendResult(action, 'action not found');
        return
    }
    try {
        if (!result["param"]) {
            theHandler(function (response) {
                _this.sendResult(action, response);
            })
        } else {
            theHandler(function (response) {
                _this.sendResult(action, response);
            }, result["param"])
        }

    } catch (e) {
        console.log("error: " + e);
        _this.sendResult(action + e);
    }
}

Hlclient.prototype.sendResult = function (action, response) {
    var responseJson;
    if (typeof response == 'string') {
        try {
            responseJson = JSON.parse(response);
        } catch (e) {
            responseJson = {};
            responseJson['data'] = response;
        }
    } else if (typeof response == 'object') {
        responseJson = response;
    } else {
        responseJson = {};
        responseJson['data'] = response;
    }
    if (Array.isArray(responseJson)) {
        responseJson = {
            data: responseJson,
            code: 0
        }
    }

    if (responseJson['code']) {
        responseJson['code'] = 0;
    } else if (responseJson['status']) {
        responseJson['status'] = 0;
    } else {
        responseJson['status'] = 0;
    }
    var responseText = JSON.stringify(responseJson);
    this.send(action + atob("aGxeX14") + responseText);
}

在这里插入图片描述
上图是连接通信的代码,这里我们需要将请求位置的代码复制过来(前面红圈圈起来的部分),操作完之后如下:
在这里插入图片描述
之后将上图中的代码也复制到自己创建的js文件中,js完整代码如下:

function Hlclient(wsURL) {
    this.wsURL = wsURL;
    this.handlers = {};
    this.socket = {};

    if (!wsURL) {
        throw new Error('wsURL can not be empty!!')
    }
    this.connect()
}

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) {
            console.log("send func", e.data);
            _this.handlerRequest(e.data);
        }
    } 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)
    }

};
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 this;

}
Hlclient.prototype.handlerRequest = function (requestJson) {
    var _this = this;
    var result = JSON.parse(requestJson);
    if (!result['action']) {
        this.sendResult('', 'need request param {action}');
        return
    }
    action = result["action"]
    var theHandler = this.handlers[action];
    if (!theHandler || theHandler == undefined) {
        this.sendResult(action, 'action not found');
        return
    }
    try {
        if (!result["param"]) {
            theHandler(function (response) {
                _this.sendResult(action, response);
            })
        } else {
            theHandler(function (response) {
                _this.sendResult(action, response);
            }, result["param"])
        }

    } catch (e) {
        console.log("error: " + e);
        _this.sendResult(action + e);
    }
}

Hlclient.prototype.sendResult = function (action, response) {
    var responseJson;
    if (typeof response == 'string') {
        try {
            responseJson = JSON.parse(response);
        } catch (e) {
            responseJson = {};
            responseJson['data'] = response;
        }
    } else if (typeof response == 'object') {
        responseJson = response;
    } else {
        responseJson = {};
        responseJson['data'] = response;
    }
    if (Array.isArray(responseJson)) {
        responseJson = {
            data: responseJson,
            code: 0
        }
    }

    if (responseJson['code']) {
        responseJson['code'] = 0;
    } else if (responseJson['status']) {
        responseJson['status'] = 0;
    } else {
        responseJson['status'] = 0;
    }
    var responseText = JSON.stringify(responseJson);
    this.send(action + atob("aGxeX14") + responseText);
}

// 连接通信
var client = new Hlclient("ws://127.0.0.1:12080/ws?group=match20&name=yuanrenxue");
// 第二个参数为函数,resolve里面的值是想要的值(发送到服务器的)
// param是可传参参数,可以忽略
client.regAction("ShiGuang", function (resolve, param) {
    t = Date.parse(new Date());
    var list = {
        "page": String(param),
        "sign": window.sign(String(param) + '|' + t.toString()),
        "t": t,
    }
    resolve(list)
})

做完这些js注入的代码已经全部完成,之后打开之前下载好的文件

在这里插入图片描述
在这里插入图片描述
接下来就是注入js代码,自己创建的js文件中的代码全部复制到console面板中,如下图所示:
在这里插入图片描述
注入完成,之后我们写一个demo来获取下参数
在这里插入图片描述
直接成功拿到加密参数,为了验证我们拿到的参数是否正确,我们用这个参数来获取下数据。
在这里插入图片描述
成功拿到每一页的数据,到这里整个实操过程完成,有没有觉得很简单,是不是很惊讶,我们竟然没有做任何逆向就能拿到加密参数,就能拿到数据,这就是JsRpc的强大之处。

这里不建议大家在做题的时候使用这种方式,做题不是为了单纯的拿到结果,而是为了在做题的过程中学习到知识,所以不要为了单纯的完成题目而使用这种方式。

举报

相关推荐

0 条评论