1 730
https://github.com/Maldev-Academy/MaldevAcademyLdr.2
RunPE Implementation With Multiple Evasive Techniques
@reverseengine
29 Oct 2025, 15:56
#include <stdio.h> #include <string.h> void vuln() { char buf[64]; gets(buf); // ❌ Insecure printf("You said: %s\n", buf); } int main() { vuln(); return 0; }If you give more than 64 bytes in input, you can overwrite the Return Address and send the program to your shellcode address instead of returning to main @reverseengine
#include <stdio.h> #include <string.h> void vuln() { char buf[64]; gets(buf); // ❌ ناامن printf("You said: %s\n", buf); } int main() { vuln(); return 0; }اگه توی ورودی بیشتر از 64 بایت بدید میتونی Return Address رو overwrite کنید و برنامه رو به جای برگشت به main بفرستید روی آدرس shellcode خودتون Binary Exploitation It means finding and exploiting bugs or security weaknesses in binary executable programs to change the flow of program execution or execute the attacker's desired code Simpler definition: Suppose you have a C program that takes user input without checking and copies it into a buffer. If you give it more than the buffer capacity, you can write your data into important parts of memory and force the program to do what you want This is called Binary Exploitation, which means using memory or logic bugs to take control of Execution 🧱 Basic Structure of Process Memory: To understand Binary Exploitation, you need to be familiar with the memory structure of a program:
بخش چهارم بافر اورفلوتوضیح heap overflow هیپ جایی که برای تخصیص حافظه پویا با malloc calloc یا new heap overflow زمانی رخ میده که داده ای زیاد در بلاک های heap نوشته بشه متادیتای allocator یا بلاک های همجوار رو خراب میکنه خطاهای heap معمولا با کرش در توابع libc یا هنگام free کردن حافظه دیده میشن و ردگیری اونها با tools مثل valgrind یا heap debugger مفیده کد هیپ در این کد یک بلوک روی heap اختصاص داده شده و بعد با memset مقدار بیشتری از اندازه نوشته میشه هدف دیدن خطا در زمان free یا گزارش valgrind هست کد هیپ فایل any_heap.c:
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *p = malloc(32); if (!p) return 1; printf("allocated 32 bytes on heap\n"); /* intentionally overflow the heap block for any_heap do not use this pattern in real code */ memset(p, 'A', 64); free(p); printf("freed block\n"); return 0; }دستورات اجرا و بررسی heap از valgrind یا malloc debug استفاده کنید تا متادیتا یا خطاها رو ببینید
gcc -g any_heap.c -o any_heap valgrind --leak-check=full ./ any_heap# یا اجرا در محیطی با malloc debug فعال نکات که هنگام نوشتن کد باید بدونیم خطاهای هیپ ممکنه فوری کرش نکنن و اغلب در زمان free یا عملیات بعدی ظاهر میشن از ابزارهایی مثل valgrind یا malloc debug برای ردگیری استفاده کنید
Part 4 Buffer OverflowHeap Overflow Explanation Heap where to allocate dynamic memory with malloc calloc or new Heap overflow occurs when too much data is written to heap blocks Corrupts allocator metadata or adjacent blocks Heap errors are usually seen with crashes in libc functions or when freeing memory and are useful to trace with tools like valgrind or heap debugger Heap Code In this code, a block is allocated on the heap and then written with memset more than the size The goal is to see the error at free time or in valgrind reports Heap Code File any_heap.c:
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *p = malloc(32); if (!p) return 1; printf("allocated 32 bytes on heap\n"); /* intentionally overflow the heap block for any_heap do not use this pattern in real code */ memset(p, 'A', 64); free(p); printf("freed block\n"); return 0; }Heap execution and inspection commands Use valgrind or malloc debug to see metadata or errors
gcc -g any_heap.c -o any_heap valgrind --leak-check=full ./ any_heap# or run in an environment with malloc debug enabled Things to know when writing code Heap errors may not crash immediately and often appear during free or subsequent operations Use tools like valgrind or malloc debug for tracing @reverseengine

We use cookies to improve your browsing experience.
By clicking “Accept all”, you agree to the cookie policy.