|
| 1 | +<?php |
| 2 | +define("USERNAME", "DRodgers"); |
| 3 | +define("FLAG", "jctf{b3_CAR3fu1_wh@t_yOU_put_on_the_WEB}"); |
| 4 | +$questions = [ |
| 5 | + "q1" => [ |
| 6 | + "q" => "What was your first job's company name?", |
| 7 | + "a" => "Bank Heist Security 101" |
| 8 | + ], |
| 9 | + "q2" => [ |
| 10 | + "q" => "What city was your high school located in?", |
| 11 | + "a" => "Rahway", |
| 12 | + ], |
| 13 | + "q3" => [ |
| 14 | + "q" => "What is your favorite sport?", |
| 15 | + "a" => "Arm wrestling" |
| 16 | + ] |
| 17 | +]; |
| 18 | + |
| 19 | +function showFirstForm() |
| 20 | +{ |
| 21 | +?> |
| 22 | + <form action="" method="post"> |
| 23 | + <label>Username |
| 24 | + <input type="text" name="username"> |
| 25 | + </label> |
| 26 | + <input type="submit" value="Continue" name="submit"> |
| 27 | + </form> |
| 28 | +<?php |
| 29 | +} |
| 30 | + |
| 31 | +function showSecondForm() |
| 32 | +{ |
| 33 | + global $questions; |
| 34 | +?> |
| 35 | + <h2>Security Questions</h2> |
| 36 | + <form action="" method="post"> |
| 37 | + <?php |
| 38 | + foreach ($questions as $question_id => $question) { ?> |
| 39 | + <label><?php echo $question["q"]; ?> |
| 40 | + <input type="text" name="<?php echo $question_id; ?>"> |
| 41 | + </label> |
| 42 | + <br> |
| 43 | + <?php } ?> |
| 44 | + <input type="submit" value="Reset Password" name="submit"> |
| 45 | + </form> |
| 46 | +<?php |
| 47 | +} |
| 48 | + |
| 49 | +function scriptAlert($msg) |
| 50 | +{ |
| 51 | +?> |
| 52 | + <script> |
| 53 | + alert("<?php echo $msg; ?>"); |
| 54 | + </script> |
| 55 | + <noscript> |
| 56 | + <p> |
| 57 | + <?php echo $msg; ?> |
| 58 | + </p> |
| 59 | + </noscript> |
| 60 | +<?php |
| 61 | +} |
| 62 | +?> |
| 63 | +<!DOCTYPE html> |
| 64 | +<html lang="en"> |
| 65 | + |
| 66 | +<head> |
| 67 | + <meta charset="UTF-8"> |
| 68 | + <title>Forgot Password</title> |
| 69 | +</head> |
| 70 | + |
| 71 | +<body> |
| 72 | + <h1>Forgot Password</h1> |
| 73 | + |
| 74 | + <?php |
| 75 | + if (isset($_POST["submit"])) { |
| 76 | + // 1st "public" layer of form |
| 77 | + if (isset($_POST["username"])) { |
| 78 | + if ($_POST["username"] === USERNAME) { |
| 79 | + showSecondForm(); |
| 80 | + } else if ($_POST["username"] === "Wolverine") { |
| 81 | + showFirstForm(); |
| 82 | + scriptAlert("Nice try! Find another user."); |
| 83 | + } else { |
| 84 | + showFirstForm(); |
| 85 | + } |
| 86 | + } |
| 87 | + // 2nd form is "secret", know by checking the form input names |
| 88 | + else if (count(array_intersect_key($questions, $_POST)) === count($questions)) { |
| 89 | + $missed_question = null; |
| 90 | + foreach ($questions as $question_id => $question) { |
| 91 | + if ($_POST[$question_id] !== $question["a"]) { |
| 92 | + $missed_question = $question; |
| 93 | + break; |
| 94 | + } |
| 95 | + } |
| 96 | + if ($missed_question === null) { |
| 97 | + showFirstForm(); |
| 98 | + scriptAlert(FLAG); |
| 99 | + } else { |
| 100 | + showSecondForm(); |
| 101 | + scriptAlert("Incorrect Answer(s)"); |
| 102 | + } |
| 103 | + } |
| 104 | + } else { |
| 105 | + showFirstForm(); |
| 106 | + } ?> |
| 107 | +</body> |
| 108 | + |
| 109 | +</html> |
0 commit comments