-
Notifications
You must be signed in to change notification settings - Fork 30
/
settings-hardening.php
627 lines (538 loc) · 25.6 KB
/
settings-hardening.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
<?php
/**
* Code related to the settings-hardening.php interface.
*
* @package Sucuri Security
* @subpackage settings-hardening.php
* @copyright Since 2010 Sucuri Inc.
*/
if (!defined('SUCURISCAN_INIT') || SUCURISCAN_INIT !== true) {
if (!headers_sent()) {
/* Report invalid access if possible. */
header('HTTP/1.1 403 Forbidden');
}
exit(1);
}
/**
* Renders the content of the plugin's hardening page.
*/
class SucuriScanHardeningPage extends SucuriScan
{
/**
* Generate the HTML code necessary to show a form with the options to harden
* a specific part of the WordPress installation, if the Status variable is
* set as a positive integer the button is shown as "unharden".
*
* @param array $args Array with template variables to replace.
* @return string HTML code with the replaced template variables.
*/
private static function drawSection($args = array())
{
$params = array();
$params['Hardening.Title'] = '';
$params['Hardening.Status'] = '';
$params['Hardening.FieldName'] = '';
$params['Hardening.FieldText'] = '';
$params['Hardening.FieldAttrs'] = '';
$params['Hardening.Description'] = '';
foreach ($args as $keyname => $value) {
$params[$keyname] = $value;
}
if (!empty($params['Hardening.FieldName'])) {
$params['Hardening.FieldName'] = sprintf(
'%s_hardening_%s',
SUCURISCAN,
$params['Hardening.FieldName']
);
}
return SucuriScanTemplate::getSnippet('settings-hardening-options', $params);
}
/**
* Checks if the request has a valid nonce to prevent a CSRF.
*
* @param string $function Name of the action that was executed.
* @return bool True if the request has a valid CSRF protection.
*/
private static function processRequest($function)
{
return (bool) (
SucuriScanInterface::checkNonce() /* CSRF protection */
&& SucuriScanRequest::post(':hardening_' . $function)
);
}
/**
* Checks if the Firewall service is enabled and configured.
*
* WAF is a protection layer for your web site, blocking all sort of attacks
* (brute force attempts, DDoS, SQL injections, etc) and helping it remain
* malware and blacklist free. This test checks if your site is using Sucuri
* Firewall to protect your site.
*/
public static function firewall()
{
$params = array();
if (self::processRequest(__FUNCTION__)) {
SucuriScanInterface::error(__('HardeningFirewallPurchase', SUCURISCAN_TEXTDOMAIN));
}
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.Title'] = __('HardeningFirewallTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningFirewallDescription', SUCURISCAN_TEXTDOMAIN);
if (!SucuriScan::isBehindFirewall()) {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
}
return self::drawSection($params);
}
/**
* Checks if the WordPress version is the latest available.
*
* Why keep your site updated? WordPress is an open-source project which
* means that with every update the details of the changes made to the
* source code are made public, if there were security fixes then someone
* with malicious intent can use this information to attack any site that
* has not been upgraded.
*/
public static function wpversion()
{
$params = array();
$updates = get_core_updates();
$site_version = SucuriScan::siteVersion();
$params['URL.Settings'] = admin_url('update-core.php');
$params['Hardening.Status'] = 0;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Title'] = __('HardeningVersionTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningVersionDescription', SUCURISCAN_TEXTDOMAIN);
if (isset($updates[0]) && $updates[0] instanceof stdClass) {
if ($updates[0]->response == 'latest' || $updates[0]->response == 'development') {
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.Status'] = 1;
}
}
return self::drawSection($params);
}
/**
* Checks if the server is using a modern PHP version.
*
* Each release branch of PHP is fully supported for two years from its
* initial stable release. During this period, bugs and security issues that
* have been reported are fixed and are released in regular point releases.
* After this two year period of active support, each branch is then
* supported for an additional year for critical security issues only.
* Releases during this period are made on an as-needed basis: there may be
* multiple point releases, or none, depending on the number of reports.
* Once the three years of support are completed, the branch reaches its end
* of life and is no longer supported.
*
* @see http://php.net/supported-versions.php
*/
public static function phpversion()
{
$params = array();
if (self::processRequest(__FUNCTION__)) {
SucuriScanInterface::error(__('HardeningPHPVersionLifetime', SUCURISCAN_TEXTDOMAIN));
}
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.Title'] = __('HardeningPHPVersionTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = sprintf(__('HardeningPHPVersionDescription', SUCURISCAN_TEXTDOMAIN), PHP_VERSION);
if (intval(version_compare(PHP_VERSION, '5.6.0') >= 0)) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
}
return self::drawSection($params);
}
/**
* Notify the state of the hardening for the removal of the Generator tag in
* HTML code printed by WordPress to show the current version number of the
* installation.
*/
public static function wpgenerator()
{
$params = array();
$params['Hardening.Title'] = __('HardeningGeneratorTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Status'] = 1;
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.Description'] = __('HardeningGeneratorDescription', SUCURISCAN_TEXTDOMAIN);
return self::drawSection($params);
}
/**
* Offers information to apply a hardening to an Nginx installation.
*/
public static function nginxphp()
{
if (!SucuriScan::isNginxServer()) {
return ''; /* empty page */
}
$params = array();
if (self::processRequest(__FUNCTION__)) {
SucuriScanInterface::error(__('HardeningNginxSuggestion', SUCURISCAN_TEXTDOMAIN));
}
$params['Hardening.Title'] = __('HardeningNginxTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Status'] = 2;
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.FieldText'] = __('HardeningNginxField', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningNginxDescription', SUCURISCAN_TEXTDOMAIN);
return self::drawSection($params);
}
/**
* Check whether the WordPress upload folder is protected or not.
*
* A htaccess file is placed in the upload folder denying the access to any php
* file that could be uploaded through a vulnerability in a Plugin, Theme or
* WordPress itself.
*/
public static function wpuploads()
{
if (SucuriScan::isNginxServer() || SucuriScan::isIISServer()) {
return ''; /* empty page */
}
$params = array();
$folder = WP_CONTENT_DIR . '/uploads';
if (self::processRequest(__FUNCTION__)) {
$result = SucuriScanHardening::hardenDirectory($folder);
if ($result === true) {
SucuriScanEvent::reportNoticeEvent('Hardening applied to the uploads directory');
SucuriScanInterface::info(__('HardeningUploadsApplySuccess', SUCURISCAN_TEXTDOMAIN));
} else {
SucuriScanInterface::error(__('HardeningUploadsApplyFailure', SUCURISCAN_TEXTDOMAIN));
}
}
if (self::processRequest(__FUNCTION__ . '_revert')) {
$result = SucuriScanHardening::unhardenDirectory($folder);
if ($result === true) {
SucuriScanEvent::reportErrorEvent('Hardening reverted in the uploads directory');
SucuriScanInterface::info(__('HardeningUploadsRevertSuccess', SUCURISCAN_TEXTDOMAIN));
} else {
SucuriScanInterface::error(__('HardeningUploadsRevertFailure', SUCURISCAN_TEXTDOMAIN));
}
}
$params['Hardening.Title'] = __('HardeningUploadsTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningUploadsDescription', SUCURISCAN_TEXTDOMAIN);
if (SucuriScan::isBehindFirewall()) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} elseif (SucuriScanHardening::isHardened($folder)) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldName'] = __FUNCTION__ . '_revert';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
}
return self::drawSection($params);
}
/**
* Check whether the WordPress content folder is protected or not.
*
* A htaccess file is placed in the content folder denying the access to any php
* file that could be uploaded through a vulnerability in a Plugin, Theme or
* WordPress itself.
*/
public static function wpcontent()
{
if (SucuriScan::isNginxServer() || SucuriScan::isIISServer()) {
return ''; /* empty page */
}
$params = array();
if (self::processRequest(__FUNCTION__)) {
$result = SucuriScanHardening::hardenDirectory(WP_CONTENT_DIR);
if ($result === true) {
SucuriScanEvent::reportNoticeEvent('Hardening applied to the content directory');
SucuriScanInterface::info(__('HardeningContentApplySuccess', SUCURISCAN_TEXTDOMAIN));
} else {
SucuriScanInterface::error(__('HardeningContentApplyFailure', SUCURISCAN_TEXTDOMAIN));
}
}
if (self::processRequest(__FUNCTION__ . '_revert')) {
$result = SucuriScanHardening::unhardenDirectory(WP_CONTENT_DIR);
if ($result === true) {
SucuriScanEvent::reportErrorEvent('Hardening reverted in the content directory');
SucuriScanInterface::info(__('HardeningContentRevertSuccess', SUCURISCAN_TEXTDOMAIN));
} else {
SucuriScanInterface::error(__('HardeningContentRevertFailure', SUCURISCAN_TEXTDOMAIN));
}
}
$params['Hardening.Title'] = __('HardeningContentTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningContentDescription', SUCURISCAN_TEXTDOMAIN);
if (SucuriScan::isBehindFirewall()) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} elseif (SucuriScanHardening::isHardened(WP_CONTENT_DIR)) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldName'] = __FUNCTION__ . '_revert';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
}
return self::drawSection($params);
}
/**
* Check whether the WordPress includes folder is protected or not.
*
* A htaccess file is placed in the includes folder denying the access to any php
* file that could be uploaded through a vulnerability in a Plugin, Theme or
* WordPress itself, there are some exceptions for some specific files that must
* be available publicly.
*/
public static function wpincludes()
{
if (SucuriScan::isNginxServer() || SucuriScan::isIISServer()) {
return ''; /* empty page */
}
$params = array();
$folder = ABSPATH . '/wp-includes';
if (self::processRequest(__FUNCTION__)) {
$result = SucuriScanHardening::hardenDirectory($folder);
if ($result === true) {
try {
SucuriScanHardening::whitelist('wp-tinymce.php', 'wp-includes');
SucuriScanHardening::whitelist('ms-files.php', 'wp-includes');
SucuriScanEvent::reportNoticeEvent('Hardening applied to the library directory');
SucuriScanInterface::info(__('HardeningIncludesApplySuccess', SUCURISCAN_TEXTDOMAIN));
} catch (Exception $e) {
SucuriScanInterface::error($e->getMessage());
}
} else {
SucuriScanInterface::error(__('HardeningIncludesApplyFailure', SUCURISCAN_TEXTDOMAIN));
}
}
if (self::processRequest(__FUNCTION__ . '_revert')) {
$result = SucuriScanHardening::unhardenDirectory($folder);
if ($result === true) {
SucuriScanHardening::dewhitelist('wp-tinymce.php', 'wp-includes');
SucuriScanHardening::dewhitelist('ms-files.php', 'wp-includes');
SucuriScanEvent::reportErrorEvent('Hardening reverted in the library directory');
SucuriScanInterface::info(__('HardeningIncludesRevertSuccess', SUCURISCAN_TEXTDOMAIN));
} else {
SucuriScanInterface::error(__('HardeningIncludesRevertFailure', SUCURISCAN_TEXTDOMAIN));
}
}
$params['Hardening.Title'] = __('HardeningIncludesTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningIncludesDescription', SUCURISCAN_TEXTDOMAIN);
if (SucuriScan::isBehindFirewall()) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} elseif (SucuriScanHardening::isHardened($folder)) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldName'] = __FUNCTION__ . '_revert';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
}
return self::drawSection($params);
}
/**
* Check whether the "readme.html" file is still available in the root of the
* site or not, which can lead to an attacker to know which version number of
* Wordpress is being used and search for possible vulnerabilities.
*/
public static function readme()
{
$params = array();
// TODO: Create an option to automatically delete this after WP upgrade.
if (self::processRequest(__FUNCTION__)) {
if (@unlink(ABSPATH . '/readme.html') === false) {
SucuriScanInterface::error(sprintf(
__('HardeningReadmeApplyFailure', SUCURISCAN_TEXTDOMAIN),
ABSPATH /* root of the WordPress installation */
));
} else {
SucuriScanEvent::reportNoticeEvent('Hardening applied to the <code>readme.html</code> file');
SucuriScanInterface::info(__('HardeningReadmeApplySuccess', SUCURISCAN_TEXTDOMAIN));
}
}
$params['Hardening.Title'] = __('HardeningReadmeTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningReadmeDescription', SUCURISCAN_TEXTDOMAIN);
if (file_exists(ABSPATH . '/readme.html')) {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.FieldAttrs'] = 'disabled';
}
return self::drawSection($params);
}
/**
* Check whether the main administrator user still has the default name "admin"
* or not, which can lead to an attacker to perform a brute force attack.
*/
public static function adminuser()
{
$params = array();
$user_query = new WP_User_Query(array(
'search' => 'admin',
'fields' => array('ID', 'user_login'),
'search_columns' => array('user_login'),
));
$results = $user_query->get_results();
$params['URL.Settings'] = admin_url('users.php?role=administrator');
$params['Hardening.Title'] = __('HardeningAdminUserTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningAdminUserDescription', SUCURISCAN_TEXTDOMAIN);
if (count($results) === 0) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldAttrs'] = 'disabled';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
}
return self::drawSection($params);
}
/**
* Enable or disable the user of the built-in Wordpress file editor.
*/
public static function fileeditor()
{
$params = array();
$fileEditorWasDisabled = (bool) (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT);
if (self::processRequest(__FUNCTION__)) {
$config = SucuriScan::getWPConfigPath();
if (!$config) {
SucuriScanInterface::error(__('ConfigNotFound', SUCURISCAN_TEXTDOMAIN));
} elseif (!is_writable($config)) {
SucuriScanInterface::error(__('ConfigNotWritable', SUCURISCAN_TEXTDOMAIN));
} else {
$content = SucuriScanFileInfo::fileContent($config);
$lines = explode("\n", $content);
$newlines = array();
foreach ($lines as $line) {
if (strpos($line, 'DB_COLLATE') === false) {
$newlines[] = $line;
continue;
}
$newlines[] = $line; /* add current line */
$newlines[] = ''; /* add line separator */
$newlines[] = "define('DISALLOW_FILE_EDIT', true);";
}
$fileEditorWasDisabled = true;
$content = implode("\n", $newlines);
@file_put_contents($config, $content, LOCK_EX);
SucuriScanEvent::reportNoticeEvent('Hardening applied to the plugin and theme editor');
SucuriScanInterface::info(__('HardeningFileEditorApplySuccess', SUCURISCAN_TEXTDOMAIN));
}
}
if (self::processRequest(__FUNCTION__ . '_revert')) {
$config = SucuriScan::getWPConfigPath();
if (!$config) {
SucuriScanInterface::error(__('ConfigNotFound', SUCURISCAN_TEXTDOMAIN));
} elseif (!is_writable($config)) {
SucuriScanInterface::error(__('ConfigNotWritable', SUCURISCAN_TEXTDOMAIN));
} else {
$content = SucuriScanFileInfo::fileContent($config);
$lines = explode("\n", $content);
$hardeningWasReverted = false;
$newlines = array();
foreach ($lines as $line) {
if (strpos($line, 'DISALLOW_FILE_EDIT') !== false) {
$hardeningWasReverted = true;
continue; /* remove the constant from the file */
}
$newlines[] = $line; /* add current line */
}
if (!$hardeningWasReverted) {
SucuriScanInterface::error(__('HardeningFileEditorRevertFailure', SUCURISCAN_TEXTDOMAIN));
} else {
$fileEditorWasDisabled = false;
$content = implode("\n", $newlines);
@file_put_contents($config, $content, LOCK_EX);
SucuriScanEvent::reportErrorEvent('Hardening reverted in the plugin and theme editor');
SucuriScanInterface::info(__('HardeningFileEditorRevertSuccess', SUCURISCAN_TEXTDOMAIN));
}
}
}
$params['Hardening.Title'] = __('HardeningFileEditorTitle', SUCURISCAN_TEXTDOMAIN);
$params['Hardening.Description'] = __('HardeningFileEditorDescription', SUCURISCAN_TEXTDOMAIN);
if ($fileEditorWasDisabled) {
$params['Hardening.Status'] = 1;
$params['Hardening.FieldName'] = __FUNCTION__ . '_revert';
$params['Hardening.FieldText'] = __('RevertHardening', SUCURISCAN_TEXTDOMAIN);
} else {
$params['Hardening.Status'] = 0;
$params['Hardening.FieldName'] = __FUNCTION__;
$params['Hardening.FieldText'] = __('ApplyHardening', SUCURISCAN_TEXTDOMAIN);
}
return self::drawSection($params);
}
/**
* Whitelist individual PHP files.
*
* Allows an admin to whitelist individual PHP files after the directory has
* been hardened. Since the hardening rules denies access to all PHP files
* contained in such directory, 3rd-party plugins and themes that makes use
* of these direct requests will stop working. The admins will want to allow
* direct access to certain PHP files.
*/
public static function whitelistPHPFiles()
{
$params = array(
'HardeningWhitelist.List' => '',
'HardeningWhitelist.NoItemsVisibility' => 'visible',
);
$allowed_folders = array(
'wp-includes',
'wp-content',
'wp-content/uploads',
);
if (SucuriScanInterface::checkNonce()) {
// Add a new file to the hardening whitelist.
if ($fwhite = SucuriScanRequest::post(':hardening_whitelist')) {
$folder = SucuriScanRequest::post(':hardening_folder');
if (in_array($folder, $allowed_folders)) {
try {
SucuriScanHardening::whitelist($fwhite, $folder);
SucuriScanInterface::info(__('PHPWhitelistSuccess', SUCURISCAN_TEXTDOMAIN));
} catch (Exception $e) {
SucuriScanInterface::error($e->getMessage());
}
} else {
SucuriScanInterface::error(__('PHPWhitelistFailure', SUCURISCAN_TEXTDOMAIN));
}
}
// Remove a file from the hardening whitelist.
if ($rmfwhite = SucuriScanRequest::post(':hardening_rmfwhite', '_array')) {
foreach ($rmfwhite as $fpath) {
$fpath = str_replace('/.*/', '|', $fpath);
$parts = explode('|', $fpath, 2);
SucuriScanHardening::dewhitelist($parts[1], $parts[0]);
}
SucuriScanInterface::info(__('PHPDewhitelistSuccess', SUCURISCAN_TEXTDOMAIN));
}
}
// Read the access control file and retrieve the whitelisted files.
foreach ($allowed_folders as $folder) {
if ($files = SucuriScanHardening::getWhitelisted($folder)) {
$params['HardeningWhitelist.NoItemsVisibility'] = 'hidden';
foreach ($files as $file) {
$fregexp = sprintf('%s/.*/%s', $folder, $file);
$html = SucuriScanTemplate::getSnippet('settings-hardening-whitelist-phpfiles', array(
'HardeningWhitelist.Regexp' => $fregexp,
'HardeningWhitelist.Folder' => $folder,
'HardeningWhitelist.File' => $file,
));
$params['HardeningWhitelist.List'] .= $html;
}
}
}
return SucuriScanTemplate::getSection('settings-hardening-whitelist-phpfiles', $params);
}
}