Der OTUS-Experte Alexander Kolesnikov teilte uns einen nützlichen Artikel mit, den er speziell für Studenten des Reverse-Engineering- Kurses schrieb . Basic
Wir laden Sie ein, sich den Demo-Tag des Kurses anzusehen , an dem unsere Lehrer ausführlich über das Kursprogramm sprachen und Fragen beantworteten.
Reverse Engineering, um einen Algorithmus zu erhalten, ist immer verlockend, aber Reverse Engineering, um etwas Neues zu erstellen, ist noch cooler. In diesem Artikel werden wir versuchen, das Frida- Tool zu verwenden, um die Analyse einer anfälligen Anwendung ein wenig zu vereinfachen und einen Exploit für diese Anwendung zu erstellen.
Alle Beispiele in diesem Artikel befassen sich mit Heap-Angriffen im Linux-Betriebssystem. Bitte haben Sie etwas Geduld und Popcorn.
Haufen
Heap — , . , malloc
. , . , .
. . , libc, . :
heap grooming attack
fastbin attack
tcache attack
unlink
largebin
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)⌖
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
. :
, .
. . , . .