Advertisement
h4212421

type_juggling.php

Dec 7th, 2016
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.88 KB | None | 0 0
  1. <?php
  2.  
  3. echo '
  4.    <form action="type_juggling.php" class="authform" method="POST" accept-charset="utf-8">
  5.        <fieldset>
  6.            <legend>Authentication</legend>
  7.            <input type="text" id="username" name="username" value="" placeholder="Your username" />
  8.            <input type="password" id="password" name="password" value="" placeholder="Your password" />
  9.            <input type="submit" name="submit" value="Authenticate" />
  10.        </fieldset>
  11.    <br>
  12.    <p class=return_value> </p>
  13.    <br>
  14.    <a target="_blank" href="https://www.owasp.org/images/6/6b/PHPMagicTricks-TypeJuggling.pdf"> <b> Hint... </b> </a>
  15.    ';
  16.  
  17.  
  18.  
  19. echo '<script src="http://challenge01.root-me.org/web-serveur/ch44/jquery-2.2.1.min.js" type="text/javascript">
  20.    </script>
  21.    <script type="text/javascript">
  22.        $("document").ready(function(){
  23.            $(".authform").submit(function(){
  24.                $(".return-value").html("&nbsp;");
  25.  
  26.                var data = {username: $("#username").val(), password: $("#password").val()};
  27.                $.ajax({
  28.                    type: "POST",
  29.                    dataType: "json",
  30.                    url: "type_juggling.php",
  31.                    data: {auth : JSON.stringify({data})},
  32.                    success: function(data) {
  33.                        $(".return_value").html(
  34.                            "Result: " + data["status"]
  35.                        );
  36.                    }
  37.                });
  38.                return false;
  39.            });
  40.        });
  41.    </script>
  42.    ';
  43.  
  44. ?>
  45.  
  46.  
  47. <?php
  48. //declare
  49. $USER='admin';
  50. $USERNAME='admin';
  51. $PASSWORD="F098cdrrJFERrgseijIJ";
  52. $PASSWORD_SHA256=0x5eed8a5d0fec8763a28f90c5ccf4dbcdd4b3f07792a2091666322558c01d9607;
  53. $FLAG='flag{secret_flag}';
  54.  
  55.  
  56. //execute
  57. $return['status'] = 'Authentication failed!';
  58. echo "<br>";
  59. //use jquery
  60. if (isset($_POST["auth"]))  {
  61.     // retrieve JSON data
  62.     echo $_POST["auth"] . "<br>";
  63.     echo "auth...<br>";
  64.     $auth = @json_decode($_POST['auth'], true);
  65.     // check login and password (sha256)
  66.     if($auth['data']['username'] == $USER && !strcmp($auth['data']['password'], $PASSWORD)){
  67.         $return['status'] = "Access granted! The validation password is: $FLAG";
  68.     }
  69.     echo '<br>' . htmlentities($return['status']) . '<br>';
  70. }
  71.  
  72. //not use jquery
  73. if (isset($_POST["username"]) && isset($_POST["password"]))  {
  74.  
  75.     echo "login...<br>";
  76.     $auth['data']['username'] = $_POST['username'];
  77.     $auth['data']['password'] = $_POST['password'];
  78.  
  79.     $auth = @json_decode('{"data":{"username":"admin","password":{}}}',true);
  80.  
  81.     // check username and password (sha256)
  82.     if($auth['data']['username'] == $USERNAME && !strcmp($auth['data']['password'], $PASSWORD)){
  83.         $return['status'] = "Access granted! The validation password is: $FLAG";
  84.     }
  85.     echo '<br>' . htmlentities($return['status']) . '<br>';
  86. }
  87.  
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement