Use-after-free exploit techneeq

Written by

in

Use-after-free depends on the codebase you’re working on to determine whether it’s exploitable… but given an example code base, it’s insidiously easy to create…

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void func()
{
	printf("Hello world\n");
}

void func2()
{
	printf("How did I get here?\n");
}


struct s_ops {
	void (* f) ();
};


int main()
{
	struct s_ops *a = malloc(sizeof(struct s_ops));
	
	a->f = func;

	a->f();

	free(a); // use-after-free... free here, and use 'a' again later on

	struct s_ops *b = malloc(sizeof(struct s_ops));
	b->f = func2;


	a->f();
	
}

Output:

Hello world
How did I get here?

Comments

Leave a Reply