Skip to content

Commit 232eb7b

Browse files
author
jvazquez-r7
committed
Final cleanup plus name change
1 parent 9cff72a commit 232eb7b

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

modules/auxiliary/scanner/smb/loggedin_users.rb renamed to modules/auxiliary/scanner/smb/psexec_loggedin_users.rb

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ class Metasploit3 < Msf::Auxiliary
1717

1818
def initialize
1919
super(
20-
'Name' => 'SMB - Query Logged On Users',
20+
'Name' => 'Microsoft Windows Authenticated Logged In Users Enumeration',
2121
'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.
2425
},
2526
'Author' =>
2627
[
27-
'Royce Davis @R3dy__ <rdavis[at]accuvant.com>' # Metasploit module
28+
'Royce Davis @R3dy__ <rdavis[at]accuvant.com>' # Metasploit module
2829
],
2930
'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' ]
3135
],
3236
'License' => MSF_LICENSE
3337
)
@@ -41,14 +45,10 @@ def initialize
4145
deregister_options('RHOST')
4246
end
4347

44-
45-
4648
def peer
4749
return "#{rhost}:#{rport}"
4850
end
4951

50-
51-
5252
# This is the main controller function
5353
def run_host(ip)
5454
cmd = "C:\\WINDOWS\\SYSTEM32\\cmd.exe"
@@ -67,19 +67,17 @@ def run_host(ip)
6767

6868
keys = get_hku(ip, smbshare, cmd, text, bat)
6969
if !keys
70-
cleanup_after(smbshare, ip, cmd, text, bat)
70+
cleanup_after(cmd, text, bat)
7171
disconnect
7272
return
7373
end
7474
keys.each do |key|
7575
check_hku_entry(key, ip, smbshare, cmd, text, bat)
7676
end
77-
cleanup_after(smbshare, ip, cmd, text, bat)
77+
cleanup_after(cmd, text, bat)
7878
disconnect
7979
end
8080

81-
82-
8381
# This method runs reg.exe query HKU to get a list of each key within the HKU master key
8482
# Returns an array object
8583
def get_hku(ip, smbshare, cmd, text, bat)
@@ -97,8 +95,6 @@ def get_hku(ip, smbshare, cmd, text, bat)
9795
end
9896
end
9997

100-
101-
10298
# This method will retrive output from a specified textfile on the remote host
10399
def get_output(ip, smbshare, file)
104100
begin
@@ -114,20 +110,18 @@ def get_output(ip, smbshare, file)
114110
end
115111
end
116112

117-
118-
119113
def report_user(username)
120-
report_note = {
114+
report_note(
121115
:host => rhost,
122116
:proto => 'tcp',
117+
:sname => 'smb',
123118
: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+
)
127123
end
128124

129-
130-
131125
# This method checks a provided HKU entry to determine if it is a valid SID
132126
# Either returns nil or returns the name of a valid user
133127
def check_hku_entry(key, ip, smbshare, cmd, text, bat)
@@ -144,7 +138,7 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
144138
domain = line if line.include?("USERDOMAIN")
145139
end
146140
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")
148142
report_user(datastore['USERNAME'])
149143
end
150144
return
@@ -159,20 +153,20 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
159153
if username.length > 0 && domain.length > 0
160154
user = domain.split(" ")[2].to_s + "\\" + username.split(" ")[2].to_s
161155
print_good("#{peer} - #{user}")
162-
report_user(user)
156+
report_user(user.chomp)
163157
elsif logonserver.length > 0 && homepath.length > 0
164158
uname = homepath.split('\\')[homepath.split('\\').size - 1]
165159
if uname.include?(".")
166160
uname = uname.split(".")[0]
167161
end
168162
user = logonserver.split('\\\\')[1].chomp.to_s + "\\" + uname.to_s
169163
print_good("#{peer} - #{user}")
170-
report_user(user)
164+
report_user(user.chomp)
171165
else
172166
if username = query_session(smbshare, ip, cmd, text, bat)
173167
user = dnsdomain.split(" ")[2].split(".")[0].to_s + "\\" + username.to_s
174168
print_good("#{peer} - #{user}")
175-
report_user(user)
169+
report_user(user.chomp)
176170
else
177171
print_status("#{peer} - Unable to determine user information for user: #{key}")
178172
end
@@ -186,23 +180,21 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
186180
end
187181
end
188182

189-
190-
191183
# 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)
193185
begin
194186
# Try and do cleanup command
195187
cleanup = "#{cmd} /C del C:#{text} & del #{bat}"
196-
print_status("Executing cleanup on host: #{peer}")
188+
print_status("#{peer} - Executing cleanup")
197189
out = psexec(cleanup)
198190
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")
200194
return cleanuperror
201195
end
202196
end
203197

204-
205-
206198
# Method trys to use "query session" to determine logged in user
207199
def query_session(smbshare, ip, cmd, text, bat)
208200
begin
@@ -220,8 +212,6 @@ def query_session(smbshare, ip, cmd, text, bat)
220212
end
221213
end
222214

223-
224-
225215
# This code was stolen straight out of psexec.rb. Thanks very much HDM and all who contributed to that module!!
226216
# Instead of uploading and runing a binary. This method runs a single windows command fed into the #{command} paramater
227217
def psexec(command)

0 commit comments

Comments
 (0)