티스토리 뷰

 

<html> 
<head> 
<title>Challenge 18</title> 
<style type="text/css"> 
body { background:black; color:white; font-size:10pt; } 
input { background:silver; } 
a { color:lightgreen; } 
</style> 
</head> 
<body> 
<br><br> 
<center><h1>SQL INJECTION</h1> 
<form method=get action=index.php> 
<table border=0 align=center cellpadding=10 cellspacing=0> 
<tr><td><input type=text name=no></td><td><input type=submit></td></tr> 
</table> 
</form> 
<a style=background:gray;color:black;width:100;font-size:9pt;><b>RESULT</b><br> 
<? 
if($_GET[no]) 
{ 

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

$q=@mysql_fetch_array(mysql_query("select id from challenge18_table where id='guest' and no=$_GET[no]")); 

if($q[0]=="guest") echo ("hi guest"); 
if($q[0]=="admin") 
{ 
@solve(); 
echo ("hi admin!"); 
} 

} 

?> 
</a> 
<br><br><a href=index.phps>index.phps</a> 
</cener> 
</body> 
</html>

@solve()에 도달해야할것같다. sql 쿼리를 "admin"으로 받아와야한다.

 

단서: 시험삼아 1을 입력해보았더니 "hi guest"를 출력하며, 첫번째 if문을 수행한다.

no=1이 guest였으니, no=2,3...값을 출력해보고싶다.

하지만 쿼리문에 where id='guest' 조건이 붙어있어 맘대로 할수가없다.

 

sql문은 and > or 순이라는 점을 이용해 앞부분의 조건을 무용지물로 만들어보자.

no값으로 0 or no=2 를 입력하면, no=2인 mysql값을 확인해볼수있다.

(0대신 다른값도 가능. (id='guest' and no=0) or no=2 형태를 만들어주는것)

 

하지만 입력시 eregi()에 의해 기본적인 특수문자 필터링이 되어, 공백을 우회시켜야한다.

eregi에서 \t같은건 필터링하므로 \n을 통해 우회시켜본다.

하지만 여전히, get으로 불러오며 \따로 n따로 url인코딩되버린다.

주소창에 \n으로 직접 입력해보자.

eregi()에서 \문자 또한 필터링되서 여전히 되지않는다.

따라서 \n이 인코딩된 %0a(line feed)를 이용하자.

입력시 문제 해결.

 

'Security&Hacking > WebHacking.kr' 카테고리의 다른 글

WebHacking.kr) Q24. wrong ip  (0) 2019.09.11
WebHacking.kr) Q16. *  (0) 2019.09.11
WebHacking.kr) Q17. unlock  (0) 2019.09.11
WebHacking.kr) Q14. ck()  (0) 2019.09.11
WebHacking.kr) Q6. index.phps  (0) 2019.09.11
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함