Skip to content

Commit a21752b

Browse files
committed
Fix NoMethodError on os, mark DCs as 'server'
1 parent a75d47a commit a21752b

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

modules/post/windows/gather/enum_ad_computers.rb

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ def run
6666

6767
# Results table holds raw string data
6868
results_table = Rex::Ui::Text::Table.new(
69-
'Header' => "Domain Computers",
70-
'Indent' => 1,
71-
'SortIndex' => -1,
72-
'Columns' => fields
73-
)
69+
'Header' => "Domain Computers",
70+
'Indent' => 1,
71+
'SortIndex' => -1,
72+
'Columns' => fields
73+
)
7474

7575
# Hostnames holds DNS Names to Resolve
7676
hostnames = []
@@ -81,40 +81,37 @@ def run
8181

8282
report = {}
8383
0.upto(fields.length-1) do |i|
84-
if result[i].nil?
85-
field = ""
86-
else
87-
field = result[i]
88-
89-
# Only perform these actions if the database is connected and we want
90-
# to store in the DB.
91-
if db and datastore['STORE_DB']
92-
case fields[i]
93-
when 'dNSHostName'
94-
dns = field
95-
report[:name] = dns
96-
hostnames << dns
97-
when 'operatingSystem'
98-
report[:os_name] = os
99-
when 'distinguishedName'
100-
if field =~ /Domain Controllers/i
101-
# TODO: Find another way to mark a host as being a domain controller
102-
# The 'purpose' field should be server, client, device, printer, etc
103-
# report[:purpose] = "DC"
104-
end
105-
when 'operatingSystemServicePack'
106-
# XXX: Does this take into account the leading 'SP' string?
107-
108-
if field.to_i > 0
109-
report[:os_sp] = 'SP' + field
110-
end
111-
if field =~ /(Service Pack|SP)\s?(\d+)/
112-
report[:os_sp] = 'SP' + $2
113-
end
114-
115-
when 'description'
116-
report[:info] = field
84+
field = result[i] || ""
85+
86+
# Only perform these actions if the database is connected and we want
87+
# to store in the DB.
88+
if db && datastore['STORE_DB']
89+
case fields[i]
90+
when 'dNSHostName'
91+
dns = field
92+
report[:name] = dns
93+
hostnames << dns
94+
when 'operatingSystem'
95+
report[:os_name] = field
96+
when 'distinguishedName'
97+
if field =~ /Domain Controllers/i
98+
# TODO: Find another way to mark a host as being a domain controller
99+
# The 'purpose' field should be server, client, device, printer, etc
100+
#report[:purpose] = "DC"
101+
report[:purpose] = "server"
117102
end
103+
when 'operatingSystemServicePack'
104+
# XXX: Does this take into account the leading 'SP' string?
105+
106+
if field.to_i > 0
107+
report[:os_sp] = 'SP' + field
108+
end
109+
if field =~ /(Service Pack|SP)\s?(\d+)/
110+
report[:os_sp] = 'SP' + $2
111+
end
112+
113+
when 'description'
114+
report[:info] = field
118115
end
119116
end
120117

@@ -125,7 +122,7 @@ def run
125122
results_table << row
126123
end
127124

128-
if db and datastore['STORE_DB']
125+
if db && datastore['STORE_DB']
129126
print_status("Resolving IP addresses...")
130127
ip_results = client.net.resolve.resolve_hosts(hostnames, AF_INET)
131128

0 commit comments

Comments
 (0)