ở trên mình đã trigger xss thành công, nhưng để fetch được tới nguồn khác thì không thể bởi chỉ thị default-src không cho phép mình làm như vậy, nên ở đây ta sử dụng document.location để chuyển hướng trang, vì ta đã có thể control được code js cần thực thi nên hướng này là khả thi
ta có serect thì việc cuối cùng chỉ cần curl tới cái path secret này ta sẽ có flag
**Missing Flavortext
constcrypto=require('crypto');constdb=require('better-sqlite3')('db.sqlite3')// remake the `users` tabledb.exec(`DROP TABLE IF EXISTS users;`);db.exec(`CREATE TABLE users( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, password TEXT);`);// add an admin user with a random passworddb.exec(`INSERT INTO users (username, password) VALUES ( 'admin', '${crypto.randomBytes(16).toString('hex')}')`);constexpress=require('express');constbodyParser=require('body-parser');constapp=express();// parse json and serve static filesapp.use(bodyParser.urlencoded({ extended:true }));app.use(express.static('static'));// login routeapp.post('/login', (req, res) => {if (!req.body.username ||!req.body.password) {returnres.redirect('/'); }if ([req.body.username,req.body.password].some(v =>v.includes('\''))) {returnres.redirect('/'); }// see if user is in databaseconstquery=`SELECT id FROM users WHERE username = '${req.body.username}' AND password = '${req.body.password}' `;let id;try { id =db.prepare(query).get()?.id } catch {returnres.redirect('/'); }// correct loginif (id) returnres.sendFile('flag.html', { root: __dirname });// incorrect loginreturnres.redirect('/');});app.listen(3000);
đề cung cấp source như sau, ta thấy có 1 table users, và nếu login thành công thì sẽ có flag