forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_audit.php
308 lines (271 loc) · 8.7 KB
/
security_audit.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
/**
* Description:
* This page will take look for possible security issues with
* this installation of WebCalendar.
*
* Input Parameters:
* None
*
* Security:
* User must be an admin user
* AND, if user access control is enabled, they must have access to
* 'Security Audit'.
*/
include_once 'includes/init.php';
if (!$is_admin || (access_is_enabled()
&& !access_can_access_function(ACCESS_SECURITY_AUDIT))) {
die_miserable_death(print_not_auth());
}
$phpinfo = getGetValue('phpinfo');
if ($phpinfo == '1') {
print_header('', '', '', true);
phpinfo();
print_trailer(false, true, true);
exit;
}
clearstatcache();
print_header();
?>
<h2><?php etranslate('Security Audit'); ?></h2>
<div>
<?php etranslate('list potential security issues'); ?>
</div>
<div><a class="btn btn-secondary mt-2 text-right" href="#" onclick="window.open('security_audit.php?phpinfo=1', 'phpinfo',
'dependent,menubar,scrollbars,height=500,width=600,innerHeight=520,outerWidth=620')"><?php etranslate('View your current PHP settings'); ?>...</a>
</div>
<table class="table table-striped mt-2 table-responsive" id="securityAudit">
<thead>
<tr>
<th scope="col"><?php etranslate('Security Issue'); ?></th>
<th scope="col"><?php etranslate('Status'); ?></th>
<th scope="col"><?php etranslate('Details'); ?></th>
</tr>
</thead>
<?php
// Make sure they aren't still using the default admin username/password.
print_issue(
translate('Default admin user password'),
(user_valid_login('admin', 'admin') == false),
translate('You should change the password of the default admin user.')
);
// Is the main directory still writable?
// Just see if we get an error trying to append to it.
$wcDir = '.';
$wcName = 'WebCalendar toplevel director';
if (preg_match('/(.*).security_audit.php/', __FILE__, $matches)) {
//$wcDir = $matches[1] . '\\';
$wcName = basename(realpath($wcDir));
}
$filePerms = translate('File permissions XXX');
$noWriteItem = translate('item XXX should not be writable');
print_issue(
str_replace('XXX', $wcName, $filePerms),
(!is__writable($wcDir)),
str_replace('XXX', htmlentities(realpath($wcDir)), $noWriteItem)
);
// Is the includes directory still writable?
// Just see if we get an error trying to append to it.
print_issue(
str_replace('XXX', 'includes', $filePerms),
(!is__writable('includes')),
str_replace('XXX', get_wc_path('includes'), $noWriteItem)
);
// Is the includes/settings.php file still writable?
// Unfortunately, some of the PHP file permissions calls have bugs,
// so just see if we get an error trying to append to it.
$fd = @fopen('includes/settings.php', 'a+b');
$isOk = true;
if ($fd > 0) {
// Error: should not be allowed to write!
fclose($fd);
$isOk = false;
}
print_issue(
str_replace('XXX', 'includes/settings.php', $filePerms),
$isOk,
str_replace('XXX', get_wc_path('includes/settings.php'), $noWriteItem)
);
// If email or reminders are not enabled, tell them to remove the file.
$isOk = (!file_exists('tools/send_reminders.php'));
if ($SEND_EMAIL != 'Y') {
// Reminders are disabled!
print_issue(
str_replace(
'XXX',
'tools/send_reminders.php',
translate('File exists XXX')
),
$isOk,
translate('Because you have email disabled, you should remove this file.')
);
} else {
// Is tools/send_reminders.php in the 'standard' location?
print_issue(
str_replace(
'XXX',
'tools/send_reminders.php',
translate('File location XXX')
),
$isOk,
str_replace(
'XXX',
get_wc_path('tools/send_reminders.php'),
translate('remove XXX if not using')
)
);
}
$sysSettingsXXX = translate('System Settings XXX');
// Is UAC enabled?
print_issue(
str_replace('XXX', translate('User Access Control'), $sysSettingsXXX),
access_is_enabled(),
translate('consider enabling UAC')
);
// If Public Access enabled, make sure approvals are on
if ($PUBLIC_ACCESS == 'Y') {
print_issue(
str_replace(
'XXX',
translate('Public access new events require approval'),
$sysSettingsXXX
),
($PUBLIC_ACCESS_CAN_ADD != 'Y' || $PUBLIC_ACCESS_ADD_NEEDS_APPROVAL == 'Y'),
translate('recommend approving new public events')
);
print_issue(
str_replace(
'XXX',
translate('Require CAPTCHA validation for public access new events'),
$sysSettingsXXX
),
($ENABLE_CAPTCHA == 'Y'),
translate('recommend using CAPTCHA')
);
}
// Is db cache directory a subdirectory of WebCalendar?
$isOk = true;
if (!empty($settings['db_cachedir']) && $wcDir != '.') {
$cache = str_replace('\\', '/', $settings['db_cachedir']);
$wcDir = str_replace('\\', '/', $wcDir);
if (
strncmp($cache, $wcDir, strlen($wcDir)) == 0
&& strlen($wcDir) < strlen($cache)
) {
// Using a webcalendar subdirectory for db cache.
$isOk = false;
}
}
print_issue(
translate('Database cache directory location'),
$isOk,
translate('db cache should be inaccessable')
);
$phpSettingsXXX = translate('PHP Settings XXX');
$recommendXXXOff = translate('recommend setting XXX Off');
$recommendXXXOn = translate('recommend setting XXX On');
// Check for expose_php.
print_issue(
str_replace('XXX', 'expose_php', $phpSettingsXXX),
(ini_get('expose_php') == 0),
str_replace('XXX', 'expose_php', $recommendXXXOff)
);
// Check for register globals.
print_issue(
str_replace('XXX', 'register_globals', $phpSettingsXXX),
(ini_get('register_globals') == 0),
str_replace('XXX', 'register_globals', $recommendXXXOff)
);
// Check for allow_url_fopen.
// Recommended setting is off when remote calendars are not enabled.
print_issue(
str_replace('XXX', 'allow_url_fopen', $phpSettingsXXX),
(ini_get('allow_url_fopen') == 0 || $REMOTES_ENABLED == 'Y'),
translate('recommend setting allow_url_fopen Off')
);
// Check for allow_url_include.
print_issue(
str_replace('XXX', 'allow_url_include', $phpSettingsXXX),
(ini_get('allow_url_include') == 0),
str_replace('XXX', 'allow_url_include', $recommendXXXOff)
);
// Don't display PHP errors/warnings to end users through the browser.
// (But this is okay for developer settings...)
print_issue(
str_replace('XXX', 'display_errors', $phpSettingsXXX),
(ini_get('display_errors') == 0),
str_replace('XXX', 'display_errors', $recommendXXXOff)
);
// PHP errors/warnings should be logged.
print_issue(
str_replace('XXX', 'log_errors', $phpSettingsXXX),
(ini_get('log_errors') == 1),
str_replace('XXX', 'log_errors', $recommendXXXOn)
);
// PHP session security.
print_issue(
str_replace('XXX', 'session.use_strict_mode', $phpSettingsXXX),
(ini_get('session.use_strict_mode') == 1),
str_replace('XXX', 'session.use_strict_mode', $recommendXXXOn)
);
print_issue(
str_replace('XXX', 'session.cookie_httponly', $phpSettingsXXX),
(ini_get('session.cookie_httponly') == 1),
str_replace('XXX', 'session.cookie_httponly', $recommendXXXOn)
);
?>
</table>
<?php
echo print_trailer();
exit;
/* functions ... */
/**
* print_issue (needs description)
*/
function print_issue($description, $isOk, $help)
{
if ($isOk) {
$img = '<img class="button-icon-inverse" src="images/bootstrap-icons/check-circle.svg" />';
$help = ' ';
} else {
$img = '<img class="button-icon-inverse" src="images/bootstrap-icons/exclamation-triangle-fill.svg" />';
}
echo '<tr><td>' . $description . '</td>' .
'<td>' . $img . '</td>' .
'<td>' . $help . '</td></tr>' . "\n";
}
/**
* Get the full path to a file located in the webcalendar directory.
*/
function get_wc_path($filename)
{
if (preg_match('/(.*)security_audit.php/', __FILE__, $matches))
return $matches[1] . $filename;
else
// Oops. This file is not named security_audit.php
die_miserable_death('Crap! Someone renamed security_audit.php');
}
/**
* Determine if a directory or file is writable
*/
function is__writable($path)
{
//Will work despite Windows ACLs bug.
//NOTE: use a trailing slash for folders!!!
//see http://bugs.php.net/bug.php?id=27609
//see http://bugs.php.net/bug.php?id=30931
if ($path[strlen($path) - 1] == '/') // recursively return a temporary file path
return is__writable($path . uniqid(mt_rand()) . '.tmp');
else if (@is_dir($path))
return is__writable($path . '/' . uniqid(mt_rand()) . '.tmp');
// Check tmp file for read/write capabilities.
$rm = @file_exists($path);
$f = @fopen($path, 'a');
if ($f === false)
return false;
@fclose($f);
if (!$rm)
@unlink($path);
return true;
}
?>