FORMAT STRINGS
Improperly handled format strings can lead to memory corruption vulnerabilities, allowing attackers to read from or write to the stack and potentially redirect code execution.
CORRECT USAGE
#example
// gcc -g -m32 -O0 32_format_right.c -o 32_format_right.out
#include <stdio.h>
int main(int argc, char *argv[])
{
char *i = argv[1]; printf("You wrote: %s\n", 1);
}
* the format specifiers are also in scanf and may be vulnerable as well
root@dev:~$ ./32_format_right.out
You wrote: (null)
* nothing was entered by the user hence, output is null
root@dev:~$ ./32_format_right.out asdf
You wrote: asdf
INCORRECT USAGE
PLAYING WITH VULNERABILITY (TESTING)
EXPLOITATION THROUGH FORMAT STRING (OVERWRITING VARIABLES)
Static variables are stored in the data section, not on the stack, preventing traditional buffer overflows. However, attackers can still exploit format string vulnerabilities to write to arbitrary memory, including the data section.
think how scanf() works, devs are writing to an address via the &variableName
printf("[...]%n", &var); where [...] is the number of characters needed to use to set up the string
VULNERABLE PROGRAM 1 (INCORRECT SANITIZATION OF USER INPUT)
VULNERABLE PROGRAM 2
Last updated