T03 · Remote Payload Retrieval and Execution
- Location
scripts/install.js:33- Finding
Unverified Remote Native Binary Is Downloaded and Executed
- Content
View full analysis
{ const client = url.startsWith("https") ? https : require("http"); client .get(url, (res) => { if (res.statusCode === 302 || res.statusCode === 301) { return download(res.headers.location, destPath).then(resolve, reject); } if (res.statusCode !== 200) { return reject( new Error(`Download failed with status ${res.statusCode}: ${url}`), ); } const file = fs.createWriteStream(destPath); res.pipe(file); file.on("finish", () => { file.close(); resolve(); }); }) .on("error", reject); }); } async function install() { const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "browsectl-")); const archivePath = path.join(tmpDir, archiveName); try { await download(url, archivePath); if (isWindows) { execSync( `powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`, { stdio: "ignore" }, ); } else { execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: "ignore", }); } const binaryName = NAME + (isWindows ? ".exe" : ""); const extractedBinary = path.join(tmpDir, binaryName); fs.copyFileSync(extractedBinary, dest); fs.chmodSync(dest, 0o755); console.log(`${NAME} v${VERSION} installed successfully`); } finally { ...[truncated 2852 chars]- Remediation
View remediation
