今晚有空 之後隨緣寫博客了 好好沉澱php
web1當天作出的隊伍不多 其實不難 折騰到最後就差一步 惋惜 css
截圖沒留了 只留了代碼部分。html
有個頁面 有上傳和下載功能前端
起初覺得是上傳漏洞 發現上傳後都會在後面加.jpgjquery
且phpsessionid爲文件名和目錄web
上傳繞了好久 再看的時候是看下載功能 發現有文件讀取。session
能夠進行目錄穿越讀取 經過文件中的包含信息順騰摸瓜把文件類讀取出來:app
func.php:函數
而後根據這裏auto_class讀取其餘類文件。post
邏輯順序來讀一遍。分析利用的點
先是定義類的index:
<?php defined('DS') or define('DS', DIRECTORY_SEPARATOR); define('APP_DIR', realpath('./')); define('Cache_DIR',APP_DIR.DS.'user'); define('View_DIR',APP_DIR.DS.'app'.DS.'view'); define('Core_DIR',APP_DIR.DS.'core'); define('Image_DIR',APP_DIR.DS.'upload'); include(Core_DIR.DS.'core.php');
而後是核心core文件:
<?php if(!defined('Core_DIR')){ exit(); } include(Core_DIR.DS.'config.php'); include(Core_DIR.DS.'func.php'); _if_debug($config['debug']); spl_autoload_register('autoload_class'); config($config['ini']); // 'session.name' => 'PHPSESSID', // 'session.serialize_handler' => 'php' session_start(); define('Upload_DIR',Image_DIR.DS.session_id()); init(); $app = new IndexController(); if(method_exists($app, $app->data['method'])){ $app->{$app->data['method']}($app->data['param']); }else{ $app->index(); } #$this->method($_POST)
先是包含了兩個文件func和inc
而後spl_autoload_register('autoload_class');加載類文件 接着開啓session 定義上傳文件的路徑 下面就是new 了一個 IndexController();對象
看看這個對象的IndexController類文件:
(比賽的時候本身作了點註釋)
不難看出 在post方法中會實體一個FILEs類 這是題目本身定義的文件類 接着進行Cache類的實體化
FILE類:
Cache類:
File類對上傳的文件進行控制處理,目錄寫死了的 $data雖然在IndexController類可控 意義不大 重點看Cache類:
<?php class Cache{ public $data; public $sj; public $path; public $html; function __construct($data){ $this->data['name']=isset($data['post']['name'])?$data['post']['name']:''; $this->data['message']=isset($data['post']['message'])?$data['post']['message']:''; $this->data['image']=!empty($data['image'])?$data['image']:'/static/images/pic04.jpg'; $this->path=Cache_DIR.DS.session_id().'.php'; } function __destruct(){ $this->html=sprintf('<!DOCTYPE HTML><html><head><title>LOL</title><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /><link rel="stylesheet" href="/static/css/main.css" /><noscript><link rel="stylesheet" href="/static/css/noscript.css" /></noscript> </head> <body class="is-preload"><div id="wrapper"><header id="header"> <div class="logo"><span class="icon fa-diamond"></span> </div> <div class="content"><div class="inner"> <h1>Hero of you</h1></div> </div> <nav><ul> <li><a href="#you">YOU</a></li></ul> </nav></header><div id="main"><article id="you"> <h2 class="major" ng-app>%s</h2> <span class="image main"><img src="%s" alt="" /></span> <p>%s</p><button type="button" onclick=location.href="/download/%s">下載</button></article></div><footer id="footer"></footer></div><script src="/static/js/jquery.min.js"></script><script src="/static/js/browser.min.js"></script><script src="/static/js/breakpoints.min.js"></script><script src="/static/js/util.js"></script><script src="/static/js/main.js"></script><script src="/static/js/angular.js"></script> </body></html>', substr($this->data['name'],0,62),$this->data['image'],$this->data['message'],session_id().'.jpg'); if(file_put_contents($this->path,$this->html)){ include($this->path); } } }
發現此類的析構函數中對前端輸出同時 用一些變量寫入了文件 而且在後面進行寫文件和包含
這裏就考察了php反序列化的內容 一個經典的引擎解析不一樣致使反序列化 + session.upload_progress進行文件包含
upload_progress這個之前沒遇到過~ 卑微
關於解析引擎不一樣的反序列化這裏只簡單提一下 看不懂本身網上去學
反序列化參數:
session.save_handler session保存形式。默認爲files session.save_path session保存路徑。 session.serialize_handler session序列化存儲所用處理器。默認爲php。 session.upload_progress.cleanup 一旦讀取了全部POST數據,當即清除進度信息。默認開啓 session.upload_progress.enabled 將上傳文件的進度信息存在session中。默認開啓。
當 session.serialize_handler=php 時,session文件內容爲: name|s:7:"mochazz";
當 session.serialize_handler=php_serialize 時,session文件爲: a:1:{s:4:"name";s:7:"mochazz";}
因此解析引擎不一樣致使反序列化 原本是字符串的 | 被當成php中的分隔符
關於session.upload_progress.enabled
當 session.upload_progress.enabled INI 選項開啓時,PHP 可以在每個文件上傳時監測上傳進度。 若是session.upload_progress.cleanup = off的話 會話信息會寫到文件中。
這裏對文件名直接反序列化並文件名被寫在包含文件中
直接構造上傳表單便可:
<form action="index.php" method="POST" enctype="multipart/form-data"> <input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="1111" /> <input type="file" name="file" /> <input type="submit"/> </form>
filename爲咱們的反序列cache類的 paylaod 內容進行一句話的替換