T03 · Remote Payload Retrieval and Execution
- Location
sitemd/install.js:158- Finding
Unverified Remote Native Binary Download and Execution
- Content
View full analysis
{ const follow = (u) => { https.get(u, { headers: { 'User-Agent': 'sitemd-install' } }, res => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { return follow(res.headers.location) } if (res.statusCode !== 200) { return reject(new Error(`Download failed: HTTP ${res.statusCode} ${u}`)) } const file = fs.createWriteStream(dest) res.pipe(file) file.on('finish', () => { file.close(); resolve() }) file.on('error', reject) }).on('error', reject) } follow(url) }) } ``` ```js const archive = `sitemd-${wanted}-${platform}-${arch}${ext}` const url = `${GITHUB_RELEASE_URL}/v${wanted}/${archive}` const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sitemd-install-')) const archivePath = path.join(tmpDir, archive) const extractDir = path.join(tmpDir, 'extracted') try { console.log(` sitemd: downloading v${wanted} (${platform}-${arch})...`) await download(url, archivePath) fs.mkdirSync(extractDir, { recursive: true }) if (ext === '.zip') { // Windows 10 1803+ ships tar.exe which handles zip files execFileSync('tar', ['-xf', archivePath, '-C', extractDir], { stdio: 'ignore' }) } else { execFileSync('tar', ['-xzf', archivePath, '-C', extractDir], { stdio: 'ignore' }) } ``` ```js const extractedBinary = path.join(sourceRoot, archiveBinaryName) if (!fs.existsSync(extractedBinary)) { throw new Error(`Binary not found in archive: ${ ...[truncated 5178 chars]- Remediation
View remediation
