WARGAME.KR login filterling 풀이
[ 대소문자 ]
오늘은 wargame.kr의 login filterling 문제를 풀어보자.
들어가면 다음과 같이 로그인창이 하나 나온다.
친절하게도 이 페이지의 백엔드 코드를 제공해줬다.
<?php
if (isset($_GET['view-source'])) {
show_source(__FILE__);
exit();
}
/*
create table user(
idx int auto_increment primary key,
id char(32),
ps char(32)
);
*/
if(isset($_POST['id']) && isset($_POST['ps'])){
include("../lib.php"); # include for auth_code function.
mysql_connect("localhost","login_filtering","login_filtering_pz");
mysql_select_db ("login_filtering");
mysql_query("set names utf8");
$key = auth_code("login filtering");
$id = mysql_real_escape_string(trim($_POST['id']));
$ps = mysql_real_escape_string(trim($_POST['ps']));
$row=mysql_fetch_array(mysql_query("select * from user where id='$id' and ps=md5('$ps')"));
if(isset($row['id'])){
if($id=='guest' || $id=='blueh4g'){
echo "your account is blocked";
}else{
echo "login ok"."<br />";
echo "Password : ".$key;
}
}else{
echo "wrong..";
}
}
?>
<!DOCTYPE html>
<style>
* {margin:0; padding:0;}
body {background-color:#ddd;}
#mdiv {width:200px; text-align:center; margin:50px auto;}
input[type=text],input[type=[password] {width:100px;}
td {text-align:center;}
</style>
<body>
<form method="post" action="./">
<div id="mdiv">
<table>
<tr><td>ID</td><td><input type="text" name="id" /></td></tr>
<tr><td>PW</td><td><input type="password" name="ps" /></td></tr>
<tr><td colspan="2"><input type="submit" value="login" /></td></tr>
</table>
<div><a href='?view-source'>get source</a></div>
</form>
</div>
</body>
<!--
you have blocked accounts.
guest / guest
blueh4g / blueh4g1234ps
-->
그럼 이제 우리가 해야할것은?
당연히 코드를 분석하는것이다.
if(isset($_POST['id']) && isset($_POST['ps'])){
include("../lib.php"); # include for auth_code function.
id값과 ps값이 POST를 통해 넘어오면 lib.php를 include해준다.
mysql_connect("localhost","login_filtering","login_filtering_pz");
mysql_select_db ("login_filtering");
mysql_query("set names utf8");
DB서버에 접속하고 login_filtering이라는 db를 select한다.
$id = mysql_real_escape_string(trim($_POST['id']));
$ps = mysql_real_escape_string(trim($_POST['ps']));
넘어온 id값과 ps값의 특수문자를 이스케이핑시키고 각각 $id와 $ps에 저장.
$row=mysql_fetch_array(mysql_query("select * from user where id='$id' and ps=md5('$ps')"));
$id와 $ps를 이용하여 SQL 쿼리 구문을 작성한다.
if(isset($row['id'])){
아이디가 존재한다면
if($id=='guest' || $id=='blueh4g'){
echo "your account is blocked";
}else{
echo "login ok"."<br />";
echo "Password : ".$key;
}
}
아이디가 guest 또는 blueh4g라면 your account is blocked를 출력해주고, 아닌 경우에는 로그인이 되며 키값이 출력된다.
else{
echo "wrong..";
}
아이디가 존재하지 않는다면 wrong..을 띄워준다.
우선 PHP는 대소문자를 구별하고, SQL은 대소문자를 구별하지 않는다는 속성을 이용해보자.
소스코드의 하단에 보면 차단된 계정이 기록되어 있는데, 그 계정을 이용하여 로그인해보자.
guest의 앞글자를 대문자 G로 바꿔서 로그인해보자.
로그인에 성공하고 키값이 도출된다.
WARGAME.KR login filterling 클리어!
'보안공부 > Wargame.kr 풀이' 카테고리의 다른 글
wargame.kr type confusion 풀이 - json (0) | 2018.08.03 |
---|---|
wargame.kr WTF_CODE 풀이 - Space (0) | 2018.07.15 |
wargame.kr flee button 풀이 - Style (0) | 2018.07.13 |
wargame.kr QR CODE PUZZLE 풀이 - GET (0) | 2018.07.12 |
wargame.kr already got 풀이 - 머리속에 (0) | 2018.07.12 |