-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecurity-check.php
191 lines (181 loc) · 7.77 KB
/
security-check.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
<?php
/*
Secure Yor PHP
Version 0.1
Copyright (C) 2015 Jorge Matricali
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
ini_set('display_errors', 1);
function disabled_functions()
{
static $disabled_fn;
if ($disabled_fn === null) {
$df = ini_get('disable_functions');
$shfb = ini_get('suhosin.executor.func.blacklist');
$fn_list = array_map('trim', explode(',', "$df,$shfb"));
$disabled_fn = array_filter($fn_list, create_function('$value', 'return $value !== "";'));
}
return $disabled_fn;
}
$security_checks = array(
'Loaded Extensions' => function () {
return implode(', ', get_loaded_extensions());
},
'Running platform' => function () {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return 'You\'re running PHP under Windows!';
} else {
return PHP_OS;
}
},
'Webserver software' => function () {
return $_SERVER['SERVER_SOFTWARE'];
},
'PHP Version' => function () {
return phpversion();
},
'Version check' => function () {
return version_compare(phpversion(), '5.3.10', '>');
},
'PHP configuration file' => function () {
if ($ini_file = php_ini_loaded_file()) {
return $ini_file;
}
return 'No configuration file has been loaded.';
},
'safe_mode' => function () {
if (version_compare(phpversion(), '5.3.0', '>')) {
// safe_mode has been declared as OBSOLETE since 5.3.0 and DELETED from 5.4.0
return true;
}
return ini_get('safe_mode');
},
'PHP Information leakage (Version)' => function () {
return empty(ini_get('expose_php'));
},
'PHP Information leakage (Logs)' => function () {
return ini_get('display_errors') == 1;
},
'Can view /etc/passwd' => function () {
return !is_readable('/etc/passwd');
},
'Can view /etc/shadow' => function () {
return !is_readable('/etc/shadow');
},
'Command execution via "system" function' => function () {
return in_array('system', disabled_functions()) || !is_callable('system');
},
'Command execution via "shell_exec" function' => function () {
return in_array('shell_exec', disabled_functions()) || !is_callable('shell_exec');
},
'Command execution via "exec" function' => function () {
return in_array('exec', disabled_functions()) || !is_callable('exec');
},
'Command execution via "passthru" function' => function () {
return in_array('passthru', disabled_functions()) || !is_callable('passthru');
},
'Command execution via "proc_open" function' => function () {
return in_array('proc_open', disabled_functions()) || !is_callable('proc_open');
},
'Command execution via "popen" function' => function () {
return in_array('popen', disabled_functions()) || !is_callable('popen');
},
'Command execution via "preg_replace" function' => function () {
// The "e" modifier has been decalres as OBSOLETE since 5.5.0
return empty(@preg_replace("/.*/e","`pwd`", ""));
} ,
'Kill unix processes via "posix_kill" function' => function () {
return in_array('posix_kill', disabled_functions()) || !is_callable('posix_kill');
},
'Remote file inclusion via "file_get_contents" function' => function () {
$g = @file_get_contents('http://google.com/');
return empty($g);
},
'Remote file inclusion via "include" statement' => function () {
$g = @include('http://google.com/');
return empty($g);
}
);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Secure your PHP v0.1</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
.footer {
text-align: center;
padding-top: 1.5rem;
color: #777;
border-top: .05rem solid #e5e5e5;
padding-bottom: 2em;
}
.footer-icons {
top: 4px;
position: relative;
}
</style>
</head>
<body>
<div class="container">
<h1 class="page-header">Secure your PHP v0.1</h1>
<div class="table-responsive">
<table class="table table-bordered" border="1">
<thead><tr><th>Check</th><th>Status</th></tr></thead>
<tbody>
<?php
foreach ($security_checks as $security_check => $func) {
if (is_callable($func)) {
$ret = $func();
echo '<tr><td>', $security_check, '</td>';
echo '<td>';
if (!$ret) {
echo '<i class="glyphicon glyphicon-remove"></i> <span class="text-danger">VULNERABLE</span>';
} elseif ($ret === true) {
echo '<i class="glyphicon glyphicon-ok"></i> <span class="text-success">PASSED</span>';
} else {
echo $ret;
}
echo '</td></tr>';
}
}
?>
</tbody>
</table>
</div>
<footer class="footer">
Secure your PHP v0.1 <span class="text-muted">© Copyright 2015 Jorge Matricali</span> -
<span class="footer-icons">
<!-- Place this tag where you want the button to render. -->
<a class="github-button" href="https://github.com/jorge-matricali/secure-your-php" data-icon="octicon-star" data-show-count="true" aria-label="Star jorge-matricali/secure-your-php on GitHub">Star</a>
<!-- Place this tag where you want the button to render. -->
<a class="github-button" href="https://github.com/jorge-matricali/secure-your-php/fork" data-icon="octicon-repo-forked" data-show-count="true" aria-label="Fork jorge-matricali/secure-your-php on GitHub">Fork</a>
<!-- Place this tag where you want the button to render. -->
<a class="github-button" href="https://github.com/jorge-matricali/secure-your-php/issues" data-icon="octicon-issue-opened" data-show-count="true" aria-label="Issue jorge-matricali/secure-your-php on GitHub">Issue</a>
<!-- Place this tag where you want the button to render. -->
<a class="github-button" href="https://github.com/jorge-matricali/secure-your-php/archive/master.zip" data-icon="octicon-cloud-download" aria-label="Download jorge-matricali/secure-your-php on GitHub">Download</a>
</span>
</footer>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
</body>
</html>