京麒CTF25-热身Web
1diot9 Lv3

Execute

考命令执行

先看一下php版本,这里可以直接执行代码:img

是php7,那么我们知道,这里是支持这种函数执行方式的:

1
2
$a = "system";
$a('ls');

试了一下,直接成功了:img

可以看一下题目的过滤逻辑:

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
89
90
91
92
93
94
95
<?php
header('Content-Type: text/html; charset=utf-8');

$max_execution_time = 5;
$memory_limit = '128M';
$disabled_functions = [
'exec', 'passthru', 'shell_exec', 'system', 'proc_open', 'popen',
'curl_exec', 'curl_multi_exec', 'parse_ini_file', 'show_source',
'pcntl_exec', 'posix_kill', 'posix_mkfifo', 'posix_setpgid',
'posix_setsid', 'posix_setuid', 'posix_setgid', 'posix_uname',
'dl', 'openlog', 'syslog', 'closelog'
];

ini_set('max_execution_time', $max_execution_time);
ini_set('memory_limit', $memory_limit);

$code = isset($_POST['code']) ? $_POST['code'] : '';

if (empty($code)) {
die('错误: 没有提供PHP代码');
}

foreach ($disabled_functions as $func) {
if (preg_match('/\b' . preg_quote($func, '/') . '\s*\(/i', $code)) {
die("安全错误: 不允许使用 {$func}() 函数");
}
}

$dangerous_patterns = [
'/`.*`/', // 反引号执行
'/eval\s*\(/i', // eval函数
'/create_function\s*\(/i', // create_function
'/include\s*\(/i', // include
'/require\s*\(/i', // require
'/include_once\s*\(/i', // include_once
'/require_once\s*\(/i', // require_once
'/file_put_contents\s*\(/i', // 文件写入
'/file_get_contents\s*\(/i', // 文件读取
'/unlink\s*\(/i', // 文件删除
'/phpinfo\s*\(/i', // phpinfo
'/chmod\s*\(/i', // 修改权限
'/chown\s*\(/i', // 修改所有者
'/chgrp\s*\(/i', // 修改组
'/putenv\s*\(/i', // 环境变量
'/ini_set\s*\(/i', // 修改INI设置
'/extract\s*\(/i', // extract
'/parse_str\s*\(/i', // parse_str
'/assert\s*\(/i', // assert
'/preg_replace\s*\(.*\/e.*\)/i', // preg_replace /e修饰符
'/proc_terminate\s*\(/i', // 进程终止
'/pcntl_fork\s*\(/i', // 进程控制
'/posix_getpwuid\s*\(/i', // 获取用户信息
'/posix_kill\s*\(/i', // 发送信号
'/posix_setuid\s*\(/i', // 设置UID
'/posix_setgid\s*\(/i' // 设置GID
];

foreach ($dangerous_patterns as $pattern) {
if (preg_match($pattern, $code)) {
die("安全错误: 检测到潜在的危险操作");
}
}

ob_start();

$old_error_reporting = error_reporting(E_ALL);
$old_display_errors = ini_set('display_errors', '1');

try {
eval('?>' . $code);
} catch (ParseError $e) {
echo "解析错误: " . $e->getMessage() . "\n";
echo "位于行: " . $e->getLine() . "\n";
} catch (Throwable $e) {
echo "运行时错误: " . $e->getMessage() . "\n";
echo "位于行: " . $e->getLine() . "\n";
}

error_reporting($old_error_reporting);
ini_set('display_errors', $old_display_errors);

$output = ob_get_clean();

$sensitive_patterns = [
'/\/home\/.*/i',
'/\/var\/www\/.*/i',
'/\[internal function\]/i'
];

foreach ($sensitive_patterns as $pattern) {
$output = preg_replace($pattern, '[隐藏信息]', $output);
}

echo htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
?>

大概就是通过 ‘system(‘这样的匹配规则来过滤。最底下还会对输出中的敏感目录进行过滤。

Ezlogin

可以通过插件或者cookie来判断是一道Java。img

扫一下目录,发现有/actuator泄露。简单看一下mapping,env,能发现是一个8u111的环境。

然后开始用heapdump,先getfile看一下依赖:img

可以看到有shiro和cc3.2.1,下面还有一个cb1.9.4

查一下shirokey,上面图片最顶上其实已经查了。

那接下来用java-chain工具一把梭就行。img

记得把GCM模式打开。

带上cookie,发包即可。不过这里好像对header长度有限制,我生成内存马直接报错了。

Cookie: rememberMe= 6ZAFnvTDGFQNmw2R2x4S8+bF。。。

总结

题目比较简单,但是题目的环境都挺好的,看着很舒服。

由 Hexo 驱动 & 主题 Keep
本站由 提供部署服务
总字数 22.8k 访客数 访问量