Saltar al contenido ForoHackers

Shadow stacks and CFI, explained with a CTF mindset

Análisis de binariosDesarrollo de exploitsFormación en seguridad
#1217 · rop_gadget_goblin · · Denunciar

Following the stack-frame thread, here is the next layer of the story, in defender language.

The problem the frame diagram showed: the return address sits on the same stack as the data, so a bug that writes too far can change where ret goes. Mitigations attack that from different sides:

  • Canaries detect that something overwrote the area between buffer and return address.
  • NX says data pages are not executable, so injected bytes cannot simply run.
  • ASLR / PIE randomize addresses so the attacker needs to know where things are.
  • Shadow stack: the CPU keeps a second copy of every return address in a separate protected region, and on ret compares the two. A mismatch stops the program. The overwritten copy on the normal stack stops mattering.
  • CFI (control-flow integrity): before an indirect jump or call, check that the target is a valid destination, for example the start of a function with a matching type. A jump into the middle of a function is refused.

None of these is perfect on its own. They stack. Each one removes a class of easy wins and raises the cost of the next one, which is why CTF boxes are usually built with some of them off, so the exercise isolates one idea at a time.

When you read a challenge, the first question should be: which of these are on? It tells you what kind of challenge it is.

#2174 · sh3llc0d3_sh3ph3rd · · Denunciar

That "which of these are on?" question is the best triage I know. checksec-style tools tell you in a second, and the answer decides whether you are reading a lesson about overflows, about leaks, or about control flow.

#2175 · ghost_in_the_heap · · Denunciar

Good list. One footnote: all of these protect the control flow. Data-only corruption (changing a flag, a length, a permission bit) does not touch the return address and passes right through every item above. A memory-safe language or careful allocator design is the answer to that class, not another mitigation.

#2176 · undefined_behaviour_enjoyer · · Denunciar

And in C and C++ the root cause is often undefined behaviour that the compiler then "optimizes" in surprising ways. Fix the bug and the mitigation becomes insurance instead of the only thing between you and trouble.

#2177 · rop_gadget_goblin · · Denunciar

Agreed on both. The mitigations are a seat belt, not a driving licence.

Inicia sesión o únete para responder.