-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanary_test.c
More file actions
23 lines (21 loc) · 768 Bytes
/
Copy pathcanary_test.c
File metadata and controls
23 lines (21 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Demo del stack canary.
//
// Compilar dos veces:
// gcc -fstack-protector-all canary_test.c -o canary_on
// gcc -fno-stack-protector canary_test.c -o canary_off
//
// Ejecutar ambos con un argumento largo (>16 bytes) y comparar:
// ./canary_on AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ← *** stack smashing detected ***
// ./canary_off AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ← segfault o ejecución sospechosa
#include <stdio.h>
#include <string.h>
void copy_input(char *src) {
char buf[16];
strcpy(buf, src); // ⚠ overflow si src > 15 chars + null
printf("[ok] buf = \"%s\"\n", buf);
}
int main(int argc, char *argv[]) {
if (argc < 2) { printf("Uso: %s <input>\n", argv[0]); return 1; }
copy_input(argv[1]);
return 0;
}