Skip to content

Instantly share code, notes, and snippets.

@gabemarshall
Created July 12, 2015 16:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabemarshall/788e692d581ddb5bf0aa to your computer and use it in GitHub Desktop.
Save gabemarshall/788e692d581ddb5bf0aa to your computer and use it in GitHub Desktop.
Powerhell
#!/usr/bin/env python
#
# Powerhell
#
# by Gabe Marshall
# base64 encodes command line argument to Windows PowerShell
#
# Heavily influenced by Carol Perez's ps_encoder script (https://github.com/darkoperator/powershell_scripts/blob/master/ps_encoder.py)
import base64
import sys
import re
import os
def ps_encode(input):
command = ""
for character in (input):
# insert nullbyte for each character
command += character + "\x00"
command = base64.b64encode(command)
return command
try:
code = sys.argv[1]
except:
sys.exit("Ex: powerhell.py '(Powershell Cmdlet or script)")
print("powershell -nop -noni -win hidden -enc %s" % ps_encode(code))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment