Skip to content

Commit b0bf901

Browse files
author
Brent Cook
committed
Land rapid7#6950, avoid printing rhost:rport twice when using Msf::Exploit::Remote::SMB::Client
2 parents 943b07f + 199ae04 commit b0bf901

16 files changed

+78
-74
lines changed

lib/msf/core/auxiliary/auth_brute.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ def build_brute_message(host_ip,host_port,proto,msg,legacy)
593593
old_msg = msg.to_s.strip
594594
msg_regex = /(#{ip})(:#{port})?(\s*-?\s*)(#{proto.to_s})?(\s*-?\s*)(.*)/ni
595595
if old_msg.match(msg_regex) and !old_msg.match(msg_regex)[6].to_s.strip.empty?
596-
complete_message = [ip,port].join(":")
597-
(complete_message << " ") if ip
596+
complete_message = ''
598597
complete_message << (old_msg.match(msg_regex)[4] || proto).to_s
599598
complete_message << " - "
600599
progress = tried_over_total(ip,port)
@@ -604,8 +603,7 @@ def build_brute_message(host_ip,host_port,proto,msg,legacy)
604603
complete_message = msg.to_s.strip
605604
end
606605
else
607-
complete_message = [ip,port].join(":")
608-
(complete_message << " ") if ip
606+
complete_message = ''
609607
complete_message << "#{proto.to_s.strip} - " if proto
610608
progress = tried_over_total(ip,port)
611609
complete_message << progress if progress

modules/auxiliary/admin/smb/check_dir_file.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def check_path(path)
6464
when "STATUS_OBJECT_PATH_NOT_FOUND"
6565
vprint_error("Object PATH \\\\#{rhost}\\#{datastore['SMBSHARE']}\\#{path} NOT found!")
6666
when "STATUS_ACCESS_DENIED"
67-
vprint_error("Host #{rhost} reports access denied.")
67+
vprint_error("Host reports access denied.")
6868
when "STATUS_BAD_NETWORK_NAME"
69-
vprint_error("Host #{rhost} is NOT connected to #{datastore['SMBDomain']}!")
69+
vprint_error("Host is NOT connected to #{datastore['SMBDomain']}!")
7070
when "STATUS_INSUFF_SERVER_RESOURCES"
71-
vprint_error("Host #{rhost} rejected with insufficient resources!")
71+
vprint_error("Host rejected with insufficient resources!")
7272
when "STATUS_OBJECT_NAME_INVALID"
7373
vprint_error("opeining \\#{path} bad filename")
7474
else
@@ -92,13 +92,13 @@ def run_host(ip)
9292
check_path(path.chomp)
9393
end #end do
9494
rescue ::Rex::HostUnreachable
95-
vprint_error("Host #{rhost} offline.")
95+
vprint_error("Host offline.")
9696
rescue ::Rex::Proto::SMB::Exceptions::LoginError
97-
print_error("Host #{rhost} login error.")
97+
print_error("Host login error.")
9898
rescue ::Rex::ConnectionRefused
99-
print_error "Host #{rhost} unable to connect - connection refused"
99+
print_error "Unable to connect - connection refused"
100100
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode
101-
print_error "Host #{rhost} unable to connect to share #{datastore['SMBSHARE']}"
101+
print_error "Unable to connect to share #{datastore['SMBSHARE']}"
102102
end # end begin
103103
end # end def
104104
end

modules/auxiliary/admin/smb/delete_file.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ def initialize
4141
end
4242

4343
def smb_delete_files
44-
vprint_status("#{peer}: Connecting to the server...")
44+
vprint_status("Connecting to the server...")
4545
connect()
4646
smb_login()
4747

48-
vprint_status("#{peer}: Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
48+
vprint_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
4949
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
5050

5151
remote_paths.each do |remote_path|
5252
begin
5353
simple.delete("\\#{remote_path}")
5454

5555
# If there's no exception raised at this point, we assume the file has been removed.
56-
print_good("#{peer}: Deleted: #{remote_path}")
56+
print_good("Deleted: #{remote_path}")
5757
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
5858
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
59-
print_error("#{peer}: Cannot delete #{remote_path}: #{e.message}")
59+
print_error("Cannot delete #{remote_path}: #{e.message}")
6060
end
6161
end
6262
end
@@ -66,7 +66,7 @@ def run_host(_ip)
6666
smb_delete_files
6767
rescue Rex::Proto::SMB::Exceptions::LoginError => e
6868
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
69-
print_error("#{peer}: Unable to login: #{e.message}")
69+
print_error("Unable to login: #{e.message}")
7070
end
7171
end
7272

modules/auxiliary/admin/smb/download_file.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def initialize
4141
end
4242

4343
def smb_download
44-
vprint_status("#{peer}: Connecting...")
44+
vprint_status("Connecting...")
4545
connect()
4646
smb_login()
4747

@@ -50,7 +50,7 @@ def smb_download
5050

5151
remote_paths.each do |remote_path|
5252
begin
53-
vprint_status("#{peer}: Trying to download #{remote_path}...")
53+
vprint_status("Trying to download #{remote_path}...")
5454

5555
data = ''
5656
fd = simple.open("\\#{remote_path}", 'ro')
@@ -62,10 +62,10 @@ def smb_download
6262

6363
fname = remote_path.split("\\")[-1]
6464
path = store_loot("smb.shares.file", "application/octet-stream", rhost, data, fname)
65-
print_good("#{peer}: #{remote_path} saved as: #{path}")
65+
print_good("#{remote_path} saved as: #{path}")
6666
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
6767
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
68-
print_error("#{peer} Unable to download #{remote_path}: #{e.message}")
68+
print_error("Unable to download #{remote_path}: #{e.message}")
6969
end
7070
end
7171
end
@@ -75,7 +75,7 @@ def run_host(ip)
7575
smb_download
7676
rescue Rex::Proto::SMB::Exceptions::LoginError => e
7777
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
78-
print_error("#{peer} Unable to login: #{e.message}")
78+
print_error("Unable to login: #{e.message}")
7979
end
8080
end
8181

modules/auxiliary/admin/smb/upload_file.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,38 @@ def initialize
4949

5050
def run_host(_ip)
5151
begin
52-
vprint_status("#{peer}: Connecting to the server...")
52+
vprint_status("Connecting to the server...")
5353
connect()
5454
smb_login()
5555

56-
vprint_status("#{peer}: Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
56+
vprint_status("Mounting the remote share \\\\#{datastore['RHOST']}\\#{datastore['SMBSHARE']}'...")
5757
self.simple.connect("\\\\#{rhost}\\#{datastore['SMBSHARE']}")
5858

5959
remote_path = remote_paths.first
60+
61+
if local_paths.nil?
62+
print_error("Local paths not specified")
63+
return
64+
end
65+
6066
local_paths.each do |local_path|
6167
begin
62-
vprint_status("#{peer}: Trying to upload #{local_path} to #{remote_path}...")
68+
vprint_status("Trying to upload #{local_path} to #{remote_path}...")
6369

6470
fd = simple.open("\\#{remote_path}", 'rwct')
6571
data = ::File.read(datastore['LPATH'], ::File.size(datastore['LPATH']))
6672
fd.write(data)
6773
fd.close
6874

69-
print_good("#{peer}: #{local_path} uploaded to #{remote_path}")
75+
print_good("#{local_path} uploaded to #{remote_path}")
7076
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
7177
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
72-
print_error("#{peer} Unable to upload #{local_path} to #{remote_path} : #{e.message}")
78+
print_error("Unable to upload #{local_path} to #{remote_path} : #{e.message}")
7379
end
7480
end
7581
rescue Rex::Proto::SMB::Exceptions::LoginError => e
7682
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
77-
print_error("#{peer} Unable to login: #{e.message}")
83+
print_error("Unable to login: #{e.message}")
7884
end
7985
end
8086
end

modules/auxiliary/gather/windows_deployment_services_shares.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def srvsvc_netshareenum
6060
begin
6161
dcerpc_bind(handle)
6262
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
63-
print_error("#{rhost} : #{e.message}")
63+
print_error(e.message)
6464
return
6565
end
6666

@@ -148,7 +148,7 @@ def run_host(ip)
148148
share_type = share[1]
149149

150150
if share_type == "DISK" && (share_name == "REMINST" || share_comm == "MDT Deployment Share")
151-
vprint_good("#{ip}:#{rport} Identified deployment share #{share_name} #{share_comm}")
151+
vprint_good("Identified deployment share #{share_name} #{share_comm}")
152152
deploy_shares << share_name
153153
end
154154
end
@@ -164,12 +164,12 @@ def run_host(ip)
164164

165165
def query_share(share)
166166
share_path = "\\\\#{rhost}\\#{share}"
167-
vprint_status("#{rhost}:#{rport} Enumerating #{share}...")
167+
vprint_status("Enumerating #{share}...")
168168

169169
begin
170170
simple.connect(share_path)
171171
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
172-
print_error("#{rhost}:#{rport} Could not access share: #{share} - #{e}")
172+
print_error("Could not access share: #{share} - #{e}")
173173
return
174174
end
175175

@@ -188,7 +188,7 @@ def query_share(share)
188188
next unless cred['password'].to_s.length > 0
189189

190190
report_creds(cred['domain'].to_s, cred['username'], cred['password'])
191-
print_good("#{rhost}:#{rport} Credentials: " +
191+
print_good("Credentials: " +
192192
"Path=#{share_path}#{file_path} " +
193193
"Username=#{cred['domain'].to_s}\\#{cred['username'].to_s} " +
194194
"Password=#{cred['password'].to_s}"
@@ -238,7 +238,7 @@ def parse_client_unattend(data)
238238
def loot_unattend(data)
239239
return if data.empty?
240240
path = store_loot('windows.unattend.raw', 'text/plain', rhost, data, "Windows Deployment Services")
241-
print_status("#{rhost}:#{rport} Stored unattend.xml in #{path}")
241+
print_status("Stored unattend.xml in #{path}")
242242
end
243243

244244
def report_creds(domain, user, pass)

modules/auxiliary/scanner/smb/pipe_auditor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def run_host(ip)
8989
end
9090

9191
if(pass.length > 0)
92-
print_status("#{ip} - Pipes: #{pass.map{|c| "\\#{c}"}.join(", ")}")
92+
print_status("Pipes: #{pass.map{|c| "\\#{c}"}.join(", ")}")
9393
# Add Report
9494
report_note(
9595
:host => ip,

modules/auxiliary/scanner/smb/pipe_dcerpc_auditor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def run_host(ip)
274274

275275
begin
276276
dcerpc_bind(handle)
277-
print_line("#{ip} - UUID #{uuid[0]} #{uuid[1]} OPEN VIA #{datastore['SMBPIPE']}")
277+
print_line("UUID #{uuid[0]} #{uuid[1]} OPEN VIA #{datastore['SMBPIPE']}")
278278
# Add Report
279279
report_note(
280280
:host => ip,

modules/auxiliary/scanner/smb/smb_enum_gpp.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def check_path(ip, path)
6262
when 'STATUS_OBJECT_PATH_NOT_FOUND'
6363
vprint_error("Object PATH \\\\#{ip}\\#{datastore['SMBSHARE']}\\#{path} NOT found!")
6464
when 'STATUS_ACCESS_DENIED'
65-
vprint_error("Host #{ip} reports access denied.")
65+
vprint_error("Host reports access denied.")
6666
when 'STATUS_BAD_NETWORK_NAME'
67-
vprint_error("Host #{ip} is NOT connected to #{datastore['SMBDomain']}!")
67+
vprint_error("Host is NOT connected to #{datastore['SMBDomain']}!")
6868
when 'STATUS_INSUFF_SERVER_RESOURCES'
69-
vprint_error("Host #{ip} rejected with insufficient resources!")
69+
vprint_error("Host rejected with insufficient resources!")
7070
when 'STATUS_OBJECT_NAME_INVALID'
7171
vprint_error("opening \\#{path} bad filename")
7272
else

modules/auxiliary/scanner/smb/smb_enumshares.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def lanman_netshareenum(ip, rport, info)
187187
))
188188
rescue ::Rex::Proto::SMB::Exceptions::ErrorCode => e
189189
if e.error_code == 0xC00000BB
190-
vprint_error("#{ip}:#{rport} - Got 0xC00000BB while enumerating shares, switching to srvsvc...")
190+
vprint_error("Got 0xC00000BB while enumerating shares, switching to srvsvc...")
191191
@srvsvc = true # Make sure the module is aware of this state
192192
return srvsvc_netshareenum(ip)
193193
end
@@ -224,7 +224,7 @@ def srvsvc_netshareenum(ip)
224224
begin
225225
dcerpc_bind(handle)
226226
rescue Rex::Proto::SMB::Exceptions::ErrorCode => e
227-
vprint_error("#{ip} : #{e.message}")
227+
vprint_error(e.message)
228228
return []
229229
end
230230

@@ -336,7 +336,7 @@ def get_files_info(ip, rport, shares, info)
336336
next
337337
end
338338
if not datastore['ShowFiles']
339-
print_status("#{ip}:#{rport} - Spidering #{x}.")
339+
print_status("Spidering #{x}.")
340340
end
341341
subdirs = [""]
342342
if x.strip() == "C$" and datastore['SpiderProfiles']
@@ -361,7 +361,7 @@ def get_files_info(ip, rport, shares, info)
361361
subdirs.shift
362362
next
363363
end
364-
header = "#{ip}:#{rport}"
364+
header = ""
365365
if simple.client.default_domain and simple.client.default_name
366366
header << " \\\\#{simple.client.default_domain}"
367367
end
@@ -408,18 +408,18 @@ def get_files_info(ip, rport, shares, info)
408408
end
409409
subdirs.shift
410410
end
411-
print_status("#{ip}:#{rport} - Spider #{x} complete.") unless datastore['ShowFiles']
411+
print_status("Spider #{x} complete.") unless datastore['ShowFiles']
412412
end
413413
unless detailed_tbl.rows.empty?
414414
if datastore['LogSpider'] == '1'
415415
p = store_loot('smb.enumshares', 'text/csv', ip, detailed_tbl.to_csv)
416-
print_good("#{ip} - info saved in: #{p.to_s}")
416+
print_good("info saved in: #{p.to_s}")
417417
elsif datastore['LogSpider'] == '2'
418418
p = store_loot('smb.enumshares', 'text/plain', ip, detailed_tbl)
419-
print_good("#{ip} - info saved in: #{p.to_s}")
419+
print_good("info saved in: #{p.to_s}")
420420
elsif datastore['LogSpider'] == '3'
421421
p = store_loot('smb.enumshares', 'text/plain', ip, logdata)
422-
print_good("#{ip} - info saved in: #{p.to_s}")
422+
print_good("info saved in: #{p.to_s}")
423423
end
424424
end
425425
end
@@ -453,12 +453,12 @@ def run_host(ip)
453453
end
454454

455455
os_info = get_os_info(ip, rport)
456-
print_status("#{ip}:#{rport} - #{os_info}") if os_info
456+
print_status(os_info) if os_info
457457

458458
if shares.empty?
459-
print_status("#{ip}:#{rport} - No shares collected")
459+
print_status("No shares collected")
460460
else
461-
shares_info = shares.map{|x| "#{ip}:#{rport} - #{x[0]} - (#{x[1]}) #{x[2]}" }.join(", ")
461+
shares_info = shares.map{|x| "#{x[0]} - (#{x[1]}) #{x[2]}" }.join(", ")
462462
shares_info.split(", ").each { |share|
463463
print_good share
464464
}
@@ -482,15 +482,15 @@ def run_host(ip)
482482
raise $!
483483
rescue ::Rex::Proto::SMB::Exceptions::LoginError,
484484
::Rex::Proto::SMB::Exceptions::ErrorCode => e
485-
print_error("#{ip}:#{rport} - #{e.message}")
485+
print_error(e.message)
486486
return if e.message =~ /STATUS_ACCESS_DENIED/
487487
rescue Errno::ECONNRESET,
488488
::Rex::Proto::SMB::Exceptions::InvalidType,
489489
::Rex::Proto::SMB::Exceptions::ReadPacket,
490490
::Rex::Proto::SMB::Exceptions::InvalidCommand,
491491
::Rex::Proto::SMB::Exceptions::InvalidWordCount,
492492
::Rex::Proto::SMB::Exceptions::NoReply => e
493-
vprint_error("#{ip}:#{rport} - #{e.message}")
493+
vprint_error(e.message)
494494
next if not shares.empty? and rport == 139 # no results, try again
495495
rescue Errno::ENOPROTOOPT
496496
print_status("Wait 5 seconds before retrying...")
@@ -499,7 +499,7 @@ def run_host(ip)
499499
rescue ::Exception => e
500500
next if e.to_s =~ /execution expired/
501501
next if not shares.empty? and rport == 139
502-
vprint_error("#{ip}:#{rport} - Error: '#{ip}' '#{e.class}' '#{e.to_s}'")
502+
vprint_error("Error: '#{ip}' '#{e.class}' '#{e.to_s}'")
503503
ensure
504504
disconnect
505505
end

0 commit comments

Comments
 (0)