Skip to content

Commit d2e1fdb

Browse files
committed
Fixes enum_domain_group_users when running as SYSTEM.
2 parents cb51bcc + 028f9dd commit d2e1fdb

File tree

1 file changed

+28
-52
lines changed

1 file changed

+28
-52
lines changed

modules/post/windows/gather/enum_domain_group_users.rb

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,23 @@
77
require 'rex'
88

99
class Metasploit3 < Msf::Post
10-
11-
def initialize(info={})
12-
super( update_info( info,
13-
'Name' => 'Windows Gather Enumerate Domain Group',
14-
'Description' => %q{ This module extracts user accounts from specified group
15-
and stores the results in the loot. It will also verify if session
16-
account is in the group. Data is stored in loot in a format that
17-
is compatible with the token_hunter plugin. This module should be
18-
run over as session with domain credentials.},
19-
'License' => MSF_LICENSE,
20-
'Author' =>
21-
[
22-
'Carlos Perez <carlos_perez[at]darkoperator.com>',
23-
'Stephen Haywood <haywoodsb[at]gmail.com>'
24-
],
25-
'Platform' => [ 'win' ],
26-
'SessionTypes' => [ 'meterpreter' ]
27-
))
10+
def initialize(info = {})
11+
super(update_info(info,
12+
'Name' => 'Windows Gather Enumerate Domain Group',
13+
'Description' => %q( This module extracts user accounts from specified group
14+
and stores the results in the loot. It will also verify if session
15+
account is in the group. Data is stored in loot in a format that
16+
is compatible with the token_hunter plugin. This module should be
17+
run over as session with domain credentials.),
18+
'License' => MSF_LICENSE,
19+
'Author' =>
20+
[
21+
'Carlos Perez <carlos_perez[at]darkoperator.com>',
22+
'Stephen Haywood <haywoodsb[at]gmail.com>'
23+
],
24+
'Platform' => [ 'win' ],
25+
'SessionTypes' => [ 'meterpreter' ]
26+
))
2827
register_options(
2928
[
3029
OptString.new('GROUP', [true, 'Domain Group to enumerate', nil])
@@ -38,18 +37,16 @@ def run
3837
cur_domain, cur_user = client.sys.config.getuid.split("\\")
3938
ltype = "domain.group.members"
4039
ctype = "text/plain"
41-
domain = ""
4240

4341
# Get Data
44-
usr_res = run_cmd("net groups \"#{datastore['GROUP']}\" /domain")
45-
dom_res = run_cmd("net config workstation")
42+
usr_res = cmd_exec("net groups \"#{datastore['GROUP']}\" /domain")
4643

4744
# Parse Returned data
4845
members = get_members(usr_res.split("\n"))
49-
domain = get_domain(dom_res.split("\n"))
46+
domain = get_env("USERDOMAIN")
5047

5148
# Show results if we have any, Error if we don't
52-
if ! members.empty?
49+
if !members.empty?
5350

5451
print_status("Found users in #{datastore['GROUP']}")
5552

@@ -61,9 +58,9 @@ def run
6158

6259
# Is our current user a member of this domain and group
6360
if is_member(cur_domain, cur_user, domain, members)
64-
print_status("Current sessions running as #{cur_domain}\\#{cur_user} is a member of #{datastore['GROUP']}!!")
61+
print_good("Current sessions running as #{cur_domain}\\#{cur_user} is a member of #{datastore['GROUP']}!")
6562
else
66-
print_error("Current session running as #{cur_domain}\\#{cur_user} is not a member of #{datastore['GROUP']}")
63+
print_status("Current session running as #{cur_domain}\\#{cur_user} is not a member of #{datastore['GROUP']}")
6764
end
6865

6966
# Store the captured data in the loot.
@@ -72,7 +69,6 @@ def run
7269
else
7370
print_error("No members found for #{datastore['GROUP']}")
7471
end
75-
7672
end
7773

7874
def get_members(results)
@@ -90,41 +86,21 @@ def get_members(results)
9086
end
9187
end
9288

93-
return members
94-
end
95-
96-
def get_domain(results)
97-
domain = ''
98-
99-
results.each do |line|
100-
if line =~ /Workstation domain \s+(.*)/ then domain = $1.strip end
101-
end
102-
103-
return domain
89+
members
10490
end
10591

10692
def is_member(cur_dom, cur_user, dom, users)
107-
10893
member = false
10994

11095
if cur_dom == dom
11196
users.each do |u|
112-
if u.downcase == cur_user.downcase then member = true end
97+
if u.downcase == cur_user.downcase
98+
member = true
99+
break
100+
end
113101
end
114102
end
115103

116-
return member
104+
member
117105
end
118-
def run_cmd(cmd)
119-
process = session.sys.process.execute(cmd, nil, {'Hidden' => true, 'Channelized' => true})
120-
res = ""
121-
while (d = process.channel.read)
122-
break if d == ""
123-
res << d
124-
end
125-
process.channel.close
126-
process.close
127-
return res
128-
end
129-
130106
end

0 commit comments

Comments
 (0)