在一个CTF平台上发现了一个命令执行的题目
题目源代码如下:
<?php
if(isset($_REQUEST['ip'])) {
$target = trim($_REQUEST['ip']);
$substitutions = array(
'&' =>'',
';' =>'',
'|' =>'',
'-' =>'',
'$' =>'',
'(' =>'',
')' =>'',
"'" =>'',
);
$target = str_replace( array_keys ( $substitutions ),$substitutions,$target);
$cmd = shell_exec('nslookup' . $target);
echo $target;
echo "<pre>{$cmd}</pre>";
}
show_source(__FILE__);
?>
这个代码其实很容易就可以看懂,
用ip传参,然后带入shell_exec中执行命令
shell_exec:通过shell环境执行命令,并且将完整的输出以字符串的方式返回
他前面用了一个‘nslookup’,所以我们要在后面拼接上我们想要执行的语句
windows下执行多条命令:
Comnand1 & Comnand2:
先后执行Comnand1和Comnand2,无论Comnand1执行是否成功
Comnand1 && Comnand2:
先后执行Comnand1和Comnand2,只有Comnand1执行成功时才执行Comnand2
Comnand1 || Comnand2:
先后执行Comnand1和Comnand1,只有Comnand1执行失败时才执行Comnand1
Comnand1 | Comnand2:
|是管道符,将Comnand1的执行结果传递给Comnand2
linux下执行多条命令
Comnand1 ; Comnand2:
先后执行Comnand1和Comnand2,无论Comnand1执行是否成功
Comnand1 && Comnand2:
先后执行Comnand1和Comnand2,只有Comnand1执行成功时才执行Comnand2
Comnand1 || Comnand2:
先后执行Comnand1和Comnand1,只有Comnand1执行失败时才执行Comnand1
Comnand1 | Comnand2:
|是管道符,将Comnand1的执行结果传递给Comnand2
我们通过谷歌插件发现是乌班图系统,但是上面的命令都被过滤掉了
我们尝试用%0a进行绕过
%0a 代表换行的意思
成功的查看到了flag