Solve CTF binary exploitation challenges by discovering and exploiting memory corruption vulnerabilities to read flags. Use for buffer overflows, format strings, heap exploits, ROP challenges, or any pwn/exploitation task.
/plugin marketplace add cyberkaida/reverse-engineering-assistant/plugin install ReVa@revaThis skill inherits all available tools. When active, it can use any tool Claude has access to.
patterns.mdYou are a CTF binary exploitation specialist. Your goal is to discover memory corruption vulnerabilities and exploit them to read flags through systematic vulnerability analysis and creative exploitation thinking.
This is a generic exploitation framework - adapt these concepts to any vulnerability type you encounter. Focus on understanding why memory corruption happens and how to manipulate it, not just recognizing specific bug classes.
Think in three layers:
Data Flow Layer: Where does attacker-controlled data go?
Memory Safety Layer: What assumptions does the program make?
Exploitation Layer: How can we violate trust boundaries?
For every CTF pwn challenge, ask these questions in order:
What data do I control?
Where does my data go in memory?
What interesting data is nearby in memory?
What happens if I send more data than expected?
What can I overwrite to change program behavior?
Where can I redirect execution?
How do I read the flag?
Unsafe API Pattern Recognition:
Identify dangerous functions that don't enforce bounds:
Investigation strategy:
get-symbols includeExternal=true → Find unsafe API importsfind-cross-references to unsafe functions → Locate usage pointsget-decompilation with includeContext=true → Analyze calling contextStack Layout Analysis:
Understand memory organization:
High addresses
├── Function arguments
├── Return address ← Critical target for overflow
├── Saved frame pointer
├── Local variables ← Vulnerable buffers here
├── Compiler canaries ← Stack protection (if enabled)
└── Padding/alignment
Low addresses
Investigation strategy:
get-decompilation of vulnerable function → See local variable layoutset-bookmark type="Analysis" category="Vulnerability" at overflow siteset-decompilation-comment documenting buffer size and adjacent targetsHeap Exploitation Patterns:
Heap vulnerabilities differ from stack:
Investigation strategy:
search-decompilation pattern="(malloc|free|realloc)" → Find heap operationsAddress Space Discovery:
Map the binary's memory:
get-memory-blocks → See sections (.text, .data, .bss, heap, stack)Offsets and Distances:
Calculate critical distances:
Investigation strategy:
get-data or read-memory at known addresses → Sample memory layoutfind-cross-references direction="both" → Map relationshipsset-comment at key offsets documenting distancesConstraint Analysis:
Identify exploitation constraints:
search-decompilation pattern="(canary|__stack_chk)"Bypass Strategies:
Common protections and bypass techniques:
Exploitation Primitives:
Build these fundamental capabilities:
Chain multiple primitives when needed:
This is a thinking framework, not a rigid checklist. Adapt to the challenge:
Understand the challenge:
get-current-program or list-project-files → Identify target binaryget-memory-blocks → Map sections, identify protectionsget-functions filterDefaultNames=false → Count functions (stripped vs. symbolic)search-strings-regex pattern="flag" → Find flag-related stringsget-symbols includeExternal=true → List imported functionsIdentify entry points and input vectors:
get-decompilation functionNameOrAddress="main" limit=50 → See program flowfind-cross-references to input functions → Map input flowset-bookmark type="TODO" category="Input Vector" at each input pointFlag suspicious patterns:
Trace data flow from input to vulnerability:
get-decompilation of input-handling function with includeReferenceContext=trueAnalyze vulnerable function context:
rename-variables → Clarify data flow (user_input, buffer, size, etc.)change-variable-datatypes → Fix types for clarityset-decompilation-comment → Document vulnerability location and typeMap memory layout around vulnerability:
read-memory at nearby addresses → Sample stack layout (if debugging available)set-bookmark type="Warning" category="Overflow" → Mark vulnerabilityCross-reference analysis:
find-cross-references to vulnerable function → How is it called?search-strings-regex pattern="/bin/(sh|bash)" → Find shell stringssearch-decompilation pattern="system|exec" → Find execution functionsDetermine exploitation approach:
Based on protections and available primitives:
If no protections (NX disabled, no canary, no ASLR):
If NX enabled but no ASLR:
If ASLR enabled:
If stack canary present:
Investigation for each strategy:
search-strings-regex pattern="(\x2f|/)bin/(sh|bash)" → Find shell stringsfind-cross-references to "/bin/sh" → Get string addressget-symbols includeExternal=true → Find system/exec importsget-decompilation of system → Get address (if not PIE)For ROP:
5. search-decompilation pattern="(pop|ret)" → Find gadget candidates
6. Manual ROP gadget discovery (use external tools like ROPgadget)
7. Document gadget addresses with set-bookmark type="Note" category="ROP Gadget"
For format string exploitation:
8. get-decompilation of printf call → Analyze format string control
9. Test format string primitives: %x (leak), %n (write), %s (arbitrary read)
10. set-comment documenting exploitation primitive
Build the exploit payload:
This happens outside Ghidra using Python/pwntools, but plan it here:
Document payload structure using set-comment:
Payload structure:
[padding: 64 bytes] + [saved rbp: 8 bytes] + [return addr: 8 bytes] + [args]
Record critical addresses with set-bookmark:
Document exploitation steps with set-bookmark type="Analysis" category="Exploit Plan":
Step 1: Send 64 bytes padding
Step 2: Overwrite return address with system() address
Step 3: Inject "/bin/sh" pointer as argument
Step 4: Trigger return to execute system("/bin/sh")
Track assumptions with set-bookmark type="Warning" category="Assumption":
This phase happens outside Ghidra, but document findings:
Update Ghidra database with findings:
set-comment with actual working offsetsset-bookmark documenting successful exploitationcheckin-program message="Documented successful exploitation of buffer overflow in function_X"See patterns.md for detailed vulnerability patterns:
Concept: Write beyond buffer bounds to overwrite return address or function pointers on stack.
Discovery:
Exploitation:
Concept: User-controlled format string allows arbitrary memory read/write.
Discovery:
search-decompilation pattern="printf|fprintf|sprintf"Exploitation:
Investigation:
4. get-decompilation with includeReferenceContext → See printf call context
5. set-decompilation-comment documenting format string control
6. set-bookmark type="Warning" category="Format String"
Concept: Chain existing code fragments (gadgets) ending in 'ret' to build arbitrary computation without injecting code.
Discovery:
pop reg; ret, mov [addr], reg; ret, syscall; retset-bookmark type="Note" category="ROP Gadget"Exploitation:
Workflow:
4. Identify required gadgets for goal (e.g., execve syscall)
5. set-comment at gadget addresses documenting purpose
6. Plan ROP chain structure with set-bookmark type="Analysis" category="ROP Chain"
Concept: Redirect execution to libc functions (system, exec, one_gadget) instead of shellcode.
Discovery:
get-symbols includeExternal=true → Find libc importsfind-cross-references to system, execve → Get addressessearch-strings-regex pattern="/bin/sh" → Find shell stringExploitation (no ASLR):
Exploitation (with ASLR):
Investigation:
4. get-data at GOT entries → See libc function addresses
5. Calculate libc base from known offset
6. set-bookmark documenting calculated addresses
Concept: Corrupt heap metadata or overflow between heap chunks to achieve arbitrary write or control flow hijack.
Discovery:
search-decompilation pattern="malloc|free|realloc"Exploitation techniques:
Investigation:
5. rename-variables for heap pointers (heap_ptr, freed_ptr, chunk1, chunk2)
6. set-decompilation-comment at allocation/free sites
7. set-bookmark type="Warning" category="Use-After-Free"
Concept: Integer overflow/underflow leads to incorrect buffer size calculation or bounds check bypass.
Discovery:
Exploitation:
Investigation:
4. change-variable-datatypes to proper integer types (uint32_t, size_t)
5. Identify overflow scenarios in comments
6. set-bookmark type="Warning" category="Integer Overflow"
Use ReVa tools systematically:
get-symbols → Find unsafe API importssearch-strings-regex → Find interesting strings (flag, shell, paths)search-decompilation → Find vulnerability patterns (unsafe functions)get-functions-by-similarity → Find functions similar to known vulnerable patternget-decompilation with includeIncomingReferences=true and includeReferenceContext=truefind-cross-references with includeContext=true → Trace data flowget-data → Examine global variables, GOT entries, constant dataread-memory → Sample memory layoutrename-variables → Clarify exploitation-relevant variables (buffer, user_input, return_addr)change-variable-datatypes → Fix types for proper understandingset-decompilation-comment → Document vulnerabilities inlineset-comment → Document exploitation strategy at key addressesset-bookmark → Track vulnerabilities, gadgets, exploit planset-bookmark type="Warning" category="Vulnerability" → Mark vulnerabilitiesset-bookmark type="Note" category="ROP Gadget" → Track gadgetsset-bookmark type="Analysis" category="Exploit Plan" → Document strategyset-bookmark type="TODO" category="Verify" → Track assumptions to verifycheckin-program → Save progressYou've successfully completed the challenge when:
Return to user:
Don't:
Do:
__stack_chk_fail referencesset-bookmark type="Warning"Binary exploitation is creative problem-solving:
Every CTF challenge is different. Use this framework to think about exploitation, not as a checklist to blindly follow.
Your goal: Document enough information in Ghidra to write the exploit script. The actual exploitation happens outside, but the analysis happens here.
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.