[Level 18]Lord of SQL injection – nightmare

Lord of SQL injection – nightmare

Level 18


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)|#|-/i', $_GET[pw])) exit("No Hack ~_~"); 
  if(strlen($_GET[pw])>6) exit("No Hack ~_~"); 
  $query = "select id from prob_nightmare where pw=('{$_GET[pw]}') and id!='admin'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result['id']) solve("nightmare"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/nightmare-~~.php?pw=123 이라고 입력하게 되면
select id from prob_nightmare where pw=('123') and id!='admin'과 같이 MySQL 쿼리문이 입력된다.
6번째 줄을 보면 pw의 길이가 6이 넘어가면 "No Hack ~_~"을 출력되며 #, -- 등의 주석을 모두 필터링 하였다.
그리고 10번째 줄을 보면 
&result['id']
가 설정 되어있으면 nightmare문제가 풀린다.

Frist Hint is next page

[Level 17]Lord of SQL injection – succubus

Lord of SQL injection – succubus

Level 17


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/\'/i', $_GET[id])) exit("HeHe"); 
  if(preg_match('/\'/i', $_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_succubus 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("succubus"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/succubus-~~.php?id=user&pw=123 이라고 입력하게 되면
select id from prob_succubus where id='user' and pw='123'과 같이 MySQL 쿼리문이 입력된다.
이번엔 정규표현식을 통해 id와 pw의 입력에서 싱글 쿼터(‘)를 필터링 하고 있다.
그리고 11번째 줄을 보면 &result['id']가 설정 되어있으면 succubus문제가 풀린다.

Frist Hint is next page

[Level 16]Lord of SQL injection – zombie_assassin

Lord of SQL injection – zombie_assassin

Level 16


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/\\\|prob|_|\.|\(\)/i', $_GET[id])) exit("No Hack ~_~"); 
  if(preg_match('/\\\|prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  if(@ereg("'",$_GET[id])) exit("HeHe"); 
  if(@ereg("'",$_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_zombie_assassin 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("zombie_assassin"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/zombie_assassin-~~.php?id=user&pw=123 이라고 입력하게 되면
select id from prob_zombie_assassin where id='user' and pw='123'과 같이 MySQL 쿼리문이 입력된다.
7번째 줄에서 ereg함수로 id와 pw의 입력에서 싱글 쿼터(‘)를 필터링 하고 있다.
그리고 11번째 줄을 보면 &result['id']가 설정 되어있으면 zombie_assassin문제가 풀린다.

Frist Hint is next page

[Level 15]Lord of SQL injection – assassin

Lord of SQL injection – assassin

Level 15


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/\'/i', $_GET[pw])) exit("No Hack ~_~"); 
  $query = "select id from prob_assassin where pw like '{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
  if($result['id'] == 'admin') solve("assassin"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/assassin-~~.php?pw=123 이라고 입력하게 되면
select 1234 from prob_assassin where pw like '123'과 같이 MySQL 쿼리문이 입력된다.
9번째 줄에서 pw가 일치하는  id를 출력한다.
그리고 10번째 줄을 보면 &result['id']가 admin이면  assassin문제가 풀린다.
 즉, 쿼리문의 pw가 일치하는 id값을 가져온다.

Frist Hint is next page

[Level 14]Lord of SQL injection – giant

Lord of SQL injection – giant

Level 14


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(strlen($_GET[shit])>1) exit("No Hack ~_~"); 
  if(preg_match('/ |\n|\r|\t/i', $_GET[shit])) exit("HeHe"); 
  $query = "select 1234 from{$_GET[shit]}prob_giant where 1"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result[1234]) solve("giant"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/giant-~~.php?shit=A 이라고 입력하게 되면
select 1234 fromAprob_giant where 1과 같이 MySQL 쿼리문이 입력된다.
그리고 5번째 줄에서 문자열의 길이가 1보다 크면 “HeHe”를 출력한다.
10번째 줄을 보면 &result['1234']가 참이기만 하면  giant문제가 풀린다.
 즉, 쿼리문이 실행 되기만 하면된다.

Frist Hint is next page

[Level 13]Lord of SQL injection – bugbear

Lord of SQL injection – bugbear

Level 13


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'/i', $_GET[pw])) exit("HeHe"); 
  if(preg_match('/\'|substr|ascii|=|or|and| |like|0x/i', $_GET[no])) exit("HeHe"); 
  $query = "select id from prob_bugbear where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_bugbear where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("bugbear"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/bugbear-~~.php?pw=123&no=12 이라고 입력하게 되면
select id from prob_bugbear where id='guest' and pw='123' no=12과 같이 MySQL 쿼리문이 입력된다.
그리고 5번째 줄에서 ‘or’, ‘and’, ‘substr’, ‘=’, ‘ascii’, ‘ ‘, ‘like’, ‘0x’, 싱글쿼터가 필터링 되어있다.
 15번째 줄을 보면 &result['pw']에 admin의 pw가 들어가야만 bugbear문제가 풀린다.

이전 문제처럼 ‘를 사용할 수 도 없고 hex값으로 우회하자니 0x가 필터링 되어있다. 어떻게 해야할까?

Frist Hint is next page

[Level 12]Lord of SQL injection – darkknight

Lord of SQL injection – darkknight

Level 12


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~"); 
  if(preg_match('/\'/i', $_GET[pw])) exit("HeHe"); 
  if(preg_match('/\'|substr|ascii|=/i', $_GET[no])) exit("HeHe"); 
  $query = "select id from prob_darkknight where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_darkknight where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/darkknight-~~.php?pw=123&no=12 이라고 입력하게 되면
select id from prob_darkknight where id='guest' and pw='123' no=12과 같이 MySQL 쿼리문이 입력된다.
그리고 5번째 줄에서 ‘or’, ‘and’, ‘substr’, ‘=’, ‘ascii’이 필터링 되어있다.
 15번째 줄을 보면 &result['pw']에 admin의 pw가 들어가야만 darkknight문제가 풀린다.

Frist Hint is next page

[Level 11]Lord of SQL injection – golem

Lord of SQL injection – golem

Level 11


Source Code

<?php 
  include "../config.php"; 
  login_chk(); 
  dbconnect(); 
  if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
  if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe"); 
  $query = "select id from prob_golem where id='guest' and pw='{$_GET[pw]}'"; 
  echo "<hr>query : <strong>{$query}</strong><hr><br>"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if($result['id']) echo "<h2>Hello {$result[id]}</h2>"; 
   
  $_GET[pw] = addslashes($_GET[pw]); 
  $query = "select pw from prob_golem where id='admin' and pw='{$_GET[pw]}'"; 
  $result = @mysql_fetch_array(mysql_query($query)); 
  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem"); 
  highlight_file(__FILE__); 
?>

Analyse

http://los.sandbox.cash/golem-~~.php?pw=123 이라고 입력하게 되면
select id from prob_golem where id='guest' and pw='123' and 1=0과 같이 MySQL 쿼리문이 입력된다.
그리고 5번째 줄에서 ‘or’, ‘and’, ‘substr(‘, ‘=’이 필터링 되어있다.
 15번째 줄을 보면 &result['pw']에 admin의 pw가 들어가야만 golem문제가 풀린다.

Frist Hint is next page