source code
<?php
include "../../config.php";
if($_GET['view_source']) view_source();
?>
<html>
<head>
<title>Challenge 26</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
a { color:lightgreen; }
</style>
</head>
<body>
<?php
if(preg_match("/admin/",$_GET['id'])) { echo"no!"; exit(); }
$_GET['id'] = urldecode($_GET['id']);
if($_GET['id'] == "admin"){
solve(26);
}
?>
<br><br>
<a href=?view_source=1>view-source</a>
</body>
</html>
이 부분을 주목하자.
if(preg_match("/admin/",$_GET['id'])) { echo"no!"; exit(); }
$_GET['id'] = urldecode($_GET['id']);
if($_GET['id'] == "admin"){
solve(26);
}
get 방식으로 id값으로 admin을 받으면 문제가 풀린다.
하지만 preg_match에 의해 admin문자열이 id값에 존재하면 "no!"를 출력한다.
*preg_match
난 단순히 문자열 비교로 이해했다.(이게 아닐지도 모른다...)
https://www.php.net/manual/en/function.preg-match.php
PHP: preg_match - Manual
This is a function that uses regular expressions to match against the various VAT formats required across the EU.
그러면 admin을 직접 입력할 수 없으면 어떻게 해야 할까? 그때 이용해야 할 것이 urldecode다. url이 %HEX방식으로 인코딩되므로 인코딩된 값을 넣어주면 디코딩 되어 admin을 출력되게하면 되는 것이다. 여기서 문제가 하나 생긴다.
이미 url에서는 원래 url 디코딩 과정을 거쳐서 진행된다. 하지만 소스코드에서 디코딩 과정을 1번 더 거치므로 우리는 총2번의 인코딩 과정을 가진 admin을 get방식으로 admin을 id값으로 넣어줘야 한다.
*urldecode
Warning
The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.
https://www.php.net/manual/en/function.urldecode.php
PHP: urldecode - Manual
www.php.net
2번의 인코딩 과정을 설명하면 다음과 같다.
2nd에서 %가 25가 되는 이유는 아스키코드표를 살펴보면 알 수 있다.
1st | 2nd | |
a | %61 | %2561 |
d | %64 | %2564 |
m | %6d | %256d |
i | %69 | %2569 |
n | %6e | %256e |
최종 코드는 다음과 같다.
?id=%2561%2564%256d%2569%256e
이 코드를 url에 입력하면 해결!!
'Wargame 풀이 > webhacking.kr (웹해킹)' 카테고리의 다른 글
old-12 (0) | 2020.11.08 |
---|---|
old -27 (0) | 2020.10.11 |
old - 16 (0) | 2020.08.16 |
old - 6 (0) | 2020.08.16 |
old - 19 (0) | 2020.08.14 |