Files
metasploit-gs/lib/msf/core/exploit/imap.rb
T

114 lines
2.3 KiB
Ruby
Raw Normal View History

2005-12-05 05:00:27 +00:00
module Msf
require 'msf/core/exploit/tcp'
###
#
# This module exposes methods that may be useful to exploits that deal with
# servers that speak the IMAP protocol.
#
###
module Exploit::Remote::Imap
include Exploit::Remote::Tcp
#
2006-11-07 14:39:13 +00:00
# Creates an instance of an IMAP exploit module.
2005-12-05 05:00:27 +00:00
#
def initialize(info = {})
super
2006-11-07 14:39:13 +00:00
# Register the options that all IMAP exploits may make use of.
2005-12-05 05:00:27 +00:00
register_options(
[
Opt::RHOST,
Opt::RPORT(143),
OptString.new('IMAPUSER', [ false, 'The username to authenticate as']),
OptString.new('IMAPPASS', [ false, 'The password for the specified username'])
2006-11-07 14:39:13 +00:00
], Msf::Exploit::Remote::Imap)
2005-12-05 05:00:27 +00:00
end
#
# This method establishes a IMAP connection to host and port specified by
# the RHOST and RPORT options, respectively. After connecting, the banner
# message is read in and stored in the 'banner' attribute.
#
def connect(global = true)
print_status("Connecting to IMAP server #{rhost}:#{rport}...")
fd = super
# Wait for a banner to arrive...
self.banner = fd.get_once
print_status("Connected to target IMAP server.")
# Return the file descriptor to the caller
fd
end
#
# Connect and login to the remote IMAP server using the credentials
# that have been supplied in the exploit options.
#
def connect_login(global = true)
ftpsock = connect(global)
if (not (user and pass))
print_status("No username and password were supplied, unable to login")
return false
end
print_status("Authenticating as #{user} with password #{pass}...")
2006-12-29 11:33:16 +00:00
res = raw_send_recv("a001 LOGIN #{user} #{pass}\r\n")
2005-12-05 05:00:27 +00:00
if (res !~ /^a001 OK/)
print_status("Authentication failed")
return false
end
return true
end
#
# This method transmits an IMAP command and waits for a response. If one is
# received, it is returned to the caller.
#
def raw_send_recv(cmd, nsock = self.sock)
nsock.put(cmd)
nsock.get_once
end
##
#
# Wrappers for getters
#
##
#
# Returns the user string from the 'IMAPUSER' option.
2005-12-05 05:00:27 +00:00
#
def user
datastore['IMAPUSER']
2005-12-05 05:00:27 +00:00
end
#
2006-02-08 01:12:26 +00:00
# Returns the user string from the 'IMAPPASS' option.
2005-12-05 05:00:27 +00:00
#
def pass
2006-02-08 01:12:26 +00:00
datastore['IMAPPASS']
2005-12-05 05:00:27 +00:00
end
protected
#
# This attribute holds the banner that was read in after a successful call
# to connect or connect_login.
#
attr_accessor :banner
end
2008-10-19 21:03:39 +00:00
end