Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cmd2.with_argparser(say_parser)
def do_say(self, args):
"""Repeat what you tell me to."""
words = []
for word in args.words:
if word is None:
word = ''
if args.piglatin:
word = '%s%say' % (word[1:], word[0])
if args.shout:
word = word.upper()
words.append(word)
repetitions = args.repeat or 1
for i in range(min(repetitions, self.maxrepeats)):
self.stdout.write(' '.join(words))
self.stdout.write('\n')
@cmd2.with_argparser(test_parser)
def do_test(self, args):
if args.type == "existing":
self._test_config_dict(self.existing_config_dict)
elif args.type == "updated":
self._test_config_dict(self.updated_config_dict)
elif args.type == "visa":
for visa_resource_name in visa.ResourceManager().list_resources():
try:
new_idn = visa_id_query(visa_resource_name)
except (VisaIOError, FxConfigError):
self._test_print_error(visa_resource_name, "Error opening or responding to IDN")
else:
self._test_print_ok(visa_resource_name, new_idn.strip())
@with_argparser(argparser)
def do_search(self, args):
if not self.packets or len(self.packets) == 0:
print 'Nothing to search! Use \'analyze\' first.'
return
if not args.key or not args.value:
self.help_search()
return
searchproto = args.key.split(".")[0].lower()
searchfield = args.key.split(".")[1].lower()
searchvalue = args.value
if searchproto in self.protodict and searchfield in self.protodict[searchproto]:
# cast searchvalue as per expected protofield datatype
try:
searchvalue = self.protodict[searchproto][searchfield](searchvalue)
except:
print "Incorrect searchvalue '%s' for protofield '%s.%s', expected %s" % (searchvalue, searchproto, searchfield, self.protodict[searchproto][searchfield])
@cmd2.with_argparser(oprint_parser)
def do_oprint(self, args):
"""Print the options and argument list this options command was called with."""
self.poutput('oprint was called with the following\n\toptions: {!r}'.format(args))
@cmd2.with_argparser(run_cmd_parser)
@cmd2.with_category(CMD_CAT_SSHAME)
def do_run_cmd(self, arg):
'''Run command on targets, where we have a valid credentials.
E.g. run_cmd -c "tar -cf - .ssh /etc/passwd /etc/ldap.conf /etc/shadow /home/*/.ssh /etc/fstab | gzip | uuencode /dev/stdout"'''
asyncio.get_event_loop().run_until_complete(
self.schedule_jobs(None, arg.command))
@cmd2.with_argparser(mumble_parser)
def do_mumble(self, args):
"""Mumbles what you tell me to."""
repetitions = args.repeat or 1
for i in range(min(repetitions, self.maxrepeats)):
output = []
if random.random() < .33:
output.append(random.choice(self.MUMBLE_FIRST))
for word in args.words:
if random.random() < .40:
output.append(random.choice(self.MUMBLES))
output.append(word)
if random.random() < .25:
output.append(random.choice(self.MUMBLE_LAST))
self.poutput(' '.join(output))
@with_argparser(argparser)
def do_pin(self, args):
filtered = self.story.filter_blocks(args.indices or None,
args.first_n or None,
args.last_n or None,
args.range)
n_blocks = len(self.story.blocks)
index_width = len(f"{n_blocks}")
for index, block in enumerate(self.story.blocks):
if block.attrs.get('pinned'):
continue
prefix = self.settings.icon_for_pins if block in filtered else " "
block_line = self.format_block_for_list(block, index, index_width)
self.poutput(f"{prefix}{block_line}")
@cmd2.with_argparser(set_parser)
def do_set(self, args):
"""Set the variables for the module"""
func = getattr(args, 'func', None)
if func is not None:
# Call whatever sub-command function was selected
func(self, args)
else:
# No sub-command was provided, so call help
self.do_help('help')
@cmd2.with_argparser(parser_path)
def do_path(self, stmt):
'''Manage paths'''
func = getattr(stmt, 'func', None)
if func is not None:
# Call whatever subcommand function was selected
func(self, stmt)
else:
self.path_list(None)
@cmd2.with_argparser(__parser_payload)
@cmd2.with_category(__CMD_CAT_WSP)
def do_payload(self, stmt):
'''List available payloads'''
func = getattr(stmt, 'func', None)
if func is not None:
# Call whatever subcommand function was selected
func(self, stmt)
else:
self.__payload_list(None)