Skip to content
All tools
Binary exploitationRuns locallyNo account

Cyclic pattern generator and offset finder

Generate a de Bruijn sequence and find the exact overflow offset from a crashed register value - the pwntools cyclic workflow, in the browser.

Open in ctfpal

A de Bruijn sequence has the property that every substring of length n appears exactly once. Feed one into a program that overflows, and the four or eight bytes that end up in the instruction pointer identify their own position in the sequence - so one crash gives you the exact offset, with no counting and no binary search.

The whole workflow

  • Generate a pattern comfortably longer than the buffer - 200 bytes for a small stack buffer.
  • Feed it to the program and let it crash.
  • Read the value in EIP/RIP from the debugger, or from the crash report.
  • Look that value up in the sequence. Its index is the number of bytes before the return address.

Note the subsequence length: pwntools defaults to 4, which is right for 32-bit. On 64-bit use 8, or the lookup finds an ambiguous match.

Worked example

Finding an offset

Input

0x6161616c (the value found in EIP after a crash)

Result

Offset 44 - the return address starts 44 bytes into your input

`laaa` in little-endian. The four bytes name their own position.

Load this example in the workspace

Go deeper

Related tools