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,可選,規定刪除哪些字符,省略則默認刪除一些\t\n等字符。
<?php
$a1="hello world    \t\n";
$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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM