// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 2023-12-18 // @description try to take over the world! // @author You // @match https://www.kugou.com/yy/rank/home/1-8888.html?from=rank // @icon https://www.google.com/s2/favicons?sz=64&domain=kugou.com // @grant none // ==/UserScript==
function SekiroClient(wsURL) { this.wsURL = wsURL; this.handlers = {}; this.socket = {}; // check if (!wsURL) { throw new Error('wsURL can not be empty!!') } this.webSocketFactory = this.resolveWebSocketFactory(); this.connect() }
SekiroClient.prototype.resolveWebSocketFactory = function () { if (typeof window === 'object') { var theWebSocket = window.WebSocket ? window.WebSocket : window.MozWebSocket; return function (wsURL) {
function WindowWebSocketWrapper(wsURL) { this.mSocket = new theWebSocket(wsURL); }
WindowWebSocketWrapper.prototype.close = function () { this.mSocket.close(); };
WindowWebSocketWrapper.prototype.onmessage = function (onMessageFunction) { this.mSocket.onmessage = onMessageFunction; };
WindowWebSocketWrapper.prototype.onopen = function (onOpenFunction) { this.mSocket.onopen = onOpenFunction; }; WindowWebSocketWrapper.prototype.onclose = function (onCloseFunction) { this.mSocket.onclose = onCloseFunction; };
WindowWebSocketWrapper.prototype.send = function (message) { this.mSocket.send(message); };
return new WindowWebSocketWrapper(wsURL); } } if (typeof weex === 'object') { // this is weex env : https://weex.apache.org/zh/docs/modules/websockets.html try { console.log("test webSocket for weex"); var ws = weex.requireModule('webSocket'); console.log("find webSocket for weex:" + ws); return function (wsURL) { try { ws.close(); } catch (e) { } ws.WebSocket(wsURL, ''); return ws; } } catch (e) { console.log(e); //ignore } } //TODO support ReactNative if (typeof WebSocket === 'object') { return function (wsURL) { return new theWebSocket(wsURL); } } // weex 鍜� PC鐜鐨剋ebsocket API涓嶅畬鍏ㄤ竴鑷达紝鎵€浠ュ仛浜嗘娊璞″吋瀹� throw new Error("the js environment do not support websocket"); };
SekiroClient.prototype.connect = function () { console.log('sekiro: begin of connect to wsURL: ' + this.wsURL); var _this = this; // 涓峜heck close锛岃 // if (this.socket && this.socket.readyState === 1) { // this.socket.close(); // } try { this.socket = this.webSocketFactory(this.wsURL); } catch (e) { console.log("sekiro: create connection failed,reconnect after 2s"); setTimeout(function () { _this.connect() }, 2000) }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script src="http://file.virjar.com/sekiro_web_client.js?_=123"></script> <script> function b64(arg) { return btoa(arg) } // 生成唯一标记uuid编号 function guid() { function S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); } return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); } // 连接服务端 var client = new SekiroClient("ws://127.0.0.1:5612/business-demo/register?group=ws-group&clientId="+guid()); // 业务接口 client.registerAction("demo",function(request, resolve, reject){ data = request['page'] console.log(data,'记号') resolve("我是Forever"+new Date()); }) client.registerAction("demo1",function(request, resolve, reject){ data = request['pwd'] res = b64(data) resolve(res); }) </script> </body> </html>
接收注入的结果
以python为例
sekiro支持多种语言可根据需要使用。
1 2 3 4 5 6 7 8
import requests data = {"group": "ws-group", "action": "demo", "page": 10 } res = requests.get("http://127.0.0.1:5610/business-demo/invoke",params=data ) print(res.text)
线上注入
找到需要注入的js文件进行本地覆盖保存。
将上面的脚本文件在文件中写入
在原函数的调用处进行要hook的函数回调
1 2 3 4 5 6
client.registerAction("demo",function(request, resolve, reject){ var data = request['page'] console.log(data,'记号') var value = d(data) resolve("kugou: "+value); });