DoR@Hee의 끄적끄적

webhacking.kr 18번 본문

WarGame/WebHacking.kr

webhacking.kr 18번

DoR@Hee 2019. 2. 15. 16:18


문제 첫화면 SQL INJECTION 관련 문제인거같으며, 다행이 index.phps를 보여준다. 

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
32
33
34
35
36
<html
<head
<title>Challenge 18</title
<style type="text/css"> 
body { background:black; color:white; font-size:10pt; } 
input { background:silver; } 
{ 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]) //매개변수 no가 존재한다면
if(eregi(" |/|\(|\)|\t|\||&|union|select|from|0x",$_GET[no])) exit("no hack"); //변수 no에  |/|\(|\)|\t|\||&|union|select|from|0x 존재한다면 exit 
$q=@mysql_fetch_array(mysql_query("select id from challenge18_table where id='guest' and no=$_GET[no]")); //존재하지 않는다면 쿼리 전송 $q에 값 저장
if($q[0]=="guest"echo ("hi guest"); //guest일 경우 echo
if($q[0]=="admin"//admin일 경우 solve
@solve(); 
echo ("hi admin!"); 
?> 
</a
<br><br><a href=index.phps>index.phps</a
</cener
</body
</html
cs



index.php내용이며 소스에 주석을 달아보았다.

db값을 admin으로 출력하는것이 목적인거같다.


먼저 1을 입력해보았다.



select id from challenge18_table where id='guest' and no=1 // 참



select id from challenge18_table where id='guest' and no=2 // 거짓


그럼 or 문을 이용해서 select문을 admin이 들어있는 no를 찾아야한다. 하지만 admin의 no값이 몇인지는 모른다.


select id from challenge18_table where (id='guest' and no=-1) or no = 2 // 이런식으로 접근

id='guest' and no=-1는 거짓 no=-1 or no = 2를 한번 입력해보았다.


완성된 쿼리 근데 위에서 space는 치환하고있기때문에 

Tab : %09

Line Feed(\n) : %0a

Carrage Return(wr) : %0d

주석 : /**/

괄호 : ()

더하기 : +

등을 이용해서 우회가 가능하다.

성공


'WarGame > WebHacking.kr' 카테고리의 다른 글

webhacking.kr 20번  (0) 2019.02.15
webhacking.kr 19번  (0) 2019.02.15
webhacking.kr 17번  (0) 2019.02.15
webhacking.kr 16번  (0) 2019.02.15
webhacking.kr 15번  (0) 2019.02.15
Comments