문제 설명
문제 이름처럼 로그인할 수 있는 창이 있다.
너무 눌러 보라는 듯이 get source 버튼이 있길래 눌러 보니, 소스코드가 나온다.
<?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 $FLAG, $DB_username, $DB_password.
$conn = mysqli_connect("localhost", $DB_username, $DB_password, "login_filtering");
mysqli_query($conn, "set names utf8");
$id = mysqli_real_escape_string($conn, trim($_POST['id']));
$ps = mysqli_real_escape_string($conn, trim($_POST['ps']));
$row=mysqli_fetch_array(mysqli_query($conn, "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 "FLAG : ".$FLAG;
}
}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
-->
코드 마지막쪽에 guest와 blueh4g라는 아이디/비번 쌍으로 추정되는p것이 있어서 먼저 로그인 시도를 해 본다.
'you have blocked accounts' 라고 나와있듯이... 정말 blocked 된 계정이라고 나온다.
아예 엉뚱한 아이디와 비번으로 로그인에 시도하면 wrong.. 라고 나오는 걸로 봐서, 위 두 가지 계정은 존재하나, 막혀있는 것임을 확신할 수 있다.
이 막혀있는 계정을 이용해 로그인에 성공한 뒤 플래그를 획득하는 형식의 문제이다.
다시 소스코드로 돌아가 살펴 본다.
소스코드에서 php, Mysql 등 익숙한 키워드를 볼 수 있다.
예전에 풀었던 어떤 문제에서 봤던 것도 같은데... 기억이 가물가물하기 때문에 이 개념부터 다시 찾아 봤다.
php(Personal Home Page Tools): 웹사이트 제작에 특화된 백엔드 언어. 동적인 웹 페이지를 만들기 위해 설계됨
MySQL: 오픈 소스의 관계형 데이터베이스 관리 시스템.
코드 상에서는
if($id=='guest' || $id=='blueh4g'){
echo "your account is blocked";
이러한 형태로, id인 'guest'와 'blueh4g'가 입력될 경우 무조건 blocked를 출력하게끔 제한해 두고 있다.
하지만 위에 언급한 것처럼 MySQL로 짜여진 코드이고
MySQL은 대소문자 구분을 하지 않는다.
그렇기 때문에, id를 교묘하게 대문자로 바꾸어 동일한 pw로 로그인하면 로그인이 가능하단 소리이다.
GUEST / guest 로 로그인을 시도해 본다.
플래그 획득에 성공했다.
'SWUFORCE > 워게임 풀이' 카테고리의 다른 글
[Dreamhack] littlevsbig (misc) (0) | 2024.08.06 |
---|---|
[Dreamhack] image-storage (web) (1) | 2024.07.22 |
[wargame.kr] fly me to the moon (web) (0) | 2024.07.16 |
[Dreamhack] simple_sqli_chatgpt (web) (0) | 2024.07.02 |
[Dreamhack] session (web) (1) | 2024.07.02 |