X86_64 From Source Code to Binary: What Does GCC Actually Do ? DEP / NX
Having explained how GCC options like -fstack-protector works in my preceding article , it's time to explain how to set the stack non executable and what does that mean. To illustrate this, I will use the following program : #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #define PORT 8080 #define BUFFER_SIZE 64 #define _NOTEST #ifndef _NOTEST…
The C program provided illustrates a stack-based buffer overflow vulnerability. The function `handle_client` receives data from a client, then copies the entire incoming request (which can be up to 256 bytes) into a buffer that can only hold 64 bytes. This overwrites adjacent memory, including the saved return address on the stack.
The vulnerability arises due to the use of the `strcpy()` function, which does not perform bounds checking. If the `request` string is longer than 64 bytes, it will overflow the `buffer` array and overwrite critical data on the stack, such as the saved return address. This can potentially allow an attacker to redirect the program's control flow to malicious code of their choosing.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.