Skip to content

Commit 78f2ea3

Browse files
committed
Use some pretty libral error handling
1 parent 41567b1 commit 78f2ea3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

modules/auxiliary/admin/dcerpc/samr_computer.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ def connect_samr
5757
end
5858

5959
def run
60-
connect
60+
begin
61+
connect
62+
rescue Rex::ConnectionError => e
63+
fail_with(Failure::Unreachable, e.message)
64+
end
65+
6166
begin
6267
smb_login
6368
rescue Rex::Proto::SMB::Exceptions::Error, RubySMB::Error::RubySMBError => e
64-
fail_with(Module::Failure::NoAccess, "Unable to authenticate ([#{e.class}] #{e}).")
69+
fail_with(Failure::NoAccess, "Unable to authenticate ([#{e.class}] #{e}).")
6570
end
6671
report_service(
6772
host: rhost,
@@ -75,7 +80,7 @@ def run
7580
begin
7681
@tree = simple.client.tree_connect("\\\\#{sock.peerhost}\\IPC$")
7782
rescue RubySMB::Error::RubySMBError => e
78-
fail_with(Module::Failure::Unreachable, "Unable to connect to the remote IPC$ share ([#{e.class}] #{e}).")
83+
fail_with(Failure::Unreachable, "Unable to connect to the remote IPC$ share ([#{e.class}] #{e}).")
7984
end
8085

8186
@samr = connect_samr
@@ -84,7 +89,7 @@ def run
8489
if datastore['SMBDomain'].blank? || datastore['SMBDomain'] == '.'
8590
all_domains = @samr.samr_enumerate_domains_in_sam_server(server_handle: @server_handle).map(&:to_s).map(&:encode)
8691
all_domains.delete('Builtin')
87-
if all_domains.length == 0
92+
if all_domains.empty?
8893
fail_with(Failure::NotFound, 'No domains were found on the SAM server.')
8994
elsif all_domains.length > 1
9095
print_status("Enumerated domains: #{all_domains.join(', ')}")
@@ -100,6 +105,9 @@ def run
100105
@domain_sid = @samr.samr_lookup_domain(server_handle: @server_handle, name: @domain_name)
101106
@domain_handle = @samr.samr_open_domain(server_handle: @server_handle, domain_id: @domain_sid)
102107
send("action_#{action.name.downcase}")
108+
rescue RubySMB::Dcerpc::Error::SamrError => e
109+
elog(e.message, error: e)
110+
fail_with(Failure::UnexpectedReply, e.message)
103111
end
104112

105113
def random_hostname(prefix: 'DESKTOP')

0 commit comments

Comments
 (0)