Pakar OTUS - Alexander Kolesnikov membagikan kepada kami artikel bermanfaat, yang ia tulis khusus untuk siswa kursus Rekayasa Balik. Dasar
Kami mengundang Anda untuk menonton hari demo kursus , di mana guru kami berbicara secara rinci tentang program kursus dan menjawab pertanyaan.
Rekayasa terbalik untuk mendapatkan algoritme selalu menggoda, tetapi rekayasa balik untuk membuat sesuatu yang baru bahkan lebih keren. Pada artikel ini, kami akan mencoba menggunakan alat Frida untuk mempermudah proses analisis aplikasi yang rentan dan membuat exploit untuk aplikasi ini sedikit lebih mudah.
Semua contoh dalam artikel ini akan menangani serangan heap di sistem operasi Linux, jadi kami menyimpan diri kami dengan kesabaran dan popcorn.
Tumpukan
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
. :
, .
. . , . .