[LORD OF SQLINJECTION] Cobolt 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[id])) exit("No Hack ~_~"); // do not try to attack another table, database!
 6  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
 7  $query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
 8  echo "<hr>query : <strong>{$query}</strong><hr><br>";
 9  $result = @mysqli_fetch_array(mysqli_query($db,$query));
10  if($result['id']) solve("gremlin");
11  highlight_file(__FILE__);
12?>

제시된 문제를 살펴보면 id와 pw parameters로 구성된 $query를 실행한 결과의 id field 값이 admin이면 풀림을 알 수 있다. 비록 pw parameter 값을 해시한 값으로 비교하지만, 이는 주석 처리함으로써 해결할 수 있다.

# Exploit

SQLi를 위한 id와 pw parameters의 값은 다음과 같다:

    id=admin'%23
    pw=haha

# References

  1. "cobolt," LORD OF SQLINJECTION. [Online]. Available: https://los.rubiya.kr/gate.php, [Accessed Mar. 04, 2024].