Skip to content

Latest commit

 

History

History
43 lines (24 loc) · 1.89 KB

File metadata and controls

43 lines (24 loc) · 1.89 KB
description
09/19/2023

🐤 Stack Canaries

Introduction

In this tutorial, we will be defeating stack canaries, a common mitigation technique for buffer overflows.

However, just like anything else, we can bypass them with the right effort and determination!

Stack canaries serve as warnings to the computer that a buffer overflow has occurred and will immediately crash the program.

High-Level

Simply put, a stack canary is a randomly chosen number that sits between any buffers and the return address inside of a function.

[Buffer] Stack Canary [Return address] -> Buffer Overflow -> PC -> Canary = Different Number? -> Crash

{% embed url="https://www.youtube.com/watch?v=N7kGd76evsM" %}

These implementations are very lightweight and rather effective. However, they are fairly easy to bypass.

How Does it Work?

  1. When the function is ready to return, before we jump to the return address, we check the canary value to ensure it is the same, original value.
  2. If it is not the same value, a stack smashing error will be issued; crashing the program.
  3. The attacker has essentially overwritten the canary value and alerted the system.

Methods for Bypass

  1. Stack Leak:

The attacker could obtain the value directly from the stack, write the value back in during a BOF, and successfully bypass the canary.

  1. Guessing the Value (Incremental Solving):

Guess one value at a time (256 possibilities/value). The program will not crash if we guess the first correct byte, meaning we can deduce one-by-one until we get all correct values (in a 32-bit scenario).

The worst case scenario would be we would need to guess 1,024 times.

256 (possibilities) x 4 (bytes) = 1,024 (Guesses)