// Check if user is logged in if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit(); }
// Check if session is expired if (time() > $_SESSION['expires']) { header("Location: logout.php"); exit(); }
// Display user ID on landing page echo"Welcome, User ID: " . urlencode($_SESSION['user_id']);
// Get the user for admin $db = newPDO('sqlite:memory:'); $admin = $db->query('SELECT * FROM users WHERE user_id = 0 LIMIT 1')->fetch();
// Check if the user is admin if ($admin['user_id'] === $_SESSION['user_id']) { // Read the flag from flag.txt $flag = file_get_contents('flag.txt'); echo"<h1>Flag</h1>"; echo"<p>$flag</p>"; } else { // Display the source code for this file echo"<h1>Source Code</h1>"; highlight_file(__FILE__); }
db.get('SELECT * FROM users WHERE username = "' + username + '" and password = "' + password+ '"', (err, row) => { if (err) { console.error(err); res.status(500).send('Error retrieving user'); } else { if (row) { req.session.loggedIn = true; req.session.username = username; res.send('Login successful!'); } else { res.status(401).send('Invalid username or password'); } } });
检测了username
1 2 3 4 5 6 7 8 9 10
app.get('/flag', (req, res) => { if (req.session.username == "admin") { res.send('Welcome admin. The flag is ' + fs.readFileSync('flag.txt', 'utf8')); } elseif (req.session.loggedIn) { res.status(401).send('You must be admin to get the flag.'); } else { res.status(401).send('Unauthorized. Please login first.'); } });