cyberoot

test

Jun 27th, 2024 (edited)
175
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2. require 'vendor/autoload.php';
  3.  
  4. $client = new MongoDB\Client("mongodb://localhost:27017");
  5. $collection = $client->testdb->users;
  6.  
  7. // Function vulnerable to JavaScript injection via $where
  8. function findUserWhere($collection, $username, $password) {
  9. $filter = [
  10. '$where' => "this.username == '$username' && this.password == '$password'"
  11. ];
  12. return $collection->findOne($filter);
  13. }
  14.  
  15. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  16. $username = $_POST['username'];
  17. $password = $_POST['password'];
  18.  
  19. // Vulnerable query using $where
  20. $userWhere = findUserWhere($collection, $username, $password);
  21. if ($userWhere) {
  22. echo "Welcome, " . htmlspecialchars($userWhere['username']) . "<br>";
  23. } else {
  24. echo "Invalid credentials<br>";
  25. }
  26. }
  27. ?>
  28.  
  29. <!DOCTYPE html>
  30. <html lang="en">
  31. <head>
  32. <meta charset="UTF-8">
  33. <title>NoSQL Injection Lab - $where Operator</title>
  34. </head>
  35. <body>
  36. <h1>NoSQL Injection Lab - $where Operator</h1>
  37. <form method="POST" action="">
  38. <label for="username">Username:</label>
  39. <input type="text" id="username" name="username"><br>
  40. <label for="password">Password:</label>
  41. <input type="password" id="password" name="password"><br>
  42. <button type="submit">Login</button>
  43. </form>
  44. </body>
  45. </html>
  46.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment