hacktricks/binary-exploitation/common-binary-protections-and-bypasses/stack-canaries/print-stack-canary.md
Carlos Polop 731fca1d57 a
2024-07-18 18:14:56 +02:00

4.7 KiB

Print Stack Canary

{% hint style="success" %} Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}

Enlarge printed stack

Imagine a situation where a program vulnerable to stack overflow can execute a puts function pointing to part of the stack overflow. The attacker knows that the first byte of the canary is a null byte (\x00) and the rest of the canary are random bytes. Then, the attacker may create an overflow that overwrites the stack until just the first byte of the canary.

Then, the attacker calls the puts functionality on the middle of the payload which will print all the canary (except from the first null byte).

With this info the attacker can craft and send a new attack knowing the canary (in the same program session).

Obviously, this tactic is very restricted as the attacker needs to be able to print the content of his payload to exfiltrate the canary and then be able to create a new payload (in the same program session) and send the real buffer overflow.

CTF examples:

Arbitrary Read

With an arbitrary read like the one provided by format strings it might be possible to leak the canary. Check this example: https://ir0nstone.gitbook.io/notes/types/stack/canaries and you can read about abusing format strings to read arbitrary memory addresses in:

{% content-ref url="../../format-strings/" %} format-strings {% endcontent-ref %}

{% hint style="success" %} Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}