[Webhacking.kr] old-11

Alexandria·2024년 2월 29일

Wargame Webhacking.kr

목록 보기
11/69
post-thumbnail

1. Description

2. Write-Up

view-source를 클릭하면 정규표현식을 이용하여 val에 들어있는 데이터와 매칭하여 참이면 점수를 획득할 수 있을 것으로 보인다.

... 생략 ...
<?php
  $pat="/[1-3][a-f]{5}_.*$_SERVER[REMOTE_ADDR].*\tp\ta\ts\ts/";
  if(preg_match($pat,$_GET['val'])){
    solve(11);
  }
  else echo("<h2>Wrong</h2>");
  echo("<br><br>");
?>
... 생략 ...

정규 표현식을 분해하자.

  1. [1-3] : 1, 2, 3중에 1개가 들어가야 함
  2. [a-f] : a ~ f까지 중에 1개가 들어가야 함
  3. {5} : 바로앞의 표현식(a-f)이 5번 반복되어야 함
  4. * : 앞 패턴('_')이 0번 이상 반복되어야 함
  5. $_SERVER[REMOTE_ADDR] : 공인 ip 주소
  6. * : 앞 패턴($_SERVER[REMOTE_ADDR])이 0번 이상 반복되어야 함
  7. \t : tab

패턴에 맞게 val값을 전달해 주면 점수를 획득할 수 있다.

import urllib.request

val     = urllib.parse.quote('1aaaaa_61.251.215.194_\tp\ta\ts\ts')
url     = 'https://webhacking.kr/challenge/code-2/?val='+val
header  = {'Cookie': 'PHPSESSID=s5g2rgani18o2h3nbe34lln6bd'}
request = urllib.request.Request(url, headers=header)
response= urllib.request.urlopen(request)
result  = response.read().decode()
print(result)

[Output]
<html>
<title>Challenge 11</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
</style>
</head>
<body>
<center>
<br><br>
<script>alert('old-11 Pwned!');</script><hr>old-11 Pwned. You got 30point. Congratz!<hr><br><br><a href=./?view_source=1>view-source</a>
</center>
</body>
</html>
profile
IT 도서관

0개의 댓글