Skip to content

Commit 16ce2c3

Browse files
committed
fixed catch statements
1 parent 62be877 commit 16ce2c3

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

modules/post/windows/gather/local_admin_search_enum.rb

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,47 +89,53 @@ def run_host(ip)
8989
# enumerate logged in users
9090
def enum_users(host)
9191
begin
92-
# Connect to host and enumerate logged in users
93-
winsessions = client.railgun.netapi32.NetWkstaUserEnum("\\\\#{host}", 1, 4, -1, 4, 4, nil)
94-
92+
# Connect to host and enumerate logged in users
93+
winsessions = client.railgun.netapi32.NetWkstaUserEnum("\\\\#{host}", 1, 4, -1, 4, 4, nil)
94+
rescue ::Exception => e
95+
print_error("Issue enumerating users on #{host}")
96+
end
9597
count = winsessions['totalentries'] * 2
9698
startmem = winsessions['bufptr']
9799

98100
base = 0
99101
userlist = Array.new
100-
mem = client.railgun.memread(startmem, 8*count)
102+
begin
103+
mem = client.railgun.memread(startmem, 8*count)
104+
rescue ::Exception => e
105+
print_error("Issue reading memory for #{host}")
106+
end
101107
# For each entry returned, get domain and name of logged in user
102-
count.times{|i|
103-
temp = {}
104-
userptr = mem[(base + 0),4].unpack("V*")[0]
105-
temp[:user] = client.railgun.memread(userptr,255).split("\0\0")[0].split("\0").join
106-
nameptr = mem[(base + 4),4].unpack("V*")[0]
107-
temp[:domain] = client.railgun.memread(nameptr,255).split("\0\0")[0].split("\0").join
108-
109-
# Ignore if empty or machine account
110-
unless temp[:user].empty? or temp[:user][-1, 1] == "$"
111-
112-
# Check if enumerated user's domain matches supplied domain, if there was
113-
# an error, or if option disabled
114-
data = ""
115-
if datastore['DOMAIN'].upcase == temp[:domain].upcase and not @dc_error and datastore['ENUM_GROUPS']
116-
data = " - Groups: #{enum_groups(temp[:user]).chomp(", ")}"
117-
end
118-
line = "\tLogged in user:\t#{temp[:domain]}\\#{temp[:user]}#{data}\n"
119-
120-
# Write user and groups to notes database
121-
db_note(host, "#{temp[:domain]}\\#{temp[:user]}#{data}", "localadmin.user.loggedin")
122-
userlist << line unless userlist.include? line
108+
begin
109+
count.times{|i|
110+
temp = {}
111+
userptr = mem[(base + 0),4].unpack("V*")[0]
112+
temp[:user] = client.railgun.memread(userptr,255).split("\0\0")[0].split("\0").join
113+
nameptr = mem[(base + 4),4].unpack("V*")[0]
114+
temp[:domain] = client.railgun.memread(nameptr,255).split("\0\0")[0].split("\0").join
115+
116+
# Ignore if empty or machine account
117+
unless temp[:user].empty? or temp[:user][-1, 1] == "$"
118+
119+
# Check if enumerated user's domain matches supplied domain, if there was
120+
# an error, or if option disabled
121+
data = ""
122+
if datastore['DOMAIN'].upcase == temp[:domain].upcase and not @dc_error and datastore['ENUM_GROUPS']
123+
data = " - Groups: #{enum_groups(temp[:user]).chomp(", ")}"
124+
end
125+
line = "\tLogged in user:\t#{temp[:domain]}\\#{temp[:user]}#{data}\n"
126+
127+
# Write user and groups to notes database
128+
db_note(host, "#{temp[:domain]}\\#{temp[:user]}#{data}", "localadmin.user.loggedin")
129+
userlist << line unless userlist.include? line
123130

124-
end
131+
end
125132

126-
base = base + 8
127-
}
133+
base = base + 8
134+
}
128135
rescue ::Exception => e
129136
print_error("Issue enumerating users on #{host}")
130137
end
131138
return userlist
132-
133139
end
134140

135141
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa370653(v=vs.85).aspx

0 commit comments

Comments
 (0)