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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
2.3 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2005-12-05 05:00:27 +00:00
module Msf
###
#
# 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
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
#
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
2013-08-30 16:28:33 -05:00
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
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
#
# 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)
fd = super
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
# Wait for a banner to arrive...
2010-02-26 19:06:26 +00:00
self.banner = fd.get_once(-1, 30)
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
# Return the file descriptor to the caller
fd
end
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
#
2010-02-26 19:06:26 +00:00
# Connect and login to the remote IMAP server using the credentials
2005-12-05 05:00:27 +00:00
# that have been supplied in the exploit options.
#
def connect_login(global = true)
ftpsock = connect(global)
2013-08-30 16:28:33 -05:00
if !(user and pass)
2005-12-05 05:00:27 +00:00
print_status("No username and password were supplied, unable to login")
return false
end
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
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")
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
if (res !~ /^a001 OK/)
print_status("Authentication failed")
return false
end
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
return true
end
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
#
# 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
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
##
#
# Wrappers for getters
#
##
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
#
# 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
2013-08-30 16:28:33 -05:00
2005-12-05 05:00:27 +00:00
#
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
2010-02-26 19:06:26 +00:00
end