-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheap_overflow.c
More file actions
41 lines (33 loc) · 1.16 KB
/
Copy pathheap_overflow.c
File metadata and controls
41 lines (33 loc) · 1.16 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
// Heap overflow simple: dos chunks, el primero tiene un buffer, el segundo
// tiene un puntero a función. Un overflow del buffer sobrescribe el puntero.
//
// Esta versión es ilustrativa. Heap exploitation real requiere atacar
// metadatos de glibc (tcache poisoning, House of *...), no es trivial.
//
// Compilar:
// make 0x350
#include "../0x260/0x265_hacking.h"
void normal() { puts("[+] función normal()"); }
void winner() { puts("[!] función winner() — hijack OK"); }
struct datos {
char buffer[16];
void (*action)();
};
int main(int argc, char *argv[]) {
struct datos *a, *b;
a = (struct datos *) ec_malloc(sizeof(struct datos));
b = (struct datos *) ec_malloc(sizeof(struct datos));
a->action = normal;
b->action = normal;
printf("[debug] a @ %p (action @ %p)\n", a, &a->action);
printf("[debug] b @ %p (action @ %p)\n", b, &b->action);
if (argc < 2) {
printf("Uso: %s <input>\n", argv[0]);
return 1;
}
strcpy(a->buffer, argv[1]); // ⚠ overflow
printf("Llamando a a->action: "); a->action();
printf("Llamando a b->action: "); b->action();
free(a); free(b);
return 0;
}