이번 문제는 그냥 웹 사이트 내에서 flag값을 찾으면 될 것 같습니다
바로 접속해보겠습니다
이번에도 로그인 창이 뜨는걸 확인했습니다
당연히 로그인이 되진 않겠지만 일단 무작정 넣어봅니다
Usename 입력 : admin
Password 입력 : 1234
로그인에 실패한걸 확인했습니다
소스코드를 확인해보겠습니다
로그인창의 코드 소스를 확인해보면
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Secure Customer Portal</title>
</head>
<body>
<h1>Secure Customer Portal</h1>
<p>Only letters and numbers allowed for username and password.</p>
<form role="form" action="login.php" method="post">
<input type="text" name="username" placeholder="Username" required
autofocus></br>
<input type="password" name="password" placeholder="Password" required>
<button type="submit" name="login">Login</button>
</form>
</body>
</html>
이렇게 나옵니다
아래로 내려가다보면 입력값을 검증하는 로직이 있을 것으로 예상되는 login.php 파일이 보입니다
<form role="form" action="login.php" method="post">
뭐든 해봐야하니 저 경로로 진입해보겠습니다
login.php진입 후 코드
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Login Page</title>
</head>
<body>
<script src="secure.js"></script>
<p id='msg'></p>
<form hidden action="admin.php" method="post" id="hiddenAdminForm">
<input type="text" name="hash" required id="adminFormHash">
</form>
<script type="text/javascript">
function filter(string) {
filterPassed = true;
for (let i =0; i < string.length; i++){
cc = string.charCodeAt(i);
if ( (cc >= 48 && cc <= 57) ||
(cc >= 65 && cc <= 90) ||
(cc >= 97 && cc <= 122) )
{
filterPassed = true;
}
else
{
return false;
}
}
return true;
}
window.username = "";
window.password = "";
usernameFilterPassed = filter(window.username);
passwordFilterPassed = filter(window.password);
if ( usernameFilterPassed && passwordFilterPassed ) {
loggedIn = checkPassword(window.username, window.password);
if(loggedIn)
{
document.getElementById('msg').innerHTML = "Log In Successful";
document.getElementById('adminFormHash').value = "2196812e91c29df34f5e217cfd639881";
document.getElementById('hiddenAdminForm').submit();
}
else
{
document.getElementById('msg').innerHTML = "Log In Failed";
}
}
else {
document.getElementById('msg').innerHTML = "Illegal character in username or password."
}
</script>
</body>
</html>
위 코드에서 body의 시작 부분의 checkPassword(username, password) 함수 내부 로직을 확인하고 어떤 입력값을 줘야 true가 나오는지 분석을 해야할 것 같습니다. 바로 source.js로 이동해보겠습니다
function checkPassword(username, password)
{
if( username === 'admin' && password === 'strongPassword098765' )
{
return true;
}
else
{
return false;
}
}
username이 admin
password가 strongPassword098765일때 로그인이 되도록 설계가 되었습니다
맞는지 확인까지 해보겠습니다
방금 얻은 username, password를 입력하니 flag값이 제대로 나온 것을 확인했습니다
이번에도 어려운 느낌은 아닌 문제 같습니다.