Path: blob/master/modules/auxiliary/fuzzers/smtp/smtp_fuzzer.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45##6# A Very simple Module to fuzzer some SMTP commands.7# It allows to respect the order or just throw everything at it....8##910require 'English'11class MetasploitModule < Msf::Auxiliary12include Msf::Exploit::Remote::Smtp13include Msf::Auxiliary::Fuzzer14include Msf::Auxiliary::Scanner1516def initialize17super(18'Name' => 'SMTP Simple Fuzzer',19'Description' => 'SMTP Simple Fuzzer',20'References' => [21['URL', 'http://www.ietf.org/rfc/rfc2821.txt'],22],23'Author' => 'justme',24'License' => MSF_LICENSE,25'Notes' => {26'Stability' => [CRASH_SERVICE_DOWN],27'SideEffects' => [],28'Reliability' => []29}30)3132register_options([33Opt::RPORT(25),34OptInt.new('STARTLEN', [true, 'Length of the string - start number', 100]),35OptInt.new('INTERACTIONS', [false, 'Number of interactions to run', 100]),36OptBool.new('RESPECTORDER', [false, 'Respect order of commands', true]),37OptEnum.new('CMD', [38true, 'Command to fuzzer', 'EHLO',39[40'EHLO',41'HELO',42'MAILFROM',43'RCPTTO',44'DATA',45'VRFY',46'EXPN'47], 'EHLO'48])49])50end5152def smtp_send(data = '', con: true)53@result = ''54@coderesult = ''55if con56@connected = false57connect58end59@connected = true60sock.put(data)61@result = sock.get_once62@codresult = @result[0..2]63rescue StandardError => e64print_error(e.to_s)65end6667def run_host(_ip)68last_str = nil69last_inp = nil70last_err = nil7172cnt = datastore['STARTLEN'] - 173741.upto(datastore['INTERACTIONS']) do |interaction|75cnt += 17677str = fuzzer_gen_string(cnt)78cmd = datastore['CMD']7980begin81if datastore['RESPECTORDER']82case cmd83when 'HELO', 'EHLO', 'VRFY', 'EXPN'84c = datastore['CMD'] + ' ' + str + "\r\n"85smtp_send(c)86# print_status(c)87disconnect8889when 'MAILFROM'90c = "EHLO localhost\r\n"91smtp_send(c)92# print_status(c)93c = 'MAIL FROM:<' + str + ">\r\n"94smtp_send(c)95disconnect96# print_status(c)97when 'RCPTTO'98c = "EHLO localhost\r\n"99smtp_send(c)100# print_status(c)101c = 'MAIL FROM:<' + datastore['MAILFROM'] + ">\r\n"102smtp_send(c, con: false)103# print_status(c)104c = 'RCPT TO:<' + str + ">\r\n"105smtp_send(c, con: false)106# print_status(c)107disconnect108when 'DATA'109c = "EHLO localhost\r\n"110smtp_send(c)111# print_status(c)112c = 'MAIL FROM:<' + datastore['MAILFROM'] + ">\r\n"113smtp_send(c, con: false)114# print_status(c)115c = 'RCPT TO:<' + datastore['MAILTO'] + ">\r\n"116smtp_send(c, con: false)117# print_status(c)118c = "DATA \r\n"119smtp_send(c, con: false)120c = str + "\r\n.\r\n"121smtp_send(c, con: false)122# print_status(c)123disconnect124end125else126c = datastore['CMD'] + ' ' + str + "\r\n"127smtp_send(c)128# print_status(c)129disconnect130end131132print_status("Fuzzing with iteration #{interaction}\n #{@result}")133rescue ::Interrupt134print_status("Exiting on interrupt: iteration #{interaction} using string #{str}")135raise $ERROR_INFO136rescue StandardError => e137last_err = e138# ensure139# disconnect140end141142if !@connected143if last_str144print_status("The service may have crashed: iteration:#{interection - 1} String=''#{last_str}'' error=#{last_err}")145else146print_status("Could not connect to the service: #{last_err}")147end148break149end150151last_str = str152last_inp = @last_fuzzer_input153end154end155end156157158