HackCert
Advanced 11 min read May 25, 2026

Thread Hijacking: অপারেটিং সিস্টেমের চলমান প্রসেসের থ্রেড পজ করে ম্যালওয়্যারের কোড চালানোর কৌশল!

Thread Execution Hijacking, SetThreadContext API misuse, process injection technique এবং EDR bypass-এর advanced offensive analysis।

Ahmed Rafiq Khan
Malware Researcher
share
Thread Hijacking: অপারেটিং সিস্টেমের চলমান প্রসেসের থ্রেড পজ করে ম্যালওয়্যারের কোড চালানোর কৌশল!
Overview

Modern malware-এর সবচেয়ে কার্যকর evasion technique-গুলোর একটি হলো legitimate process-এর ভেতরে নিজের code execute করা। যদি একটি malicious payload notepad.exe বা explorer.exe-এর memory space-এ চলে এবং সেই process-এর thread-এ execute হয়, তাহলে antivirus, EDR বা SOC analyst সহজে detect করতে পারে না। এই category-র technique-কে process injection বলা হয়, এবং এর মধ্যে Thread Execution Hijacking একটি বিশেষ ও সূক্ষ্ম পদ্ধতি। সাধারণ DLL injection বা CreateRemoteThread-এর তুলনায় Thread Hijacking-এ কোনো new thread create হয় না — বরং target process-এর একটি existing thread-কে suspend করে তার instruction pointer পরিবর্তন করা হয়, যাতে resume করলে সেটি attacker-এর code-এ লাফ দেয়। এই subtlety-র জন্য Thread Hijacking advanced persistent threat (APT) এবং red team operator-দের toolbox-এর গুরুত্বপূর্ণ অংশ।

Process এবং Thread-এর Architectural Background

Windows-এ প্রতিটি process-এর নিজস্ব virtual address space, handle table এবং security context থাকে। প্রতিটি process-এ এক বা একাধিক thread থাকে — execution-এর smallest unit। প্রতিটি thread-এর own stack, register set এবং execution context থাকে। CPU যখন একটি thread schedule করে, তখন সেই thread-এর saved context (register values, instruction pointer, stack pointer) restore করে instruction execute শুরু করে।

Windows API-এ GetThreadContext এবং SetThreadContext function পুরোনো এবং documented capability প্রদান করে — যেখানে suspended thread-এর CPU context কোনো process থেকে পড়া বা লেখা যায়। Debugger এই capability ব্যবহার করে breakpoint manage করে, single-step execute করে এবং register inspect করে। কিন্তু এই same capability malicious actor-দের জন্যও available — যদি তারা target process-এর THREAD_GET_CONTEXT, THREAD_SET_CONTEXT এবং THREAD_SUSPEND_RESUME access নিতে পারে।

Classic Thread Hijacking Workflow

একটি traditional Thread Hijacking flow কয়েকটি step অনুসরণ করে। প্রথমে attacker CreateToolhelp32Snapshot বা NtQuerySystemInformation ব্যবহার করে target process এবং তার thread enumerate করেন। সাধারণত long-running, stable thread (যেমন একটি GUI thread যা message loop-এ থাকে) target হিসেবে বেছে নেওয়া হয়।

দ্বিতীয় step-এ OpenProcess দিয়ে process handle, এবং OpenThread দিয়ে thread handle acquire করা হয়। তৃতীয় step-এ VirtualAllocEx দিয়ে target process-এ remote memory allocate করা হয়, যেখানে shellcode বা DLL path write করা হবে। চতুর্থ step-এ WriteProcessMemory দিয়ে payload সেই allocated memory-তে copy করা হয়।

পঞ্চম step হলো hijacking-এর হৃদয়। Thread-কে SuspendThread দিয়ে pause করে GetThreadContext দিয়ে তার current register state retrieve করা হয়। তারপর context-এর instruction pointer (x64-এ RIP, x86-এ EIP) modify করে allocated shellcode-এর address-এ point করানো হয়। SetThreadContext দিয়ে modified context লেখা হয় এবং ResumeThread দিয়ে thread পুনরায় চালু করা হয়। এখন target thread original code-এর জায়গায় attacker-এর shellcode execute করতে শুরু করে।

Shellcode সম্পন্ন হওয়ার পর সাধারণত original RIP-এ jump করে দেওয়া হয়, যাতে process স্বাভাবিকভাবে চলতে থাকে এবং কোনো crash বা hang না হয়।

কোড স্তরে একটি Conceptual Example

C/C++-এ Thread Hijacking-এর core logic প্রায় এরকম দেখায়। OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid) দিয়ে process handle, এরপর VirtualAllocEx(hProc, NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE) দিয়ে remote allocation। WriteProcessMemory(hProc, addr, shellcode, size, NULL) দিয়ে shellcode write। OpenThread(THREAD_ALL_ACCESS, FALSE, tid) দিয়ে thread handle।

এরপর SuspendThread(hThread), CONTEXT ctx = { CONTEXT_FULL };, GetThreadContext(hThread, &ctx), ctx.Rip = (DWORD64)addr;, SetThreadContext(hThread, &ctx), ResumeThread(hThread)। প্রতিটি API call malicious indicator হতে পারে — বিশেষ করে যখন একই sequence-এ execute হয়।

কেন এই Technique কার্যকর

Thread Hijacking-এর সবচেয়ে বড় সুবিধা হলো এটি new thread create করে না। CreateRemoteThread API-কে আজকাল প্রায় সব EDR product monitor করে, কারণ এটি classic injection-এর hallmark। ETW (Event Tracing for Windows) এবং kernel callback-এর মাধ্যমে remote thread creation logged হয়। Thread Hijacking এই telemetry এড়িয়ে যায়, কারণ existing thread কেবল context change-এর মাধ্যমে redirect হয়।

দ্বিতীয় সুবিধা হলো process indistinguishability। যেহেতু code legitimate process-এর memory-তে চলছে, তার network connection, file access এবং registry operation সব সেই process-এর identity ধারণ করে। Defender যদি দেখে chrome.exe outbound connection করছে, সেটি স্বাভাবিক বলে মনে হবে।

তৃতীয় সুবিধা হলো signature evasion। Static analysis tool encrypted shellcode কে initially detect করতে পারে না, এবং in-memory execution disk-resident artifact ছাড়াই কাজ করে।

Advanced Variant

Base technique-এর উপরে অনেক variation develop হয়েছে। "Stack String" variant-এ shellcode-কে directly write না করে existing executable region-এ ROP gadget chain দিয়ে execute করা হয়। এই approach-এ VirtualAllocEx প্রয়োজন হয় না, তাই memory allocation telemetry এড়ানো যায়।

"Thread Stack Spoofing" — যেখানে attacker thread-এর stack পরিবর্তন করে এমন call chain তৈরি করে যা legitimate API call-এর মতো দেখায়। Sliver, Cobalt Strike-এর latest version এবং custom C2 framework-এ এই technique implemented।

"Thread Name Calling" technique (TrickBot এ ব্যবহৃত) — যেখানে QueueUserAPC বা NtQueueApcThreadEx ব্যবহার করে suspended thread-এ asynchronous procedure call queue করা হয়। যখন thread alertable state-এ যায়, APC execute হয়।

"Module Stomping" — যেখানে remote process-এ একটি legitimate DLL load করে তার .text section-এ overwrite করে নিজের shellcode বসানো হয়। Memory permission ইতিমধ্যেই executable, তাই VirtualProtect-এর প্রয়োজন নেই — যা suspicious indicator।

Cross-Architecture Considerations

x86 এবং x64-এ Thread Hijacking-এর implementation কিছুটা ভিন্ন। x86-এ EIP modify করা হয়, x64-এ RIP। Register naming এবং calling convention-ও ভিন্ন।

WoW64 (32-bit process running on 64-bit Windows)-এ আরো জটিলতা যোগ হয়, কারণ x86 thread context-এর জন্য Wow64GetThreadContext এবং Wow64SetThreadContext API ব্যবহার করতে হয়। এই API-এ buggy implementation কিছু EDR-এ exploit হয়েছে।

ARM64 Windows machine-এর rise-এর সাথে আক্রমণকারীদের এখন তিন ভিন্ন architecture-এর জন্য shellcode maintain করতে হচ্ছে। Apple Silicon Mac-এ macOS-ও similar technique-এর সম্ভাবনা প্রদর্শন করে, যদিও Mach exception port এবং task port-এর মাধ্যমে।

Real-World Malware Family

Thread Hijacking technique-এর historical and modern adoption অসংখ্য। Conficker worm-এর কিছু variant ২০০৮ সালে এই technique ব্যবহার করেছিল। Stuxnet-এ multiple injection method ছিল, এবং Thread Hijacking তাদের একটি।

Modern banking trojan যেমন Emotet, IcedID, TrickBot, এবং Qakbot ব্যাপকভাবে process injection ব্যবহার করেছে — যার মধ্যে Thread Hijacking একটি common variant। PlugX, Dridex, এবং multiple Cobalt Strike beacon implementation-এ এই technique।

Lazarus Group (DPRK-attributed APT)-এর custom RAT, যেমন AppleJeus এবং BadCall, Thread Hijacking-এর creative use দেখিয়েছে। ২০২২ সালে discovered "Trigona" ransomware এবং ২০২৩-এ "BlackCat/ALPHV" group-ও এই technique-এর variation ব্যবহার করেছে।

Detection এবং Telemetry

EDR vendor Thread Hijacking detect করার জন্য কয়েকটি technique ব্যবহার করে। প্রথমত, API call sequence monitoring — যদি একটি single process থেকে রাশি দ্রুত OpenProcess, VirtualAllocEx, WriteProcessMemory, SuspendThread, SetThreadContext, ResumeThread call sequence আসে এবং target ভিন্ন process হয়, সেটি high-confidence indicator।

দ্বিতীয়ত, ETW Thread context modification event এবং kernel callback (PsSetCreateThreadNotifyRoutine ইত্যাদি) দিয়ে suspicious activity capture করা হয়। ETW Threat Intelligence provider কিছু sensitive API call directly subscribe করে।

তৃতীয়ত, memory scanning — periodically process memory scan করে unexpected executable region (যেমন RWX page, hollowed sections, mismatched memory protection) খোঁজা হয়। PE-Sieve, Moneta এবং Hollows Hunter-এর মতো open-source tool এই scanning capability দেখায়।

চতুর্থত, behavioral baseline — কোন application কখন কোন process-এর সাথে interact করে তার baseline তৈরি করে anomaly detect করা। উদাহরণ, যদি winword.exe থেকে lsass.exe-তে cross-process memory write আসে, সেটি অত্যন্ত abnormal।

পঞ্চমত, stack tracing — call stack analyze করে যদি unbacked memory region থেকে call আসে (যেখানে module loaded নেই), সেটি injected code-এর strong indicator।

Userland Bypass এবং Kernel Defense

Attacker EDR userland hook bypass করতে অনেক technique ব্যবহার করেন — direct system call (Hell's Gate, Halo's Gate), unhooking, manual mapping। কিন্তু kernel-level callback bypass করা অনেক কঠিন। Microsoft Vulnerable Driver Blocklist এবং Hypervisor-protected Code Integrity (HVCI) এই attacks-কে কঠিন করেছে।

Microsoft-এর introduced Protected Process Light (PPL) সংরক্ষিত process-এ external memory write এবং thread modification block করে। ETW-Ti (ETW Threat Intelligence)-এ context modification কিছু সুরক্ষিত event source হিসেবে monitor হয়।

Linux-এ ptrace system call equivalent capability প্রদান করে — যেখানে attacker PTRACE_ATTACH, PTRACE_SETREGS এবং PTRACE_CONT দিয়ে similar hijacking করতে পারে। Yama Linux Security Module এবং ptrace_scope kernel parameter এই attack mitigate করতে সাহায্য করে।

Forensic Investigation Approach

একটি incident-এ Thread Hijacking suspect হলে responder কয়েকটি artifact পরীক্ষা করেন। Volatility বা Rekall দিয়ে memory dump analysis — malfind plugin RWX region এবং injected code detect করে। dlllist, ldrmodules এবং vadinfo discrepancy খোঁজে।

Yara rule-based scanning — যেখানে known shellcode pattern বা C2 framework signature memory-তে match করা হয়। Cobalt Strike beacon detection-এ Elastic এবং CrowdStrike-এর publicly available Yara rule wide আকারে ব্যবহৃত হয়।

Network forensics-এ unusual outbound connection — বিশেষ করে যদি browser বা Office application থেকে non-standard destination-এ traffic যায়।

Sysmon Event ID 8 (CreateRemoteThread), Event ID 10 (ProcessAccess) এবং Event ID 22 (DNS query)-এর সমন্বিত analysis।

প্রতিরোধ ও প্রতিকার

Organization-level defense multi-layered approach demand করে। প্রথম layer-এ application allowlisting (AppLocker, Windows Defender Application Control) যাতে untrusted binary execute না হয়। Application allowlisting সম্পূর্ণ prevention না হলেও initial loader-কে block করে।

দ্বিতীয় layer-এ Attack Surface Reduction (ASR) rule — Microsoft Defender-এর built-in rule-গুলো process injection, vulnerable signed driver abuse এবং Office macro execution রোধ করে।

তৃতীয় layer-এ Credential Guard এবং Protected Process Light enable করা — LSASS, antivirus engine এবং security-critical process injection থেকে protect হয়।

চতুর্থ layer-এ EDR/XDR deployment with behavior-based detection enabled, kernel callback driver loaded। CrowdStrike Falcon, SentinelOne, Microsoft Defender for Endpoint, Elastic Defend — এদের সব-ই Thread Hijacking detection-এ effective।

পঞ্চম layer-এ Sysmon সঠিকভাবে configure করা (যেমন SwiftOnSecurity-এর community config) এবং Splunk বা Elastic SIEM-এ centralize করা।

ষষ্ঠ layer-এ user education — phishing email এবং malicious document — যা সাধারণত initial access vector — থেকে user-দের সচেতন করা।

সর্বশেষে red team exercise এবং purple team collaboration — যেখানে নিয়মিত detection capability test করা হয়।

Key Takeaways

Thread Hijacking process injection-এর সবচেয়ে subtle এবং কার্যকর variant-এর একটি। নতুন thread create না করে existing thread-এর context manipulate করার কৌশল adversary-দের stealthy execution-এর সুযোগ দেয়, যা EDR এবং SOC analyst-দের জন্য চিরন্তন challenge। তবে কথা মনে রাখা দরকার, কোনো attack technique-ই perfectly invisible নয় — proper telemetry, kernel callback, behavioral baseline এবং memory scanning-এর সমন্বিত defense Thread Hijacking-কে detect এবং stop করতে পারে। Defender-দের জন্য এই technique-এর গভীর understanding আবশ্যক — কারণ adversary তাদের technique constantly evolve করছেন, এবং detection capability সেই সাথে advance না হলে gap বাড়তেই থাকবে।

আপনার জ্ঞান যাচাই করতে প্রস্তুত? আজই HackCert-এ Thread Hijacking MCQ Quiz-টি দিন!

Related articles

back to all articles