-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmt_vuln.c
More file actions
25 lines (22 loc) · 827 Bytes
/
Copy pathfmt_vuln.c
File metadata and controls
25 lines (22 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Programa vulnerable a format string. La variable `target` cambia si el
// atacante consigue hacer printf escribir vía %n.
//
// Compilar (con NX desactivado para coherencia con el resto del cap):
// make 0x360
#include <stdio.h>
#include <string.h>
int target = 0xdeadc0de; // global → segmento DATA, dirección estable
int main(int argc, char *argv[]) {
char buf[256];
if (argc < 2) {
printf("Uso: %s <format>\n", argv[0]);
printf(" Pista: la dirección de target es %p\n", (void *)&target);
return 1;
}
strncpy(buf, argv[1], sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
printf(buf); // ⚠ format string vulnerable
printf("\n");
printf("[after] target = 0x%x (esperado: 0xdeadc0de si no fue alterado)\n", target);
return 0;
}