misc. bug fixes and standardization updates

1.6
Harmj0y 2016-07-20 23:39:25 -04:00
parent 0163ebec06
commit 7790b250a2
6 changed files with 52 additions and 45 deletions

View File

@ -3,6 +3,7 @@
-Fix for issue #273 - added hostnames to raw screenshot output file
-Fix for issue #285 - credential export supporting commas
-Start of code standardization/pep8 cleanup - mods to agents.py, empire.py, and credentials.py
-Misc. bug fixes
7/16/2016
---------

View File

@ -161,7 +161,7 @@ class MainMenu(cmd.Cmd):
menu.do_generate('')
else:
messages.display_stager(stagerName, targetStager)
messages.display_stager(targetStager)
except Exception as e:
print e
@ -646,7 +646,7 @@ class MainMenu(cmd.Cmd):
print helpers.color("[!] Please enter the minute window for agent checkin.")
else:
messages.display_agents(agents)
messages.display_agents(all_agents)
elif parts[0].lower() == "listeners":
@ -2871,12 +2871,12 @@ class StagerMenu(cmd.Cmd):
def do_info(self, line):
"Display stager options."
messages.display_stager(self.stagerName, self.stager)
messages.display_stager(self.stager)
def do_options(self, line):
"Display stager options."
messages.display_stager(self.stagerName, self.stager)
messages.display_stager(self.stager)
def do_set(self, line):

View File

@ -6,7 +6,8 @@ Titles, agent displays, listener displays, etc.
"""
import os, sys, textwrap
import os
import textwrap
# Empire imports
import helpers
@ -29,18 +30,18 @@ def title(version):
print ' [Web]: https://www.PowerShellEmpire.com/ | [Twitter]: @harmj0y, @sixdub, @enigma0x3'
print '===================================================================================='
print """
_______ .___ ___. .______ __ .______ _______
_______ .___ ___. .______ __ .______ _______
| ____|| \/ | | _ \ | | | _ \ | ____|
| |__ | \ / | | |_) | | | | |_) | | |__
| __| | |\/| | | ___/ | | | / | __|
| |____ | | | | | | | | | |\ \----.| |____
| |__ | \ / | | |_) | | | | |_) | | |__
| __| | |\/| | | ___/ | | | / | __|
| |____ | | | | | | | | | |\ \----.| |____
|_______||__| |__| | _| |__| | _| `._____||_______|
"""
def wrap_string(data, width=40, indent=32, indentAll=False, followingHeader=None):
"""
Print a option description message in a nicely
Print a option description message in a nicely
wrapped and formatted paragraph.
followingHeader -> text that also goes on the first line
@ -50,18 +51,18 @@ def wrap_string(data, width=40, indent=32, indentAll=False, followingHeader=None
if len(data) > width:
lines = textwrap.wrap(textwrap.dedent(data).strip(), width=width)
if indentAll:
returnString = ' '*indent+lines[0]
if followingHeader:
returnString = ' ' * indent + lines[0]
if followingHeader:
returnString += " " + followingHeader
else:
returnString = lines[0]
if followingHeader:
if followingHeader:
returnString += " " + followingHeader
i = 1
while i < len(lines):
returnString += "\n"+' '*indent+(lines[i]).strip()
returnString += "\n" + ' ' * indent + (lines[i]).strip()
i += 1
return returnString
else:
@ -74,7 +75,7 @@ def wrap_columns(col1, col2, width1=24, width2=40, indent=31):
Used by display_module()
"""
lines1 = textwrap.wrap(textwrap.dedent(col1).strip(), width=width1)
lines2 = textwrap.wrap(textwrap.dedent(col2).strip(), width=width2)
@ -86,16 +87,16 @@ def wrap_columns(col1, col2, width1=24, width2=40, indent=31):
if x < len(lines1):
if x != 0:
result += ' '*indent
result += ' ' * indent
result += '{line: <0{width}s}'.format(width=width1, line=lines1[x])
else:
if x == 0:
result += ' '*width1
result += ' ' * width1
else:
result += ' '*(indent + width1)
result += ' ' * (indent + width1)
if x < len(lines2):
result += ' ' + '{line: <0{width}s}'.format(width=width2, line=lines2[x])
result += ' ' + '{line: <0{width}s}'.format(width=width2, line=lines2[x])
if x != limit-1:
result += "\n"
@ -114,11 +115,11 @@ def display_options(options, color=True):
print "\t%s\t%s" % ('{0: <16}'.format(key), wrap_string(options[key]))
def agent_print (agents):
def agent_print(agents):
"""
Take an agent dictionary and display everything nicely.
"""
print ""
print ""
print helpers.color("[*] Active agents:\n")
print " Name Internal IP Machine Name Username Process Delay Last Seen"
print " --------- ----------- ------------ --------- ------- ----- --------------------"
@ -126,16 +127,19 @@ def agent_print (agents):
for agent in agents:
[ID, sessionID, listener, name, delay, jitter, external_ip, internal_ip, username, high_integrity, process_name, process_id, hostname, os_details, session_key, checkin_time, lastseen_time, parent, children, servers, uris, old_uris, user_agent, headers, functions, kill_date, working_hours, ps_version, lost_limit, taskings, results] = agent
if str(high_integrity) == "1":
# add a * to the username if it's high integrity
# add a * to the username if it's high integrity
username = "*" + username
print " %.19s%.16s%.16s%.20s%.20s%.9s%.20s" % ('{0: <19}'.format(name),'{0: <16}'.format(internal_ip),'{0: <16}'.format(hostname),'{0: <20}'.format(username), '{0: <20}'.format(str(process_name)+"/"+str(process_id)), '{0: <9}'.format(str(delay)+"/"+str(jitter)), lastseen_time)
print " %.19s%.16s%.16s%.20s%.20s%.9s%.20s" % ('{0: <19}'.format(name), '{0: <16}'.format(internal_ip), '{0: <16}'.format(hostname), '{0: <20}'.format(username), '{0: <20}'.format(str(process_name) + "/" + str(process_id)), '{0: <9}'.format(str(delay) + "/" +str(jitter)), lastseen_time)
print ""
def display_agents(agents):
"""
Take an agent dictionary and display everything nicely.
"""
if len(agents)>0:
if len(agents) > 0:
agent_print(agents)
else:
print helpers.color("[!] No agents currently registered ")
@ -146,7 +150,7 @@ def display_staleagents(agents):
Take an agent dictionary and display everything nicely.
"""
if len(agents)>0:
if len(agents) > 0:
agent_print(agents)
else:
print helpers.color("[!] No stale agents currently registered ")
@ -179,15 +183,15 @@ def display_listeners(listeners):
"""
if len(listeners) > 0:
print ""
print ""
print helpers.color("[*] Active listeners:\n")
print " ID Name Host Type Delay/Jitter KillDate Redirect Target"
print " -- ---- ---- ------- ------------ -------- ---------------"
for listener in listeners:
[ID,name,host,port,cert_path,staging_key,default_delay,default_jitter,default_profile,kill_date,working_hours,listener_type,redirect_target,default_lost_limit] = listener
[ID, name, host, port, cert_path, staging_key, default_delay, default_jitter, default_profile, kill_date, working_hours, listener_type, redirect_target, default_lost_limit] = listener
if not host.startswith("http"):
if cert_path and cert_path != "":
@ -213,7 +217,7 @@ def display_listener(options):
print " Name Required Value Description"
print " ---- -------- ------- -----------"
for option,values in options.iteritems():
for option, values in options.iteritems():
# if there's a long value length, wrap it
if len(str(values['Value'])) > 33:
print " %s%s%s" % ('{0: <18}'.format(option), '{0: <12}'.format(("True" if values['Required'] else "False")), '{0: <33}'.format(wrap_string(values['Value'], width=32, indent=32, followingHeader=values['Description'])))
@ -230,7 +234,7 @@ def display_listener_database(listener):
Transforms the tuple set to an options dictionary and calls display_listener().
"""
[ID,name,host,port,certPath,stagingKey,defaultDelay,defaultJitter,defaultProfile,killDate,workingHours,listenerType,redirectTarget, defaultLostLimit] = listener
[ID, name, host, port, certPath, stagingKey, defaultDelay, defaultJitter, defaultProfile, killDate, workingHours, listenerType, redirectTarget, defaultLostLimit] = listener
options = {
'ID' : {
@ -323,11 +327,11 @@ def display_listener_database(listener):
display_listener(options)
def display_stager(stagerName, stager):
def display_stager(stager):
"""
Displays a stager's information structure.
"""
print "\nName: " + stager.info['Name']
print "\nDescription:"
@ -343,9 +347,9 @@ def display_stager(stagerName, stager):
print " Name Required Value Description"
print " ---- -------- ------- -----------"
for option,values in stager.options.iteritems():
for option, values in stager.options.iteritems():
print " %s%s%s%s" % ('{0: <17}'.format(option), '{0: <12}'.format(("True" if values['Required'] else "False")), '{0: <18}'.format(values['Value']), wrap_string(values['Description'], indent=49))
print "\n"
@ -353,7 +357,7 @@ def display_module(moduleName, module):
"""
Displays a module's information structure.
"""
print '\n{0: >17}'.format("Name: ") + str(module.info['Name'])
print '{0: >17}'.format("Module: ") + str(moduleName)
print '{0: >17}'.format("NeedsAdmin: ") + ("True" if module.info['NeedsAdmin'] else "False")
@ -383,11 +387,11 @@ def display_module(moduleName, module):
print " %sRequired Value Description" %('{:<{}s}'.format("Name", maxNameLen+1))
print " %s-------- ------- -----------" %('{:<{}s}'.format("----", maxNameLen+1))
for option,values in module.options.iteritems():
for option, values in module.options.iteritems():
print " %s%s%s" % ('{:<{}s}'.format(str(option), maxNameLen+1), '{0: <12}'.format(("True" if values['Required'] else "False")), wrap_columns(str(values['Value']), str(values['Description']), indent=(31 + (maxNameLen-16))))
print ""
def display_module_search(moduleName, module):
"""
@ -396,7 +400,7 @@ def display_module_search(moduleName, module):
print " " + helpers.color(moduleName, "blue") + "\n"
# width=40, indent=32, indentAll=False,
lines = textwrap.wrap(textwrap.dedent(module.info['Description']).strip(), width=70)
for line in lines:
print "\t" + line
@ -405,6 +409,9 @@ def display_module_search(moduleName, module):
def display_credentials(creds):
"""
Take a credential array and display everything nicely.
"""
print helpers.color("\nCredentials:\n", "blue")
print " CredID CredType Domain UserName Host Password"
@ -419,7 +426,6 @@ def display_credentials(creds):
password = cred[4]
host = cred[5]
print " %s%s%s%s%s%s" % ('{0: <8}'.format(credID), '{0: <11}'.format(credType), '{0: <25}'.format(domain), '{0: <17}'.format(username), '{0: <17}'.format(host),password)
print " %s%s%s%s%s%s" % ('{0: <8}'.format(credID), '{0: <11}'.format(credType), '{0: <25}'.format(domain), '{0: <17}'.format(username), '{0: <17}'.format(host), password)
print ""

View File

@ -14,13 +14,13 @@ class Module:
'Background' : True,
'OutputExtension' : None,
'NeedsAdmin' : False,
'OpsecSafe' : True,
'MinPSVersion' : '2',
'Comments': [
'http://brianreiter.org/2010/09/03/copy-and-paste-with-clipboard-from-powershell/'
]
@ -50,7 +50,7 @@ class Module:
# 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
@ -76,7 +76,7 @@ class Module:
script += "Get-ClipboardContents"
for option,values in self.options.iteritems():
for option, values in self.options.iteritems():
if option.lower() != "agent":
if values['Value'] and values['Value'] != '':
if values['Value'].lower() == "true":