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
// DROWN (Decrypting RSA with Obsolete and Weakened eNcryption) Vulnerability Test
// CVE-2016-0800
//
// DROWN allows attackers to decrypt TLS sessions by exploiting SSLv2 on the same
// server or another server using the same private key. Even if the server doesn't
// support SSLv2 on HTTPS, if it supports SSLv2 on another port (like SMTP), it's vulnerable.
use crate::Result;
use crate::utils::network::Target;
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpStream;
use tokio::time::timeout;
/// DROWN vulnerability tester
pub struct DrownTester {
target: Target,
}
impl DrownTester {
pub fn new(target: Target) -> Self {
Self { target }
}
/// Test for DROWN vulnerability
pub async fn test(&self) -> Result<DrownTestResult> {
let sslv2_supported = self.test_sslv2().await?;
let sslv2_export = if sslv2_supported {
self.test_sslv2_export_ciphers().await?
} else {
false
};
let vulnerable = sslv2_supported;
let details = if vulnerable {
if sslv2_export {
"Vulnerable to DROWN (CVE-2016-0800) - SSLv2 with export ciphers enabled (highly vulnerable)".to_string()
} else {
"Vulnerable to DROWN (CVE-2016-0800) - SSLv2 enabled".to_string()
}
} else {
"Not vulnerable - SSLv2 not supported".to_string()
};
Ok(DrownTestResult {
vulnerable,
sslv2_supported,
sslv2_export_ciphers: sslv2_export,
details,
})
}
/// Test if SSLv2 is supported
async fn test_sslv2(&self) -> Result<bool> {
let addr = self.target.socket_addrs()[0];
match timeout(Duration::from_secs(5), TcpStream::connect(addr)).await {
Ok(Ok(mut stream)) => {
// Send SSLv2 ClientHello
let client_hello = self.build_sslv2_client_hello();
stream.write_all(&client_hello).await?;
// Read response
let mut buffer = vec![0u8; 4096];
match timeout(Duration::from_secs(3), stream.read(&mut buffer)).await {
Ok(Ok(n)) if n > 0 => {
// Check for SSLv2 ServerHello response
// SSLv2 ServerHello starts with 0x80 or 0x00 (2-byte length)
let is_sslv2_response =
n >= 2 && (buffer[0] & 0x80 != 0 || buffer[0] == 0x00);
Ok(is_sslv2_response)
}
_ => Ok(false),
}
}
_ => Ok(false),
}
}
/// Test for SSLv2 export ciphers (makes DROWN easier to exploit)
async fn test_sslv2_export_ciphers(&self) -> Result<bool> {
let addr = self.target.socket_addrs()[0];
match timeout(Duration::from_secs(5), TcpStream::connect(addr)).await {
Ok(Ok(mut stream)) => {
// Send SSLv2 ClientHello with export ciphers only
let client_hello = self.build_sslv2_client_hello_export();
stream.write_all(&client_hello).await?;
// Read response
let mut buffer = vec![0u8; 4096];
match timeout(Duration::from_secs(3), stream.read(&mut buffer)).await {
Ok(Ok(n)) if n > 0 => {
// Check if server accepted export cipher
let is_sslv2_response =
n >= 2 && (buffer[0] & 0x80 != 0 || buffer[0] == 0x00);
Ok(is_sslv2_response)
}
_ => Ok(false),
}
}
_ => Ok(false),
}
}
/// Build SSLv2 ClientHello
fn build_sslv2_client_hello(&self) -> Vec<u8> {
let mut hello = vec![
0x80, 0x31, // SSLv2 record header (high bit set, length: 49 bytes)
0x01, // Message type: CLIENT-HELLO
0x00, 0x02, // Version: SSL 2.0
];
// Cipher specs length: 15 bytes (5 ciphers * 3 bytes)
hello.push(0x00);
hello.push(0x0f);
// Session ID length: 0
hello.push(0x00);
hello.push(0x00);
// Challenge length: 16 bytes
hello.push(0x00);
hello.push(0x10);
// Cipher specs (3-byte cipher codes)
// SSL_CK_DES_192_EDE3_CBC_WITH_MD5
hello.push(0x01);
hello.push(0x00);
hello.push(0x80);
// SSL_CK_RC4_128_WITH_MD5
hello.push(0x01);
hello.push(0x00);
hello.push(0x80);
// SSL_CK_RC2_128_CBC_WITH_MD5
hello.push(0x03);
hello.push(0x00);
hello.push(0x80);
// SSL_CK_DES_64_CBC_WITH_MD5
hello.push(0x06);
hello.push(0x00);
hello.push(0x40);
// SSL_CK_RC4_128_EXPORT40_WITH_MD5
hello.push(0x04);
hello.push(0x00);
hello.push(0x80);
// Challenge (random 16 bytes)
for i in 0..16 {
hello.push((i * 13) as u8);
}
hello
}
/// Build SSLv2 ClientHello with export ciphers only
fn build_sslv2_client_hello_export(&self) -> Vec<u8> {
let mut hello = vec![
0x80, 0x2b, // SSLv2 record header (high bit set, length: 43 bytes)
0x01, // Message type: CLIENT-HELLO
0x00, 0x02, // Version: SSL 2.0
];
// Cipher specs length: 9 bytes (3 export ciphers * 3 bytes)
hello.push(0x00);
hello.push(0x09);
// Session ID length: 0
hello.push(0x00);
hello.push(0x00);
// Challenge length: 16 bytes
hello.push(0x00);
hello.push(0x10);
// Export cipher specs
// SSL_CK_RC4_128_EXPORT40_WITH_MD5
hello.push(0x04);
hello.push(0x00);
hello.push(0x80);
// SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5
hello.push(0x06);
hello.push(0x00);
hello.push(0x40);
// SSL_CK_DES_64_CBC_WITH_MD5
hello.push(0x06);
hello.push(0x00);
hello.push(0x40);
// Challenge (random 16 bytes)
for i in 0..16 {
hello.push((i * 17) as u8);
}
hello
}
}
/// DROWN test result
#[derive(Debug, Clone)]
pub struct DrownTestResult {
pub vulnerable: bool,
pub sslv2_supported: bool,
pub sslv2_export_ciphers: bool,
pub details: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_drown_result_not_vulnerable() {
let result = DrownTestResult {
vulnerable: false,
sslv2_supported: false,
sslv2_export_ciphers: false,
details: "Not vulnerable".to_string(),
};
assert!(!result.vulnerable);
assert!(!result.sslv2_supported);
}
#[test]
fn test_drown_result_vulnerable() {
let result = DrownTestResult {
vulnerable: true,
sslv2_supported: true,
sslv2_export_ciphers: false,
details: "Vulnerable".to_string(),
};
assert!(result.vulnerable);
assert!(result.sslv2_supported);
}
#[test]
fn test_sslv2_client_hello() {
let target = Target::with_ips(
"example.com".to_string(),
443,
vec!["93.184.216.34".parse().unwrap()],
)
.unwrap();
let tester = DrownTester::new(target);
let hello = tester.build_sslv2_client_hello();
assert!(hello.len() > 40);
assert_eq!(hello[0], 0x80); // SSLv2 record
assert_eq!(hello[2], 0x01); // CLIENT-HELLO
assert_eq!(hello[3], 0x00); // SSL 2.0 version
assert_eq!(hello[4], 0x02);
}
}