Skip to content

Commit 8cf5b54

Browse files
committed
make recommended changes
1 parent 0678993 commit 8cf5b54

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

modules/auxiliary/scanner/smtp/smtp_enum.rb

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
##
2-
# $Id: smtp_enum.rb 14774 2012-02-21 01:42:17Z rapid7 $
3-
##
4-
51
##
62
# This file is part of the Metasploit Framework and may be subject to
73
# redistribution and commercial restrictions. Please see the Metasploit
@@ -21,7 +17,6 @@ class Metasploit3 < Msf::Auxiliary
2117
def initialize
2218
super(
2319
'Name' => 'SMTP User Enumeration Utility',
24-
'Version' => '$Revision: 14774 $',
2520
'Description' => %q{
2621
The SMTP service has two internal commands that allow the enumeration
2722
of users: VRFY (confirming the names of valid users) and EXPN (which
@@ -58,10 +53,6 @@ def initialize
5853
deregister_options('MAILTO','MAILFROM')
5954
end
6055

61-
def target
62-
"#{rhost}:#{rport}"
63-
end
64-
6556
def smtp_send(data=nil)
6657
begin
6758
result=''
@@ -74,7 +65,7 @@ def smtp_send(data=nil)
7465
rescue Rex::ConnectionError, Errno::ECONNRESET, ::EOFError
7566
return result, code
7667
rescue ::Exception => e
77-
print_error("#{target} Error smtp_send: '#{e.class}' '#{e}' '#{e.backtrace}'")
68+
print_error("#{rhost}:#{rport} Error smtp_send: '#{e.class}' '#{e}'")
7869
return nil, 0
7970
end
8071
end
@@ -92,16 +83,16 @@ def run_host(ip)
9283
connect
9384
result, code = smtp_send(cmd)
9485

95-
if(not result or result == nil)
96-
print_error("#{target} Connection but no data...skipping")
86+
if(not result)
87+
print_error("#{rhost}:#{rport} Connection but no data...skipping")
9788
return
9889
end
9990
banner.chomp! if (banner)
10091
if(banner =~ /microsoft/i and datastore['UNIXONLY'])
101-
print_status("#{target} Skipping microsoft (#{banner})")
92+
print_status("#{rhost}:#{rport} Skipping microsoft (#{banner})")
10293
return
10394
elsif(banner)
104-
print_status("#{target} Banner: #{banner}")
95+
print_status("#{rhost}:#{rport} Banner: #{banner}")
10596
end
10697

10798
domain = result.split()[1]
@@ -111,13 +102,13 @@ def run_host(ip)
111102
vprint_status("#{ip}:#{rport} Domain Name: #{domain}")
112103

113104
result, code = smtp_send("VRFY root\r\n")
114-
vrfy = false if (code != 250)
105+
vrfy = (code == 250)
115106
users_found = do_enum('VRFY', usernames) if (vrfy)
116107

117108
if(users_found.empty?)
118109
# VRFY failed, lets try EXPN
119110
result, code = smtp_send("EXPN root\r\n")
120-
expn = false if (code != 250)
111+
expn = (code == 250)
121112
users_found = do_enum('EXPN', usernames) if(expn)
122113
end
123114

@@ -128,7 +119,7 @@ def run_host(ip)
128119
user = Rex::Text.rand_text_alpha(8)
129120
result, code = smtp_send("RCPT TO: #{user}\@#{domain}\r\n")
130121
if(code >= 250 and code <= 259)
131-
vprint_status("#{target} RCPT TO: Allowed for random user (#{user})...not reliable? #{code} '#{result}'")
122+
vprint_status("#{rhost}:#{rport} RCPT TO: Allowed for random user (#{user})...not reliable? #{code} '#{result}'")
132123
rcpt = false
133124
else
134125
smtp_send("RSET\r\n")
@@ -140,39 +131,38 @@ def run_host(ip)
140131
end
141132

142133
if(not vrfy and not expn and not rcpt)
143-
print_status("#{target} could not be enumerated (no EXPN, no VRFY, invalid RCPT)")
134+
print_status("#{rhost}:#{rport} could not be enumerated (no EXPN, no VRFY, invalid RCPT)")
144135
return
145136
end
146137
finish_host(users_found)
147138
disconnect
148139

149140
rescue Rex::ConnectionError, Errno::ECONNRESET, Rex::ConnectionTimeout, EOFError, Errno::ENOPROTOOPT
150141
rescue ::Exception => e
151-
print_error( (e.to_str == 'execution expired') ? "Error: #{target} Execution expired" : "Error: #{target} '#{e.class}' '#{e}' '#{e.backtrace}'")
142+
print_error("Error: #{rhost}:#{rport} '#{e.class}' '#{e}'")
152143
end
153144

154145
def finish_host(users_found)
155-
ip, port = target.split(':')
156146
if users_found and not users_found.empty?
157-
print_good("#{target} Users found: #{users_found.sort.join(", ")}")
147+
print_good("#{rhost}:#{rport} Users found: #{users_found.sort.join(", ")}")
158148
report_note(
159-
:host => ip,
160-
:port => port,
149+
:host => rhost,
150+
:port => rport,
161151
:type => 'smtp.users',
162152
:data => {:users => users_found.join(", ")}
163153
)
164154
end
165155
end
166156

167157
def kiss_and_make_up(cmd)
168-
vprint_status("#{target} SMTP server annoyed...reconnecting and saying HELO again...")
158+
vprint_status("#{rhost}:#{rport} SMTP server annoyed...reconnecting and saying HELO again...")
169159
disconnect
170160
connect
171161
smtp_send("HELO localhost\r\n")
172162
result, code = smtp_send("#{cmd}")
173163
result.chomp!
174164
cmd.chomp!
175-
vprint_status("#{target} - SMTP - Re-trying #{cmd} received #{code} '#{result}'")
165+
vprint_status("#{rhost}:#{rport} - SMTP - Re-trying #{cmd} received #{code} '#{result}'")
176166
return result,code
177167
end
178168

@@ -182,10 +172,10 @@ def do_enum(cmd, usernames)
182172
usernames.each {|user|
183173
next if user.downcase == 'root'
184174
result, code = smtp_send("#{cmd} #{user}\r\n")
185-
vprint_status("#{target} - SMTP - Trying #{cmd} #{user} received #{code} '#{result}'")
175+
vprint_status("#{rhost}:#{rport} - SMTP - Trying #{cmd} #{user} received #{code} '#{result}'")
186176
result, code = kiss_and_make_up("#{cmd} #{user}\r\n") if(code == 0 and result.to_s == '')
187177
if(code == 250)
188-
vprint_status("#{target} - Found user: #{user}")
178+
vprint_status("#{rhost}:#{rport} - Found user: #{user}")
189179
users.push(user)
190180
end
191181
}
@@ -196,7 +186,7 @@ def do_rcpt_enum(domain, usernames)
196186
users = []
197187
usernames.each {|user|
198188
next if user.downcase == 'root'
199-
vprint_status("#{target} - SMTP - Trying MAIL FROM: root\@#{domain} / RCPT TO: #{user}...")
189+
vprint_status("#{rhost}:#{rport} - SMTP - Trying MAIL FROM: root\@#{domain} / RCPT TO: #{user}...")
200190
result, code = smtp_send("MAIL FROM: root\@#{domain}\r\n")
201191
result, code = kiss_and_make_up("MAIL FROM: root\@#{domain}\r\n") if(code == 0 and result.to_s == '')
202192

@@ -208,11 +198,11 @@ def do_rcpt_enum(domain, usernames)
208198
end
209199

210200
if(code == 250)
211-
vprint_status("#{target} - Found user: #{user}")
201+
vprint_status("#{rhost}:#{rport} - Found user: #{user}")
212202
users.push(user)
213203
end
214204
else
215-
vprint_status("#{target} MAIL FROM: #{user} NOT allowed during brute...aborting ( '#{code}' '#{result}')")
205+
vprint_status("#{rhost}:#{rport} MAIL FROM: #{user} NOT allowed during brute...aborting ( '#{code}' '#{result}')")
216206
break
217207
end
218208
smtp_send("RSET\r\n")

0 commit comments

Comments
 (0)