mirror of
https://github.com/nganhkhoa/CTF-All-In-One.git
synced 2025-04-10 12:57:32 +07:00
39 lines
1.2 KiB
C
39 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main() {
|
|
unsigned long long stack_var = 0x21;
|
|
fprintf(stderr, "Allocating 3 buffers.\n");
|
|
char *a = malloc(9);
|
|
char *b = malloc(9);
|
|
char *c = malloc(9);
|
|
strcpy(a, "AAAAAAAA");
|
|
strcpy(b, "BBBBBBBB");
|
|
strcpy(c, "CCCCCCCC");
|
|
fprintf(stderr, "1st malloc(9) %p points to %s\n", a, a);
|
|
fprintf(stderr, "2nd malloc(9) %p points to %s\n", b, b);
|
|
fprintf(stderr, "3rd malloc(9) %p points to %s\n", c, c);
|
|
|
|
fprintf(stderr, "Freeing the first one %p.\n", a);
|
|
free(a);
|
|
fprintf(stderr, "Then freeing another one %p.\n", b);
|
|
free(b);
|
|
fprintf(stderr, "Freeing the first one %p again.\n", a);
|
|
free(a);
|
|
|
|
fprintf(stderr, "Allocating 4 buffers.\n");
|
|
unsigned long long *d = malloc(9);
|
|
*d = (unsigned long long) (((char*)&stack_var) - sizeof(d));
|
|
fprintf(stderr, "4nd malloc(9) %p points to %p\n", d, &d);
|
|
char *e = malloc(9);
|
|
strcpy(e, "EEEEEEEE");
|
|
fprintf(stderr, "5nd malloc(9) %p points to %s\n", e, e);
|
|
char *f = malloc(9);
|
|
strcpy(f, "FFFFFFFF");
|
|
fprintf(stderr, "6rd malloc(9) %p points to %s\n", f, f);
|
|
char *g = malloc(9);
|
|
strcpy(g, "GGGGGGGG");
|
|
fprintf(stderr, "7th malloc(9) %p points to %s\n", g, g);
|
|
}
|