nginx/1.16.1PHP/7.3.11

    1. <?php
    2. /*
    3. # -*- coding: utf-8 -*-
    4. # @Author: h1xa
    5. # @Date: 2020-12-08 19:13:36
    6. # @Last Modified by: h1xa
    7. # @Last Modified time: 2020-12-08 20:08:07
    8. # @email: h1xa@ctfer.com
    9. # @link: https://ctfer.com
    10. */
    11. highlight_file(__FILE__);
    12. class filter{
    13. public $filename;
    14. public $filecontent;
    15. public $evilfile=false;
    16. public function __construct($f,$fn){
    17. $this->filename=$f;
    18. $this->filecontent=$fn;
    19. }
    20. public function checkevil(){
    21. if(preg_match('/php|\.\./i', $this->filename)){
    22. $this->evilfile=true;
    23. }
    24. if(preg_match('/flag/i', $this->filecontent)){
    25. $this->evilfile=true;
    26. }
    27. return $this->evilfile;
    28. }
    29. public function __destruct(){
    30. if($this->evilfile){
    31. system('rm '.$this->filename);
    32. }
    33. }
    34. }
    35. if(isset($_GET['fn'])){
    36. $content = file_get_contents('php://input');
    37. $f = new filter($_GET['fn'],$content);
    38. if($f->checkevil()===false){
    39. file_put_contents($_GET['fn'], $content);
    40. copy($_GET['fn'],md5(mt_rand()).'.txt');
    41. unlink($_SERVER['DOCUMENT_ROOT'].'/'.$_GET['fn']);
    42. echo 'work done';
    43. }
    44. }else{
    45. echo 'where is flag?';
    46. }
    47. where is flag?

    分析:
    看似花里胡哨,其实 __destruct 里的 system 可直接拼接,也就是设法让 $this->evilfile 置为 true ,然后拼接命令即可。

    image.png
    flag
    ctfshow{0e4fa799-1846-4520-93b8-ea81d66e786d}

    题外:第一眼看去这一读一写,长的这么想被我条件竞争的样子 (