-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_overflow.c
More file actions
29 lines (23 loc) · 989 Bytes
/
Copy pathauth_overflow.c
File metadata and controls
29 lines (23 loc) · 989 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
26
27
28
29
// Variante del libro: muestra explícitamente las direcciones de las variables
// para entender el layout y el offset que necesita el overflow.
#include <stdio.h>
#include <string.h>
int check_authentication(char *password) {
int auth_flag = 0;
char password_buffer[16];
printf("\n[debug] auth_flag @ %p (valor inicial 0)\n", (void *)&auth_flag);
printf("[debug] password_buffer @ %p (capacidad 16)\n", (void *)password_buffer);
printf("[debug] distancia entre ambos: %ld bytes\n",
(char *)&auth_flag - password_buffer);
strcpy(password_buffer, password); // ⚠ overflow
printf("[debug] tras strcpy, auth_flag = 0x%x\n", auth_flag);
return auth_flag;
}
int main(int argc, char *argv[]) {
if (argc < 2) { printf("Uso: %s <password>\n", argv[0]); return 1; }
if (check_authentication(argv[1]))
printf("\n>>> Acceso garantizado <<<\n");
else
printf("\n>>> Acceso DENEGADO <<<\n");
return 0;
}