Guest User

Untitled

a guest
Jun 14th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.97 KB | None | 0 0
  1. <?php
  2.  
  3.     if (isset($_GET['source'])) {
  4.         highlight_file(__FILE__);
  5.         exit;
  6.     }
  7.  
  8.     // Settings
  9.     ini_set('display_errors', 1);
  10.     ini_set('display_startup_errors', 1);
  11.     error_reporting(E_ALL);
  12.     date_default_timezone_set('Asia/Taipei');
  13.     session_start();
  14.  
  15.     // CSRF
  16.     if (!isset($_SESSION['csrf_key']))
  17.         $_SESSION['csrf_key'] = md5(rand() * rand());
  18.     require_once('csrf.php');
  19.     $csrf = new Csrf($_SESSION['csrf_key']);
  20.  
  21.  
  22.     if ($action = @$_GET['action']) {
  23.         function redirect($path = '/', $message = null) {
  24.             $alert = $message ? 'alert(' . json_encode($message) . ')' : '';
  25.             $path = json_encode($path);
  26.             die("<script>$alert; document.location.replace($path);</script>");
  27.         }
  28.  
  29.         if ($action === 'logout') {
  30.             unset($_SESSION['user']);
  31.             redirect('/');
  32.         }
  33.         else if ($action === 'login') {
  34.             // Validate CSRF token
  35.             $token = @$_POST['csrf_token'];
  36.             if (!$token || !$csrf->validate($token)) {
  37.                 redirect('/', 'invalid csrf_token');
  38.             }
  39.  
  40.             // Check if username and password are given
  41.             $username = @$_POST['username'];
  42.             $password = @$_POST['password'];
  43.             if (!$username || !$password) {
  44.                 redirect('/', 'username and password should not be empty');
  45.             }
  46.  
  47.             // Get rid of sqlmap kiddies
  48.             if (stripos($_SERVER['HTTP_USER_AGENT'], 'sqlmap') !== false) {
  49.                 redirect('/', "sqlmap is child's play");
  50.             }
  51.  
  52.             // Get rid of you
  53.             $bad = [' ', '/*', '*/', 'select', 'union', 'or', 'and', 'where', 'from', '--'];
  54.             $username = str_ireplace($bad, '', $username);
  55.             $username = str_ireplace($bad, '', $username);
  56.  
  57.             // Auth
  58.             $hash = md5($password);
  59.             $row = (new SQLite3('/db.sqlite3'))
  60.                 ->querySingle("SELECT * FROM users WHERE username = '$username' AND password = '$hash'", true);
  61.             if (!$row) {
  62.                 redirect('/', 'login failed');
  63.             }
  64.  
  65.             $_SESSION['user'] = $row['username'];
  66.             redirect('/');
  67.         }
  68.         else {
  69.             redirect('/', "unknown action: $action");
  70.         }
  71.     }
  72.  
  73.     $user = @$_SESSION['user'];
  74.  
  75. ?><!DOCTYPE html>
  76. <head>
  77.     <title>🦉🦉🦉🦉</title>
  78.     <meta charset='utf-8'>
  79.     <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
  80.     <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
  81.     <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  82. </head>
  83. <body>
  84.     <?php if (!$user): ?>
  85.         <div id="login">
  86.             <h3 class="text-center text-white pt-5">GUESS THE STUPID USERNAME / PASSWORD</h3>
  87.             <div class="container">
  88.                 <div id="login-row" class="row justify-content-center align-items-center">
  89.                     <div id="login-column" class="col-md-6">
  90.                         <div id="login-box" class="col-md-12">
  91.                             <form id="login-form" class="form" action="?action=login" method="post">
  92.                                 <input type="hidden" name="csrf_token" value="<?= htmlentities($csrf->generate()) ?>">
  93.                                 <h3 class="text-center text-info">🦉: "Login to see cool things!"</h3>
  94.                                 <div class="form-group">
  95.                                     <label for="name" class="text-info">Username:</label><br>
  96.                                     <input type="text" name="username" id="username" class="form-control"><br>
  97.                                     <label for="name" class="text-info">Password:</label><br>
  98.                                     <input type="text" name="password" id="password" class="form-control"><br>
  99.                                 </div>
  100.                                 <div class="form-group">
  101.                                     <input type="submit" name="submit" class="btn btn-info btn-md" value="Login">
  102.                                 </div>
  103.                             </form>
  104.                         </div>
  105.                     </div>
  106.                 </div>
  107.             </div>
  108.         </div>
  109.     <?php else: ?>
  110.         <h3 class="text-center text-white pt-5"><a style="color: white" href="/?source">SHOW HINT</a></h3>
  111.         <div class="container">
  112.             <div class="row justify-content-center align-items-center">
  113.                 <div class="col-md-6">
  114.                     <div class="col-md-12">
  115.                         <h3 class="text-center text-info">Nothing</h3>
  116.                         Hello, <b><?= htmlentities($user) ?></b>, nothing here.
  117.                         <a href="?action=logout">Logout!</a>
  118.                     </div>
  119.                 </div>
  120.             </div>
  121.         </div>
  122.     <?php endif ?>
  123. </body>
Add Comment
Please, Sign In to add comment