Skip to main content
Live Webinar with SANS (June 25)— Agentic CTI Automation for Fun & ProfitRegister Free
Mallory
HighPublic exploit

Heap Buffer Overflow in PostgreSQL pgcrypto

IdentifiersCVE-2026-2005CWE-122· Heap-based Buffer Overflow

CVE-2026-2005 is a heap-based buffer overflow in PostgreSQL's pgcrypto extension, specifically in public-key decryption handling within the function pgp_parse_pubenc_sesskey in contrib/pgcrypto/pgp-pubdec.c. During parsing of a decrypted PGP public-key encrypted session key packet, the code sets ctx->sess_key_len = msglen - 3 and then copies that many bytes with memcpy(ctx->sess_key, msg + 1, ctx->sess_key_len) into ctx->sess_key, a fixed-size buffer limited to PGP_MAX_KEY (32 bytes). Because the accepted plaintext length is not properly bounded after PKCS#1 v1.5 unpadding and control_cksum() does not enforce an upper limit, a crafted ciphertext and matching key can cause ctx->sess_key_len to exceed 32 bytes, resulting in an out-of-bounds heap write. PostgreSQL states that a ciphertext provider can exploit this flaw to execute arbitrary code as the operating system user running the database. Affected versions are PostgreSQL before 18.2, 17.8, 16.12, 15.16, and 14.21.

Share:
For your environment

Are you exposed to this one?

Mallory correlates every CVE against your assets, your vendors, and active adversary campaigns. Know which vulnerabilities matter for you, not just which ones are loud.

ANALYST BRIEF

Impact, mitigation & remediation

What it means. What to do now. Patch path, mitigations, and the assume-compromise checklist.

Impact

What an attacker gets, and what they’ve been doing with it.

Successful exploitation can corrupt heap memory in the PostgreSQL backend process and lead to arbitrary code execution as the operating system user running the database service, typically the postgres account. This can result in full compromise of the database instance, unauthorized access to or modification of database contents, privilege escalation within PostgreSQL, and potential compromise of the underlying host within the privileges of the database service account. Public reporting and PoC material also indicate that exploitation may be chained into arbitrary memory read/write and superuser-level database privilege escalation before OS command execution.

Mitigation

If you can’t patch tonight, do this now.

If immediate patching is not possible, reduce exposure by preventing untrusted or user-controlled ciphertext from reaching pgcrypto decryption functions, especially public-key PGP decryption paths. Restrict which users, roles, applications, or SQL paths can invoke pgcrypto functionality; disable or remove pgcrypto where it is not required; restrict extension creation and use in multi-tenant environments; and apply least privilege to the PostgreSQL service account and network access controls to limit reachable attack surface. Monitor for backend crashes, anomalous PGP-related errors, unexpected child processes under the postgres user, and unusual outbound connections from the database host.

Remediation

Patch, then assume compromise.

Upgrade PostgreSQL to a fixed release: 18.2 or later, 17.8 or later, 16.12 or later, 15.16 or later, or 14.21 or later. Debian advisories additionally reference fixed package versions 17.8-0+deb13u1 for Debian trixie and 15.16-0+deb12u1 for Debian bookworm. PostgreSQL minor releases are cumulative, so applying the vendor-provided updated binaries is the recommended remediation.
PUBLIC EXPLOITS

Exploits

1 valid exploit after Mallory filtered fakes, detection scripts, and README-only repos (1 hidden).

VALID 1 / 2 TOTALView more in app
CVE-2026-2005MaturityPoCVerified exploit

This repository is a real Python proof-of-concept exploit for CVE-2026-2005, a heap-based buffer overflow in PostgreSQL's pgcrypto extension during PGP session key parsing. The repo is small and focused: README.md documents the vulnerability and exploitation stages, poc.py contains the full exploit logic, and requirements.txt lists dependencies (psycopg2-binary, pwntools, pycryptodome). The exploit is not part of a larger framework. Its main entry point is poc.py, which connects to a PostgreSQL server using supplied credentials and crafts malicious OpenPGP data to trigger the overflow. Based on the README and visible code, the exploit performs a multi-stage chain: generate RSA material and PGP packets, trigger a heap corruption to leak a heap pointer, use a second corruption to obtain an arbitrary read primitive, scan leaked memory for candidate code pointers, compute/vote on possible PIE bases using symbol offsets from a locally supplied postgres ELF binary, validate the recovered base by reading CurrentUserId, then build an arbitrary write primitive that overwrites CurrentUserId with bootstrap superuser OID 10. Once elevated, it executes an arbitrary OS command through PostgreSQL COPY FROM PROGRAM and prints the output. Operationally, this is more than a simple crash PoC: it includes end-to-end exploitation and post-exploitation command execution, but the payload is still basic and operator-supplied rather than modular, so OPERATIONAL is the best fit. The exploit requires a matching vulnerable PostgreSQL build, pgcrypto enabled, valid DB connectivity, and likely an AArch64 target/build environment due to the explicit pwntools architecture setting. Fingerprintable targets/endpoints are primarily the PostgreSQL host/port and the local postgres binary path used for symbol resolution; there are no hardcoded C2 endpoints or exfiltration destinations.

var77Disclosed May 13, 2026pythonmarkdownnetworkweb
EXPOSURE SURFACE

Affected products & vendors

Products and vendors Mallory has correlated with this vulnerability. Open in Mallory to drill down to specific CPE configurations and version ranges.

VendorProductType
F5Big-Ip Next For Kubernetesapplication
PostgresqlPostgresqlapplication
PostgreSQL Global Development GroupPostgresqlapplication

Vendor-confirmed product mapping. Mallory continuously reconciles this list against your asset inventory.

ACTIVITY FEED

Recent activity

50 sources tracked across advisories, community write-ups, and news. New activity surfaces here as Mallory finds it.

What this page doesn’t show

The version that knows your environment.

This page is what’s public. Mallory adds the parts that aren’t: which of your assets are affected, which adversaries are exploiting it right now, which detections to deploy, and what to do tonight.
Exposure mapping

Query your assets running an affected version, and investigate the blast radius.

Threat actor evidence

Every observed campaign linking this CVE to a named adversary.

Associated malware

Malware families riding this exploit, with evidence and IOCs.

Detection signatures

YARA, Sigma, Snort, and vendor rules, auto-deployed to your SIEM.

Vendor-by-vendor mapping

Cross-references every affected SKU, including bundled OEM variants.

Social activity33

Community discussion across Reddit, Mastodon, and other social sources.