7
7
require 'rex'
8
8
9
9
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
+ ) )
28
27
register_options (
29
28
[
30
29
OptString . new ( 'GROUP' , [ true , 'Domain Group to enumerate' , nil ] )
@@ -38,18 +37,16 @@ def run
38
37
cur_domain , cur_user = client . sys . config . getuid . split ( "\\ " )
39
38
ltype = "domain.group.members"
40
39
ctype = "text/plain"
41
- domain = ""
42
40
43
41
# 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" )
46
43
47
44
# Parse Returned data
48
45
members = get_members ( usr_res . split ( "\n " ) )
49
- domain = get_domain ( dom_res . split ( " \n " ) )
46
+ domain = get_env ( "USERDOMAIN" )
50
47
51
48
# Show results if we have any, Error if we don't
52
- if ! members . empty?
49
+ if !members . empty?
53
50
54
51
print_status ( "Found users in #{ datastore [ 'GROUP' ] } " )
55
52
@@ -61,9 +58,9 @@ def run
61
58
62
59
# Is our current user a member of this domain and group
63
60
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' ] } !" )
65
62
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' ] } " )
67
64
end
68
65
69
66
# Store the captured data in the loot.
@@ -72,7 +69,6 @@ def run
72
69
else
73
70
print_error ( "No members found for #{ datastore [ 'GROUP' ] } " )
74
71
end
75
-
76
72
end
77
73
78
74
def get_members ( results )
@@ -90,41 +86,21 @@ def get_members(results)
90
86
end
91
87
end
92
88
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
104
90
end
105
91
106
92
def is_member ( cur_dom , cur_user , dom , users )
107
-
108
93
member = false
109
94
110
95
if cur_dom == dom
111
96
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
113
101
end
114
102
end
115
103
116
- return member
104
+ member
117
105
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
-
130
106
end
0 commit comments