Platform_强网24

分析与尝试

  1. 前端没有东西开扫,有www.zip
  2. 目标就是notous…中析构执行任意代码,问题就是访问不到有些难绷,序列化和反序列化?
    1. 需要从session入手,查查php seesion利用方式,发现有一个反序列化漏洞,看一看,差不多了解了
      1. session写入键供后续反序列化,生成notouc…对象,注意到每一次访问都会进行读取,5.5.4后默认php_serialize(复现看不到版本,但是看wp一部分是php方式),使用竖线|来实现加载时的反序列化
      2. 注意到str_replace有双写绕过,但是数字限定了,需要使用字符串逃逸bro
  3. 顺带一提一个其他思路:注意到有文件包含,后面有文件写入,可不可以写入文件中进行包含执行?这里肯定不可以,主要还是看线索

源码

  1. www.zip的内容
1
2
// dashboard.php
<p>你好,<?php echo htmlspecialchars($_SESSION['user']); ?>!</p>
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
// index.php
<?php
session_start();
require 'user.php';
require 'class.php';

$sessionManager = new SessionManager();
$SessionRandom = new SessionRandom();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];

$_SESSION['user'] = $username;

if (!isset($_SESSION['session_key'])) {
$_SESSION['session_key'] =$SessionRandom -> generateRandomString();
}
$_SESSION['password'] = $password;
$result = $sessionManager->filterSensitiveFunctions();
header('Location: dashboard.php');
exit();
} else {
require 'login.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
// class.php
<?php
class notouchitsclass {
public $data;

public function __construct($data) {
$this->data = $data;
}

public function __destruct() {
eval($this->data);
}
}

class SessionRandom {

public function generateRandomString() {
$length = rand(1, 50);

$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';

for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}

return $randomString;
}


}

class SessionManager {
private $sessionPath;
private $sessionId;
private $sensitiveFunctions = ['system', 'eval', 'exec', 'passthru', 'shell_exec', 'popen', 'proc_open'];

public function __construct() {
if (session_status() == PHP_SESSION_NONE) {
throw new Exception("Session has not been started. Please start a session before using this class.");
}
$this->sessionPath = session_save_path();
$this->sessionId = session_id();
}

private function getSessionFilePath() {
return $this->sessionPath . "/sess_" . $this->sessionId;
}

public function filterSensitiveFunctions() {
$sessionFile = $this->getSessionFilePath();

if (file_exists($sessionFile)) {
$sessionData = file_get_contents($sessionFile);

foreach ($this->sensitiveFunctions as $function) {
if (strpos($sessionData, $function) !== false) {
$sessionData = str_replace($function, '', $sessionData);
}
}
file_put_contents($sessionFile, $sessionData);

return "Sensitive functions have been filtered from the session file.";
} else {
return "Session file not found.";
}
}
}