You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Laura just found a website used for monitoring security mechanisms on Rhiza's state and is planning to hack into it to forge the status of these security services. After that she will desactivate these security resources without alerting government agents. Your goal is to get into the server to change the monitoring service behavior.
Source code:
constexpress=require('express')constbodyParser=require('body-parser')constjsonpatch=require('fast-json-patch')constejs=require('ejs')constbasicAuth=require('express-basic-auth')constapp=express()// Middlewares //app.use(bodyParser.json())app.use(basicAuth({users: {"admin": process.env.SECRET||"admin"},challenge: true}))/////////////////letservices={status: "online",cameras: "online",doors: "online",dome: "online",turrets: "online"}// Static folderapp.use("/static",express.static(__dirname+"/static"));// Homepageapp.get("/",async(req,res)=>{consthtml=awaitejs.renderFile(__dirname+"/templates/index.ejs",{services})res.end(html)})// APIapp.post("/change_status",(req,res)=>{letpatch=[]Object.entries(req.body).forEach(([service,status])=>{if(service==="status"){res.status(400).end("Cannot change all services status")return}patch.push({"op": "replace","path": "/"+service,"value": status})});jsonpatch.applyPatch(services,patch)if("offline"inObject.values(services)){services.status="offline"}res.json(services)})app.listen(1337,()=>{console.log(`App listening at port 1337`)})
Writeup
There are two lines caught my eyes immediately: jsonpatch.applyPatch(services, patch) and ejs.renderFile(__dirname + "/templates/index.ejs", {services}).
From my experience, jsonpatch might have prototype pollution vulnerability. After googling a bit I found this open PR: Starcounter-Jack/JSON-Patch#262 and confirm that prototype pollution exists.
But what can we do with this? I googled: prototype pollution ejs ctf and found this useful article: From Prototype Pollution to RCE
We can use outputFunctionName to do RCE.
So just post this to /change_status and that's all, solved the challenge by googling!:
Illusion
Description
Laura just found a website used for monitoring security mechanisms on Rhiza's state and is planning to hack into it to forge the status of these security services. After that she will desactivate these security resources without alerting government agents. Your goal is to get into the server to change the monitoring service behavior.
Source code:
Writeup
There are two lines caught my eyes immediately:
jsonpatch.applyPatch(services, patch)
andejs.renderFile(__dirname + "/templates/index.ejs", {services})
.From my experience,
jsonpatch
might have prototype pollution vulnerability. After googling a bit I found this open PR: Starcounter-Jack/JSON-Patch#262 and confirm that prototype pollution exists.But what can we do with this? I googled:
prototype pollution ejs ctf
and found this useful article: From Prototype Pollution to RCEWe can use
outputFunctionName
to do RCE.So just post this to
/change_status
and that's all, solved the challenge by googling!:The text was updated successfully, but these errors were encountered: