목표 : 코드 우회 및 쿠키 변조
접속한 IP와 user agent를 보여준다.
바로 코드를 보자
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 24</title>
</head>
<body>
<p>
<?php
extract($_SERVER);
extract($_COOKIE);
$ip = $REMOTE_ADDR;
$agent = $HTTP_USER_AGENT;
if($REMOTE_ADDR){
$ip = htmlspecialchars($REMOTE_ADDR);
$ip = str_replace("..",".",$ip);
$ip = str_replace("12","",$ip);
$ip = str_replace("7.","",$ip);
$ip = str_replace("0.","",$ip);
}
if($HTTP_USER_AGENT){
$agent=htmlspecialchars($HTTP_USER_AGENT);
}
echo "<table border=1><tr><td>client ip</td><td>{$ip}</td></tr><tr><td>agent</td><td>{$agent}</td></tr></table>";
if($ip=="127.0.0.1"){
solve(24);
exit();
}
else{
echo "<hr><center>Wrong IP!</center>";
}
?><hr>
<a href=?view_source=1>view-source</a>
</body>
</html>
PHP
복사
ip값이 127.0.0.1이 되면 풀린다
..은 .으로
12 7. 0. 은 공백으로 바꾼다
extract($_SERVER);
extract($_COOKIE);
PHP
복사
서버에 있는 값들을 변수화 시킨다음, 쿠키에 있는 값들을 변수화 시킨다
즉 서버에서 받아온 $REMOTE_ADDR를 쿠키에 똑같은 변수 명이 있으면 덮어씌울 수 있다.
•
112277.. . 00 .. . 00 .. . 1
•
112277..00..00..1
•
127.0.0.1
112277...00...00...1
쿠키를 다음과 같이 새로 만들고 새로고침하면 끝