저장소

[webhacking.kr] 26번 풀이 본문

IT/웹 해킹

[webhacking.kr] 26번 풀이

huiu 2021. 8. 30. 12:06

https://webhacking.kr/

 

Webhacking.kr

Index Welcome Stranger! Chatting Notice(en) [2021-04-16] Score of old challenges has been adjusted to 1/10. For a while now, new challenges will be added "without" notice. [2020-08-12] Replace chat feature with Discord. Please do not cause inconvenience to

webhacking.kr

26번은 php 문제다. view-source를 통해 소스코드를 확인했다.

<?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>

id의 값이 admin일 때 solve되는 문제다. 다만 admin 키워드를 preg_match로 막고있다.

실제로 ?id=admin을 URL에 입력하면 no! 라는 메시지가 출력된다.

preg_match의 조건을 우회하기 위해 admin을 아스키코드로 변환하여 %61%64%6d%69%6e를 입력해보았다. 하지만 여전히 no!가 출력된다.

 

이때 php는 자동으로 URL 디코딩 작업 1번 이루어짐을 알아야 한다. 또한, 소스코드를 확인해보면 urldecode 작업을 거치고 있다. 즉, 디코딩 작업은 2번 이루어지고 있다.

 

이를 고려하여 인코딩을 한 번 더 거친 %2561%2564%256d%2569%256e를 입력해주었더니 문제가 풀렸다.

 

https://www.w3schools.com/tags/ref_urlencode.ASP

 

HTML URL Encoding Reference

HTML URL Encoding Reference URL - Uniform Resource Locator Web browsers request pages from web servers by using a URL. The URL is the address of a web page, like: https://www.w3schools.com. URL Encoding (Percent Encoding) URL encoding converts characters i

www.w3schools.com

URL 인코딩 참고 표

'IT > 웹 해킹' 카테고리의 다른 글

[웹 해킹] 참고자료 및 문제 풀이 사이트  (0) 2021.08.30
[webhacking.kr] 10번 풀이  (0) 2021.08.30
[webhacking.kr] 25번 풀이  (0) 2021.08.27
[webhacking.kr] 24번 풀이  (0) 2021.08.27
[webhacking.kr] 12번 풀이  (0) 2021.08.23
Comments