فريدا تستكشف استغلال خوارزميات الكومة

شارك خبير OTUS - ألكسندر كولسنيكوف معنا بمقال مفيد ، كتبه خصيصًا لطلاب دورة  الهندسة العكسية. الأساسي







ندعوك  لمشاهدة اليوم التجريبي للدورة ، والذي تحدث فيه مدرسونا بالتفصيل عن برنامج الدورة وأجابوا على الأسئلة.










الهندسة العكسية للحصول على خوارزمية مغرية دائمًا ، لكن الهندسة العكسية لإنشاء شيء جديد أكثر برودة. في هذه المقالة ، سنحاول استخدام أداة Frida لتسهيل عملية تحليل التطبيق الضعيف قليلاً ولإنشاء استغلال لهذا التطبيق أسهل قليلاً.





ستتناول جميع الأمثلة في هذه المقالة هجمات الكومة في نظام التشغيل Linux ، لذا يرجى التحلي بالصبر والفشار.





كومة

الكومة ، أو الكومة ، هي مساحة من الذاكرة تُستخدم لتخصيص الذاكرة ديناميكيًا للكائنات الكبيرة. عادة ، يتم الوصول إلى هذه المنطقة من خلال استدعاء وظيفة malloc



. تتعامل الوظيفة مع طلبات تخصيص الذاكرة وتدير بشكل أساسي هدف الخوارزميات التي توفر الذاكرة بأفضل طريقة وبأفضل كمية. يتم تعديل خوارزميات الذاكرة مع كل إصدار جديد من النواة ، لذلك لا توجد خوارزمية واحدة للإجراءات لتخصيص الذاكرة.





. . , libc, . :





  1. heap grooming attack





  2. fastbin attack





  3. tcache attack





  4. unlink





  5. largebin





  6. unsortedbin attack





, . . — , . , — libc. — .





Frida

frida 2 : frida-trace MemoryMonitor. , . , ,   CTF.





Heap Grooming

, libc 2.23. , , , , . , . 7.  :





#include <stdio.h>
#include <stdlib.h>
int main(void)
{
  unsigned long int *mem0, *mem1, *mem2;
  
  mem0 = malloc(0x10); 
  mem1 = malloc(0x10); 
  mem2 = malloc(0x10); 
  
  printf("Allocated memory on:\nptr0: %p\nptr1: %p\nptr2: %p\n\n", mem0, mem1, mem2);
  
  free(mem0);
  free(mem1);
  free(mem2);
  
  printf("mem0 after free and alloc again: %p\n", malloc(0x10));
  printf("mem1 after free and alloc again: %p\n", malloc(0x10));
  printf("mem2 after free and alloc again: %p\n\n", malloc(0x10));
}
      
      



. :





, , , printf



? printf



frida-trace



. :





Frida-trace -f test -i “malloc”





handler



. “handlers” frida-trace. malloc.js OnLeave



, :





. pico CTF “Are you root”. frida-trace:





, , . , login;



Auth level



. ? malloc 0x10 0x7. , , 0x10, 2 - 0x1514eb0 0x1514ed0. . 





TCACHE

, , tcache



, . , tcache



, tcache



:





#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    unsigned long int *mem0, *mem1;
	  int target;
    
	  mem0 = malloc(0x10);
    mem1 = malloc(0x10);
    target = 0xdead;
    
    printf("mem0: %p\n", mem0);
	  printf("mem1: %p\n", mem1);
	  printf("int:  %p\n\n", &target);
    
    free(mem0);
    free(mem1);
    
 		printf("Next pointer for mem1: %p\n\n", (unsigned long int *)mem1);
 
    *mem1 = (unsigned long int)&target;
 		printf("Next pointer for mem1: %p\n\n", (unsigned long int )mem1);
     
    printf("Malloc Allocated: %p\n\n", malloc(0x10));
	  printf("Malloc Allocated: %p\n\n", malloc(0x10));
}
      
      



, frida-trace , :





, , , . , malloc



. , Use-After-Free. Plaid CTF “cpp”. :





, malloc



. :





, .





. . , . . 






"Reverse-Engineering. Basic"





:

  • « » Frida Windows












All Articles