void unlink(OBJ* P){ OBJ* BK; OBJ* FD; BK=P->bk; FD=P->fd; FD->bk=BK; BK->fd=FD; } int main(int argc, char* argv[]){ malloc(1024); OBJ* A = (OBJ*)malloc(sizeof(OBJ)); OBJ* B = (OBJ*)malloc(sizeof(OBJ)); OBJ* C = (OBJ*)malloc(sizeof(OBJ));
// double linked list: A <-> B <-> C A->fd = B; B->bk = A; B->fd = C; C->bk = B;
printf("here is stack address leak: %p\n", &A); printf("here is heap address leak: %p\n", A); printf("now that you have leaks, get shell!\n"); // heap overflow! gets(A->buf);
gdb-peda$ x/20x 0x804b408 0x804b408: 0x00000000 0x00000019 0x0804b428 0x00000000 0x804b418: 0x00000000 0x00000000 0x00000000 0x00000019 0x804b428: 0x0804b440 0x0804b410 0x00000000 0x00000000 0x804b438: 0x00000000 0x00000019 0x00000000 0x0804b428 0x804b448: 0x00000000 0x00000000 0x00000000 0x00020bb1 gdb-peda$ c Continuing. here is stack address leak: 0xffffd6c4 here is heap address leak: 0x804b410 now that you have leaks, get shell!