CISCN final
打開頁面
掃描目錄
Robots.txt
Config.txt
代碼審計
<?php class master { private $path; private $name; function __construct() { } function stream_open($path) { if(!preg_match('/(.*)\/(.*)$/s',$path,$array,0,9)) return 1; $a=$array[1]; parse_str($array[2],$array); if(isset($array['path'])) { $this->path=$array['path']; } else return 1; if(isset($array['name'])) { $this->name=$array['name']; } else return 1; if($a==='upload') { return $this->upload($this->path,$this->name); } elseif($a==='search') { return $this->search($this->path,$this->name); } else return 1; } function upload($path,$name) { if(!preg_match('/^uploads\/[a-z]{10}\/$/is',$path)||empty($_FILES[$name]['tmp_name'])) return 1; $filename=$_FILES[$name]['name']; echo $filename; $file=file_get_contents($_FILES[$name]['tmp_name']); $file=str_replace('<','!',$file); $file=str_replace(urldecode('%03'),'!',$file); $file=str_replace('"','!',$file); $file=str_replace("'",'!',$file); $file=str_replace('.','!',$file); if(preg_match('/file:|http|pre|etc/is',$file)) { echo 'illegalbbbbbb!'; return 1; } file_put_contents($path.$filename,$file); file_put_contents($path.'user.jpg',$file); echo 'upload success!'; return 1; } function search($path,$name) { if(!is_dir($path)) { echo 'illegal!'; return 1; } $files=scandir($path); echo '</br>'; foreach($files as $k=>$v) { if(str_ireplace($name,'',$v)!==$v) { echo $v.'</br>'; } } return 1; } function stream_eof() { return true; } function stream_read() { return ''; } function stream_stat() { return ''; } } stream_wrapper_unregister('php'); stream_wrapper_unregister('phar'); stream_wrapper_unregister('zip'); stream_wrapper_register('master','master'); ?>
還發現有sql.txt
給出了數據庫名,數據表,列名,字段名
訪問User.php
發現有文件上傳點
訪問發現等級過低
估計要拿一個高分的賬戶
后面注意到注冊頁面有個推薦人,試了一下,注冊一個新賬戶給10個積分
到達一百個積分的時候可以上傳文件
上傳一個圖片馬
上傳失敗,回頭看看代碼config.php
這里過濾了尖括號,代碼盡管上傳成功,但是無法執行
代碼被替換了
無法上傳php馬,但是在嘗試過程中發現.htaccess可以被上傳,意味着我們可以包含文件
.htaccess相關介紹,在這里
鏈接:
https://www.cnblogs.com/adforce/archive/2012/11/23/2784664.html
https://blog.csdn.net/cmzhuang/article/details/53537591
后面實在看不出東西,無奈WP大法
說的比較詳細,大概意思是可以通過構造這個master協議來搜索文件,包含成功的話,這個文件的內容會映射到test.php里面
構造
php_value auto_append_file master://search/path={}&name={}
wp說的要把正斜杠編碼傳入才行,試了一下,確實不行,原因未知
編碼一下
php_value auto_append_file master://search/path=%2fhome%2f&name=flag
然后放進.htaccess里面,上傳
訪問1.php
直接包含進來
php_value auto_append_file /home/hiahiahia_flag
Flag拿到了