Study/Hacking
[webhacking.kr] old-04
dys4nt
2023. 6. 13. 20:33
문제 소스를 보면
<?php
sleep(1); // anti brute force
if((isset($_SESSION['chall4'])) && ($_POST['key'] == $_SESSION['chall4'])) solve(4);
$hash = rand(10000000,99999999)."salt_for_you";
$_SESSION['chall4'] = $hash;
for($i=0;$i<500;$i++) $hash = sha1($hash);
?>
hash가 (1000000~99999999)salt_for_you 형태의 값으로 결정되고
이를 500번 sha1 해시화한 것이 표시되는 해시값이다.
10000000~19999999 까지의 해시값의 앞 8글자정도만 구한 다음에 이 데이터와 맞는 숫자를 대입해주면 문제가 풀린다.
[hash.txt를 생성하는 코드]
import hashlib
import tqdm
f = open("./hash.txt","w")
for i in tqdm.tqdm(range(10000000,20000000)):
sess = str(i) + "salt_for_you"
res = sess
for j in range(500):
res = hashlib.sha1(res.encode("ascii")).hexdigest()
f.write(res[:8]+'\n')
d8cd548f을 hash.txt에서 검색해보면 9315032번째 숫자이다.
따라서 key는 19315031salt_for_you 이다.
이를 POST하면 문제가 풀리게 된다.