[Wargame] login filtering

동스토리 ㅣ 2021. 3. 1. 22:35

반응형

안녕하세요.

 

워 게임 login filtering 문제풀이 하겠습니다.

 

문제를 보면 계정을 가지고 있지만, 막혔고 우회를 해달라고 합니다.

 

소스코드를 보면,

 

<?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

-->

[line: 62 ~ 64] guest / guest, blueh4g / blueh4g1234ps 계정을 가지고 있는데 blocked이 되고 있습니다.

 

[line: 30 ~ 40]

- id가 guest OR blueh4g 일 경우 your account is blocked 메시지를 출력하고 있습니다.

- 그 외에 경우에는  login ok와 password에 key값을 출력해주고 있습니다.

- 그렇다면, id를 guest를 Guest / guest로 우회해서 로그인 시도해보겠습니다.

 

이렇게 우회를 시도한 이유는 Default로 PHP는 문자의 대소문자를 구분하지만, Mysql은 문자의 대소문자를 구분하지 못합니다.

즉, PHP에 guest / Guest는 다른 값이지만, Mysql에 guest / Guest는 같은 값이라고 말할 수 있습니다.

 

 

값으로 나온 Password에 key값을 정답으로 제출하면 문제를 해결할 수 있습니다.

 

감사합니다.

 

반응형

'Hacking > Wargame.kr' 카테고리의 다른 글

[Wargame] fly me to the moon  (0) 2021.03.17
[Wargame] WTF_CODE  (0) 2021.03.06
[Wargame] QR CODE PUZZLE  (0) 2021.02.25
[Wargame] free button  (0) 2021.02.21
[Wargame] already got  (0) 2021.02.20