PEN-200 Antivirus Evasion Practice Question
Refer to the exhibit.
[!] Error compiling payload: Function 'VirtualAlloc' not found in target assembly scope.
An operator is writing a custom process injection loader in C# and encounters the compilation error shown above while attempting to allocate memory for shellcode. How should the operator properly resolve this issue to enable low-level memory allocation?
⚠ Common exam trap
Candidates often assume managed C# code can natively call native Win32 APIs like VirtualAlloc directly without realizing that low-level memory allocation requires explicit unmanaged interoperability declarations via P/Invoke.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Import the unmanaged function from kernel32.dll using Platform Invoke (P/Invoke) declarations.
Managed languages like C# do not natively expose low-level Windows API functions like VirtualAlloc without explicit interoperability declarations. Utilizing Platform Invoke allows developers to import unmanaged DLL functions from kernel32.dll, bridging the gap between managed code execution and low-level memory manipulation required for advanced payload execution.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Replace VirtualAlloc with the standard .NET File.ReadAllBytes method to read the shellcode into a byte array.
Why it's wrong here
File.ReadAllBytes only reads shellcode into managed memory; it performs no allocation of executable memory, so injection cannot proceed. It is tempting because file reading is the correct choice when the requirement is loading shellcode bytes from disk rather than allocating and writing them into a remote process.
- ✗
Enable unsafe code blocks in the project settings and use raw C-style pointer arithmetic directly.
Why it's wrong here
Unsafe blocks permit pointer arithmetic but do not declare the P/Invoke signature, so VirtualAlloc remains unresolved at compile time. It is tempting because unsafe code is the correct choice when the requirement is direct unmanaged memory manipulation via pointers rather than calling a Win32 API through DllImport.
- ✓
Import the unmanaged function from kernel32.dll using Platform Invoke (P/Invoke) declarations.
Why this is correct
Importing VirtualAlloc from kernel32.dll via P/Invoke declarations supplies the missing unmanaged Win32 API that the .NET runtime cannot expose natively, resolving the compile error. This satisfies the stem's requirement for low-level memory allocation, since managed C# has no built-in equivalent for reserving executable pages.
- ✗
Compile the C# application as a 64-bit exclusive binary to match the target operating system architecture.
Why it's wrong here
Targeting 64-bit changes the output platform, not assembly scope resolution, so the compiler still cannot find VirtualAlloc. It is tempting because architecture matching is the correct choice when the requirement is ensuring the loader's bitness aligns with the target process before injection.
Visual reference
About these practice questions
One of 285 original PEN-200 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official OffSec exam blueprint
This PEN-200 practice question is part of Courseiva's free OffSec certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PEN-200 exam.