forked from RaymiiOrg/ssl-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
258 lines (236 loc) · 10.6 KB
/
index.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
<!--
Copyright (C) 2015 Remy van Elst
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<?php
error_reporting(E_ALL & ~E_NOTICE);
ob_start();
$write_cache = 0;
foreach (glob("functions/*.php") as $filename) {
include $filename;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SSL Decoder</title>
<link rel="stylesheet" href="<?php echo(htmlspecialchars($current_folder)); ?>css/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo(htmlspecialchars($current_folder)); ?>css/ssl.css">
<script src="<?php echo(htmlspecialchars($current_folder)); ?>js/jquery.min.js"></script>
<script src="<?php echo(htmlspecialchars($current_folder)); ?>js/bootstrap.min.js"></script>
<script src="<?php echo(htmlspecialchars($current_folder)); ?>js/ajax.js"></script>
</head>
<body>
<a id="top-of-page"></a>
<?php
if ( isset($_GET['host']) && !empty($_GET['host'])) {
echo '<div id="wrapper">';
$data = [];
$hostname = mb_strtolower(get($_GET['host']));
$hostname = parse_hostname($hostname);
$host = $hostname['hostname'];
$port = get($_GET['port'], '443');
if ( !is_numeric($port) ) {
$port = 443;
}
if ($hostname['multiple_ip']) {
choose_endpoint($hostname['multiple_ip'], $host, $port, $_GET['fastcheck']);
}
if($_GET['fastcheck'] == 1) {
$fastcheck = 1;
} else {
$fastcheck = 0;
}
$ip = $hostname['ip'];
$data["data"] = check_json($host,$ip,$port,$fastcheck);
if(isset($data["data"]["error"])) {
$data["error"] = $data["data"]["error"];
unset($data["data"]);
}
$chain_length = count($data["data"]["chain"]);
$chain_data = $data["data"]["chain"];
if ($chain_length >= 1 && $chain_length < 10) {
?>
<!-- Sidebar -->
<div id="sidebar-wrapper">
<nav>
<ul class="sidebar-nav">
<br>
<li class="sidebar-brand">
<h2>Navigation</h2>
</li>
<?php
if (count($data["data"]["connection"]["warning"]) >= 1) {
$warntxt = " <sup>(<strong>".htmlspecialchars(count(array_unique($data["data"]["connection"]["warning"])))."</strong>)</sup>";
}
?>
<li><a href="#conndata"><strong>0</strong>: Connection Data <?php echo $warntxt; $warntxt = ''; ?></a></li>
<?php
$menucount = 1;
foreach ($chain_data as $key => $value) {
if (count($value['warning']) >= 1) {
$warntxt = " <sup>(<strong>".htmlspecialchars(count($value['warning']))."</strong>)</sup>";
}
echo "<li><a href='#cert".(string)$key."'><strong>".htmlspecialchars($key)."</strong> : ". htmlspecialchars($value["cert_data"]["subject"]["CN"]) . $warntxt . "</a></li>";
$warntxt = "";
$menucount += 1;
}
if ($_GET['fastcheck'] == 0) {
?>
<li><a href="#ctsubmit"><strong><?php echo htmlspecialchars($menucount); ?></strong> : Certificate Transparency</a></li>
<?php
}
?>
<li><a href="<?php echo(htmlspecialchars($current_folder)); ?>">Try another website</a></li>
<li><hr></li>
<li><a href="https://certificatemonitor.org/">Certificate Expiry Monitor</a></li>
<li><a href="https://cipherli.st/">Strong Cipherlists</a></li>
<li><a href="https://raymii.org/s/tutorials/Strong_SSL_Security_On_Apache2.html">Apache SSL Tutorial</a></li>
<li><a href="https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html">NGINX SSL Tutorial</a></li>
<li><a href="https://raymii.org/s/tutorials/Strong_SSL_Security_On_lighttpd.html">Lighttpd SSL Tutorial</a></li>
<li><a href="https://raymii.org">Raymii.org</a></li>
</ul>
</nav>
</div>
<!-- /#sidebar-wrapper -->
<?php
}
}
if (empty($_GET['host']) && empty($_GET['csr'])) {
require_once("inc/form.php");
} else {
echo "<div id='page-content-wrapper'>";
echo "<div class='container-fluid'>";
echo "<div class='row'>";
// if ajax-ed, don't show header again
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
echo "<div class='col-md-10 col-md-offset-1'>";
echo "<div class='page-header'>";
echo "<h1><a style='color:black;' href=\"";
echo(htmlspecialchars($current_folder));
echo "\">SSL Decoder</a></h1>";
echo "</div>";
// set back to 1 after debugging
$write_cache = 1;
if (!is_dir('results')) {
mkdir('results');
}
$epoch = date('U');
$random_bla = md5(uniqid(rand(), true));
}
if ( !empty($host) ) {
if ( !empty($data["error"]) ) {
echo "<span class='text-danger'>" . htmlspecialchars($data["error"][0]) . "</span>";
echo "<hr>";
$write_cache = 0;
} else {
$hostfilename = preg_replace("([^\w\s\d\-_~,;:\[\]\(\).])", '', $host);
$hostfilename = preg_replace("([\.]{2,})", '', $host);
$hostfilename = preg_replace("([^a-z0-9])", '', $host);
$cache_filename = (string) "results/saved." . $hostfilename . "." . $epoch . "." . $random_bla . ".html";
$cache_filename_json = (string) "results/saved." . $hostfilename . "." . $epoch . "." . $random_bla . ".json";
echo "<p><strong>This tool does not make conclusions. Please check the data and define the validity yourself!</strong></p>";
if ($write_cache == 1) {
echo "<p>This result is saved at most 60 days on <a href=\"";
echo(htmlspecialchars($current_folder) . $cache_filename);
echo "\">the following URL</a>. Do note that this might be deleted earlier if space runs out.<br></p>";
}
echo "<script type='text/javascript'>document.title = \"" . htmlspecialchars($host) . ":" . htmlspecialchars($port) . " - SSL Decoder \"</script>";
echo "<p>Receive notifications when this certificate is about to expire with my other service, <a href='https://certificatemonitor.org/'>Certificate Monitor</a>.</p>";
// connection data
echo "<div class='content'><section id='conndata'>";
echo "<header><h2>Connection Data for " . htmlspecialchars($host) . " / " . htmlspecialchars($ip) . "</h2></header>";
ssl_conn_metadata($data["data"]["connection"], $fastcheck);
if ($_GET['fastcheck'] == 1) {
echo "<p>Fast check selected, therefore Connection Data enumeration is limited.</p>";
}
echo "</section></div>";
// certificates
foreach ($data["data"]["chain"] as $key => $value) {
echo "<div class='content'><section id='cert" . $key . "'>";
echo "<header><h2>Certificate for '". htmlspecialchars($value["cert_data"]["subject"]["CN"]) ."'</h2></header>";
cert_parse($value);
echo "</section></div>";
}
// submit to certificate transparency
if ($_GET['fastcheck'] == 0) {
echo "<div class='content'><section id='ctsubmit'>";
echo "<header><h2>Certificate Transparency Submission</h2></header>";
echo "<p><a href='http://www.certificate-transparency.org/'>Information about Certificate Transparency</a></p>";
foreach ($data["data"]['certificate_transparency'] as $ct_url => $ct_result) {
echo "<table class='table table-striped table-bordered'>";
echo "<tr><td>CT Log URL</td><td>" . htmlspecialchars($ct_url) . "</td></tr>";
if (is_array($ct_result)) {
foreach ($ct_result as $key => $value) {
if (is_bool($key)) {
$key = ($key) ? 'True' : 'False';
}
if (is_bool($value)) {
$value = ($value) ? 'True' : 'False';
}
echo "<tr><td width='20%'>" . htmlspecialchars(ucfirst(str_replace('_', ' ', $key))) . "</td><td width='80%' style='font-family:monospace;'>" . wordwrap(htmlspecialchars($value), 65, "<br />", 1) . "</td></tr>";
}
} else {
echo "<tr><td>Error</td><td>No result returned</td></tr>";
}
}
echo "</table>";
echo "</section></div>";
} else {
echo "<div class='content'><section id='ctsubmit'>";
echo "<header><h2>Certificate Transparency Submission</h2></header>";
echo "Fast check selected, therefore Certificate Transparency submission is disabled.";
echo "</section></div><p><hr></p>";
}
}
} elseif (!empty($_GET['csr']) ) {
$data = csr_parse_json($_GET['csr']);
echo "<p><strong>This tool does not make conclusions. Please check the data and define the validity yourself!</strong><br>\n </p>";
$cache_filename = (string) "results/saved.csr." . $epoch . "." . $random_bla . ".html";
$cache_filename_json = (string) "results/saved.csr." . $epoch . "." . $random_bla . ".json";
if ($write_cache == 1) {
echo "This result is saved at most 60 days on <a href=\"";
echo(htmlspecialchars($current_folder) . $cache_filename);
echo "\">the following URL</a>. Do note that this might be deleted earlier if space runs out.";
}
if (strpos($_GET['csr'], "BEGIN CERTIFICATE REQUEST") !== false) {
echo "<header><h2>Certificate Signing Request </h2></header><p>";
csr_parse($data);
} else {
echo "<header><h2>Certificate </h2></header><p>";
cert_parse($data);
}
} else {
echo "<span class='text-danger'> Host or Certificate required.</span>";
echo "<hr>";
$write_cache = 0;
}
}
echo "</div>";
echo "</div>";
echo "</div>";
require_once("inc/footer.php");
if ($write_cache == 1) {
if (!file_exists($cache_filename)) {
file_put_contents($cache_filename, ob_get_contents());
}
if (is_array($data)) {
$json_data = json_encode(utf8encodeNestedArray($data));
}
if (!file_exists($cache_filename_json)) {
file_put_contents($cache_filename_json, $json_data);
}
}
?>