/* ------------------------------------------------------------------------- * 项目名称:快手极速版(NEBULA · 签到 / 宝箱 / 任务卡) * 脚本文件:ks_nebula_daily.js * 更新说明: * 2026-11-22 Mist 仓库首发:签到 + 开宝箱 + 任务卡领奖 + 51 任务上报,纯 HTTP 零依赖 * ------------------------------------------------------------------------- * Author : Mist * 声明 : 仅供个人学习与技术研究,仅用于自己有权操作的账号,风险自负 * ------------------------------------------------------------------------- * cron "5 8,12,18,21 * * *" ks_nebula_daily.js * new Env('快手极速版(主站金币)'); */ 'use strict'; const https = require('https'); const http = require('http'); const zlib = require('zlib'); const { URL } = require('url'); // ============================================================================ // 一、配置 // ============================================================================ const ENV_CK = 'ks_ck'; // 必需:Cookie 整串,多账号换行 const ENV_CK_ALT = 'KS_CK'; // 同名大写容错 const ENV_ACCOUNT = 'ks_account'; // 选填:手机号#密码(仅记录,密码登录已被风控封死) const ENV_DELAY = 'ks_delay'; // 账号间隔,形如 5-15 const ENV_PUSH = 'ks_push'; // on/off const ENV_TY_PUSH = 'TYpush'; // 与有赞脚本共用的总开关 const ENV_BOX_WAIT = 'ks_box_wait'; // on/off:是否等冷却连开宝箱 const ENV_BOX_MAX = 'ks_box_max'; // 单次最多开几个宝箱 const ENV_DEBUG = 'ks_debug'; // on/off:打印原始响应 const ENV_MODE = 'ks_mode'; // full/light:light 跳过 60 个任务的点击上报 const ENV_SIG_GW = 'ks_sig_gw'; // 选填:sig3 签名网关地址(真机 Frida 桥),例如 http://127.0.0.1:8899 const ENV_SIG_GW_TIMEOUT = 'ks_sig_gw_timeout'; // 选填:网关超时秒,默认 10 /** 网关主机(H5 容器) */ const HOST_NEBULA = 'https://nebula.kuaishou.com'; const HOST_ENCOURAGE = 'https://encourage.kuaishou.com'; /** 任务中心来源标识,抓包里就是这几个 */ const SOURCE = 'cash'; // ---- __NS_sig3 签名参数(还原自 nebula 主包 chunks/main-*.js)------------ /** 签名协议版本,真实前端固定为 1 */ const SIG_CAT_VER = 1; /** 参与签名的 Cookie 字段白名单(其余一律不进签名串) */ const SIG_COOKIE_KEYS = [ 'kpn', 'kpf', 'userId', 'did', 'c', 'appver', 'language', 'mod', 'did_tag', 'egid', 'oDid', 'androidApiLevel', 'newOc', 'browseType', 'socName', 'ftt', 'abi', 'userRecoBit', 'device_abi', 'grant_browse_type', 'iuid', 'rdid', ]; /** 默认 UA:照抄抓包里 ksNebula 的 WebView UA,别改 */ const UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 ' + '(KHTML, like Gecko) Mobile/15E148 ksNebula/14.9.21.4453 ISLP/0 KDT/PHONE ' + 'NetType/WIFI locale/zh-Hans WebViewType/WK'; /** 返回码 */ const R = { OK: 1, NET: 2, NO_PARAM: 11, SIG_FAIL: 50, SIGNED_TODAY: 102006, NO_MORE_REWARD: 90107, }; /** 宝箱冷却上限(服务端一般给 300s,留点余量) */ const BOX_COOLDOWN_MAX = 600; /** 宝箱两次开之间最小间隔 */ const BOX_MIN_GAP = 3; /** 单个宝箱最多重试等几轮,防死循环 */ const BOX_WAIT_ROUNDS = 40; // ============================================================================ // 二、小工具 // ============================================================================ const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const rand = (a, b) => Math.floor(Math.random() * (b - a + 1)) + a; const line = (n) => '─'.repeat(n); const now = () => { const d = new Date(Date.now() + 8 * 3600e3); return d.toISOString().replace('T', ' ').slice(0, 19); }; function env(name, dflt) { const v = process.env[name]; return v === undefined || v === '' ? dflt : String(v).trim(); } /** * 运行模式:full / light * * 青龙上要跑两个条目,共用同一个脚本文件,靠命令行参数区分: * task ks_nebula_daily.js → full (每天首轮,做 60 个任务的点击上报) * task ks_nebula_daily.js light → light (白天高频,只领取,不发点击上报) * * 优先级:命令行参数 > 环境变量 ks_mode > 默认 full */ function runMode() { const arg = String((process.argv || []).slice(2).join(' ') || '').toLowerCase(); if (/\blight\b/.test(arg)) return 'light'; if (/\bfull\b/.test(arg)) return 'full'; return /^light$/i.test(env(ENV_MODE, 'full')) ? 'light' : 'full'; } function on(name) { return /^(on|1|true|yes|开)$/i.test(env(name, '')); } function clip(s, n) { s = String(s == null ? '' : s); return s.length > n ? s.slice(0, n) + '…' : s; } /** 去掉接口文案里的 之类标签 */ function plain(s) { return String(s == null ? '' : s).replace(/<[^>]+>/g, ''); } // ============================================================================ // 三、HTTP(零依赖,自带 br/gzip/deflate 解压 + 重定向) // ============================================================================ // 二、__NS_sig3 签名引擎(本次逆向的核心突破) // ============================================================================ // // 快手 2025 年把 H5 赚钱页的写操作全部加上了 __NS_sig3 签名,未签名的请求一律返回 // {"result":50,"error_msg":"签名验证失败!"} // 一开始以为这是 native 算法(libksxgs.so),实际上它就在 nebula 赚钱页的 JS chunk 里: // // chunks_main-*.js 内嵌了一个 js-interpreter 沙箱(函数 tm), // 沙箱里跑的是编译成字节码的 Jose 模块,对外暴露唯一方法 $encode(input) -> sig3 // // 调用点是: // function ki(e){ return new Promise((t,n)=>{ xi.call("$encode",[e,{suc:t,err:n}]) }) } // // 两套签名模式(实测确认): // 模式 A(ztReportTask / ztExpandReportTask): // sig3 = $encode( JSON.stringify(body) ) // URL → ?__NS_sig3= // 适用于 /rest/wd/zt/task/report、/rest/wd/ug/encourage/task/report、 // /rest/wd/usergrowth/encourage/matrix/resource/action // 模式 B(axios 拦截器 rI,带 sigCatVer): // sig3 = $encode( 排序拼接(sigCatVer + Cookie白名单 + query) + JSON.stringify(body) ) // URL → ?__NS_sig3=&sigCatVer=1 // // 本脚本内置的是模式 A 的沙箱本体(从官方 chunk 原样抠出来的 23KB,非重新实现), // 所以算法与服务端完全一致,不需要还原 $encode 内部的盐/摘要。 // // 注意:沙箱里带时间因子,同一个输入每次结果不同,但服务端都能验过 —— 不要做缓存。 // /** 沙箱里的 $encode 实现本体(原样搬运,勿改) */ function tm(e){(function(n,o){n.Jose=o()})(e,function(){return o={},t.m=n=[function(s,r){(function(){var a=function(d){return d.constructor.prototype},u=Object.create,i=function(d,p){return Object.prototype.hasOwnProperty.call(d,p)},c=Array.isArray,l=function(d,p,v){return Object.defineProperty(d,p,v)};r.prototypeOf=a,r.create=u,r.hasProp=i,r.isArray=c,r.defProp=l}).call(this)},function(s,r){(function(){function a(u){this.elements=u,this.index=0}a.prototype.next=function(){if(this.index>=this.elements.length)throw new Error("array over");return this.elements[this.index++]},r.ArrayIterator=a}).call(this)},function(s,r,a){function u(i){return(u=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(l){return typeof l}:function(l){return l&&typeof Symbol=="function"&&l.constructor===Symbol&&l!==Symbol.prototype?"symbol":typeof l})(i)}(function(){var i={}.hasOwnProperty,c=a(0).isArray,l=(f.prototype.run=function(){for(var E=this.callStack[this.depth],I=E.error;0<=this.depth&&E&&!this.paused;)if((E=I?this.unwind(I):E).run(),(I=E.error)instanceof Error&&this.injectStackTrace(I),E.done()){if(E.guards.length){var R=E.guards.pop();if(R.finalizer){E.ip=R.finalizer,E.exitIp=R.end,E.paused=!1;continue}}!E.construct||(R=u(this.rv))!=="object"&&R!=="function"&&(this.rv=E.scope.get(0)),(E=this.popFrame())&&!I&&(E.evalStack.push(this.rv),this.rv=void 0)}else I=(E=this.callStack[this.depth]).error;if(this.timedOut()&&(I=new Error(this),this.injectStackTrace(I)),I)throw I},f.prototype.unwind=function(E){for(var I=this.callStack[this.depth];I;){I.error=E;var R=I.ip-1,N=I.guards.length;if(N&&(N=I.guards[N-1],N.start<=R&&R<=N.end)){if(N.handler!==null)if(R<=N.handler)I.evalStack.push(E),I.error=null,I.ip=N.handler;else{if(!(N.finalizer&&I.ip<=N.finalizer)){I=this.popFrame();continue}I.ip=N.finalizer}else I.ip=N.finalizer;return I.paused=!1,I}I=this.popFrame()}throw E},f.prototype.injectStackTrace=function(E){var I,R,N,M,x,m,g,S=[],D=0;for(this.depth>this.maxTraceDepth&&(D=this.depth-this.maxTraceDepth),R=N=x=this.depth,m=D;x<=m?N<=m:m<=N;R=x<=m?++N:--N)(M=(I=this.callStack[R]).script.name)===""&&I.fname&&(M=I.fname),S.push({at:{name:M,filename:I.script.filename},line:I.line,column:I.column});if(E.trace){for(g=E.trace;c(g[g.length-1]);)g=g[g.length-1];g.push(S)}else E.trace=S;return E.stack=E.toString()},f.prototype.pushFrame=function(E,I,R,N,M,x,m){if(x==null&&(x=""),m==null&&(m=!1),this.checkCallStack())return R=new A(R,E.localNames,E.localLength),R.set(0,I),m=new d(this,E,R,this.realm,x,m),M&&m.evalStack.push(M),N&&m.evalStack.push(N),this.callStack[++this.depth]=m},f.prototype.checkCallStack=function(){return this.depth!==this.maxDepth||(this.callStack[this.depth].error=new Error("maximum call stack size exceeded"),this.pause(),!1)},f.prototype.popFrame=function(){var E=this.callStack[--this.depth];return E&&(E.paused=!1),E},f.prototype.pause=function(){return this.paused=this.callStack[this.depth].paused=!0},f.prototype.resume=function(E){if(this.timeout=E!=null?E:-1,this.paused=!1,this.callStack[this.depth].paused=!1,this.run(),!this.paused)return this.rexp},f.prototype.timedOut=function(){return this.timeout===0},f.prototype.send=function(E){return this.callStack[this.depth].evalStack.push(E)},f.prototype.done=function(){return this.depth===-1},f);function f(E,I){this.realm=E,this.timeout=I!=null?I:-1,this.maxDepth=1e3,this.maxTraceDepth=50,this.callStack=[],this.evalStack=null,this.depth=-1,this.yielded=this.rv=void 0,this.paused=!1,this.r1=this.r2=this.r3=null,this.rexp=null}var d=(p.prototype.run=function(){for(var E=this.script.instructions;this.ip!==this.exitIp&&!this.paused&&this.fiber.timeout!==0;)this.fiber.timeout--,E[this.ip++].exec(this,this.evalStack,this.scope,this.realm);this.fiber.timeout===0&&(this.paused=this.fiber.paused=!0);var I=this.evalStack.len();if(!this.paused&&!this.error&&I!==0)throw new Error("Evaluation stack has "+I+" items after execution")},p.prototype.done=function(){return this.ip===this.exitIp},p.prototype.setLine=function(E){this.line=E},p.prototype.setColumn=function(E){this.column=E},p);function p(E,I,R,N,M,x){this.fiber=E,this.script=I,this.scope=R,this.realm=N,this.fname=M,this.construct=x!=null&&x,this.evalStack=new v(this.script.stackSize,this.fiber),this.ip=0,this.exitIp=this.script.instructions.length,this.paused=!1,this.finalizer=null,this.guards=[],this.rv=void 0,this.line=this.column=-1}var v=(_.prototype.push=function(E){if(this.idx===this.array.length)throw new Error("maximum evaluation stack size exceeded");return this.array[this.idx++]=E},_.prototype.pop=function(){return this.array[--this.idx]},_.prototype.top=function(){return this.array[this.idx-1]},_.prototype.len=function(){return this.idx},_.prototype.clear=function(){return this.idx=0},_);function _(E,I){this.fiber=I,this.array=new Array(E),this.idx=0}var A=(w.prototype.get=function(E){return this.data[E]},w.prototype.set=function(E,I){return this.data[E]=I},w.prototype.name=function(E){var I,R=this.names;for(I in R)if(i.call(R,I)&&R[I]===E)return parseInt(I);return-1},w);function w(E,I,R){this.parent=E,this.names=I,this.data=new Array(R)}var P=(b.prototype.get=function(E){return this.object[E]},b.prototype.set=function(E,I){return this.object[E]=I},b.prototype.has=function(E){return E in this.object},b);function b(E,I){this.parent=E,this.object=I}r.Fiber=l,r.Scope=A,r.WithScope=P}).call(this)},function(s,r,a){a=new(a(4)),a.eval('["