https://webhacking.kr/challenge/web-11/
문제 페이지에서 view-source 링크 누르면 아래와 같이 소스코드 출력
< 코드 분석 >
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?php
if(preg_match("/admin/",$_GET['id'])) { echo"no!"; exit(); }
# preg_match("/비교 기준값/",입력값); 이므로,
# id 파라미터로 받아 온 값이 admin이면 no! 출력 후 프로그램 종료 -> 여기서 걸리면 안됨
$_GET['id'] = urldecode($_GET['id']);
# id를 받아서 urldecode 함수 처리 후 id에 넣어줌
if($_GET['id'] == "admin"){
solve(26);
}
# 만약 id 값이 admin과 같으면 solve -> 문제 해결
?>
|
cs |
그럼 id값이 admin이 아닌데, urldecode 함수를 통해 admin으로 인식 되어야 문제가 해결되는 것
=> id값에 admin을 encoding 해서 넣으면 decoding 됐을 때 admin이 되지 않을까?
< 문제 풀이>
1st TRY) 안될 것 알지만 일단 확인 위해 admin 넣어보기 -> 실패
2nd TRY) admin을 인코딩해서 넣어보기 -> 실패
3rd TRY) admin을 두 번 인코딩해서 넣어보기
한번 인코딩하면 자동으로 디코딩되는 것으로 확인되었으니, 한번 더 인코딩해서 총 두번 인코딩하면
자동 디코팅 -> urldecode 함수로 디코딩 되어 첫번째 if문에 걸리지 않고 urldecode 되어 두번째 if문 조건을 충족하고 문제를 풀 수 있다
admin --url encoding-->
%61%64%6D%69%6E --url encoding-->
%2561%2564%256D%2569%256E
알파벳 인코딩 표 -> https://www.w3schools.com/tags/ref_urlencode.ASP
자동 인코딩 사이트 -> https://www.convertstring.com/ko/EncodeDecode/UrlEncode
참고자료(PHP preg_match, urldecode 공식 doc)...
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. <!--?php function checkVatNumber( $country, $vat_number ) { switch($country) { case 'Austria': $regex = '/
www.php.net
https://www.php.net/manual/en/function.urldecode.php
PHP: urldecode - Manual
This seems to decode correctly between most browsers and charater coding configurations. Specially indicated for direct parsing of URL as it comes on environment variables:function crossUrlDecode($source) { $decodedStr = ''; $pos = 0; $len =
www.php.net
preg_match 함수 우회, urlencode와 urldecode에 대해 이해하고 있으면 풀 수 있는 문제였다.
php에 대해 거의 모르는 수준이라 문제 풀면서 얼른 공부해봐야겠다.
'해킹 공부 > 웹 해킹' 카테고리의 다른 글
Dreamhack_image-storage(파일 업로드 공격) (0) | 2022.02.13 |
---|---|
Dreamhack_command-injection-1 (0) | 2022.02.13 |
Dreamhack_csrf-1(CSRF 취약점) (0) | 2022.02.05 |
Dreamhack_csrf-2(CSRF 취약점) (0) | 2022.02.05 |
dreamhack xss-2(XSS 방화벽 우회) (0) | 2022.01.30 |