Skip to content

hypnguyen1209/offensive-claude / skills/exploit-development

exploit-development

Verified

Use when turning a memory-corruption bug into a working PoC — stack/ROP, glibc heap & FSOP, format strings, browser/JIT type confusion & UAF, Linux/Windows kernel LPE against ASLR/DEP/CFG/CET/V8-Sandbox

scripts/safe_linking.py

View on GitHub
#!/usr/bin/env python3
"""
safe_linking.py - glibc 2.32+ safe-linking encode/decode helper for tcache/fastbin fd.

Safe-linking stores a chunk's forward pointer as:
    mangled = (chunk_addr >> 12) ^ next_ptr
To poison a freed chunk's fd so the next allocation lands at `target`, write
`encode(chunk_addr, target)` into the chunk's fd field. Decoding recovers the real
pointer from a leaked mangled value (and can recover the heap base from a leaked fd).

Also enforces the 2.32 alignment check: returned chunks must be 16-byte aligned.

Usage:
    python3 safe_linking.py encode --chunk 0x555555559290 --target 0x7ffff7fae6a0
    python3 safe_linking.py decode --mangled 0x555500055ad8 --chunk 0x555555559290
    python3 safe_linking.py heapbase --mangled 0x55500005589  # recover heap base from a leaked fd
    python3 safe_linking.py --import   # use the encode()/decode() functions from your own exploit

Dependencies: none (pure Python 3).
"""
import argparse
import sys


def encode(chunk_addr: int, target: int) -> int:
    """Value to write into chunk.fd so malloc returns `target` next."""
    if target & 0xf:
        sys.stderr.write(f"[!] target {hex(target)} not 16-byte aligned -> 2.32 abort\n")
    return (chunk_addr >> 12) ^ target


def decode(mangled: int, chunk_addr: int) -> int:
    """Recover the real next pointer from a mangled fd whose chunk addr is known."""
    return (chunk_addr >> 12) ^ mangled


def recover_heap_base(leaked_fd: int) -> int:
    """A leaked *head* tcache fd (last chunk, next_ptr==0) equals (chunk_addr >> 12).
    Reverse the >>12 to recover the heap page base (low 12 bits are 0)."""
    return leaked_fd << 12


def main():
    ap = argparse.ArgumentParser(description="glibc safe-linking helper")
    sub = ap.add_subparsers(dest="cmd")

    e = sub.add_parser("encode")
    e.add_argument("--chunk", required=True)
    e.add_argument("--target", required=True)

    d = sub.add_parser("decode")
    d.add_argument("--mangled", required=True)
    d.add_argument("--chunk", required=True)

    h = sub.add_parser("heapbase")
    h.add_argument("--mangled", required=True)

    args = ap.parse_args()
    if args.cmd == "encode":
        v = encode(int(args.chunk, 0), int(args.target, 0))
        print(f"write into fd: {hex(v)}")
    elif args.cmd == "decode":
        v = decode(int(args.mangled, 0), int(args.chunk, 0))
        print(f"real next ptr: {hex(v)}")
    elif args.cmd == "heapbase":
        print(f"heap base ~= {hex(recover_heap_base(int(args.mangled, 0)))}")
    else:
        ap.print_help()


if __name__ == "__main__":
    main()
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 197kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall