def __init__(self, conn, color=True): cmd.Cmd.__init__(self) if _onwin32: if pyreadline is not None: self.out = pyreadline.GetOutputFile() else: if color is True: sys.stderr.write("Colors not available, disabled.") self.out = sys.stdout color = False else: self.out = sys.stdout self.out_write = self.out.write self._stdin_bak = None if color: self.theme = DefaultTheme() else: self.theme = NoColorTheme() self.intro = '' self.use_rawinput = True self.cmd_aliases = dict(self._default_aliases) ctx = self.Context('', self, conn) # default context self.contexts = { ctx.id: ctx } self.ctx_change(ctx.id)
""" __author__ = "Jussi Toivola" __license__ = "MIT License" from SCons.Platform import win32, posix import os import subprocess as sp import sys #: Pyreadline console CONSOLE = None try: if os.name == "nt": import pyreadline CONSOLE = pyreadline.GetOutputFile() except ImportError: #IGNORE:W0704 pass #: Color constants. TODO: Get from user settings. class Colors( object ): WARNING = 14 ERROR = 12 NORMAL = 7 COMMENT = 10 if sys.platform == "linux2": Colors.WARNING = 33 Colors.ERROR = 31 Colors.NORMAL = 0 Colors.COMMENT = 32
def main(): global conf global credentials global domains global have_readline global pool_thread banner() conf = cmdline_parser() check_conf() pool_thread = threading.BoundedSemaphore(conf.threads) try: for target in targets: pool_thread.acquire() current = test_login(target) current.daemon = True current.start() while threading.activeCount() > 1: a = 'Caughtit' pass except KeyboardInterrupt: print try: logger.warn('Test interrupted') a = 'Caughtit' stop_threads[0] = True except KeyboardInterrupt: print logger.info('User aborted') exit(1) if successes == 0: print '\nNo credentials worked on any target\n' exit(0) print '\nThe credentials worked in total %d times\n' % successes print 'TARGET SORTED RESULTS:\n' for target in targets: valid_credentials = target.get_valid_credentials() if len(valid_credentials) > 0: print target.get_identity() for valid_credential in valid_credentials: print ' %s' % valid_credential.get_identity() print print '\nUSER SORTED RESULTS:\n' for credential in credentials: valid_credentials = credential.get_valid_targets() if len(valid_credentials) > 0: print credential.get_identity() for valid_credential in valid_credentials: print ' %s' % valid_credential.get_identity() print if conf.smbcmdlist is not None: smb_cmd_list() if conf.oscmdlist is not None: os_cmd_list() if conf.batch or conf.smbcmdlist or conf.oscmdlist: return while True: msg = 'Do you want to establish a SMB shell from any of the targets? [Y/n] ' choice = raw_input(msg) if choice and choice[0].lower() != 'y': return counter = 0 targets_dict = {} msg = 'Which target do you want to connect to?' for target in targets: valid_credentials = target.get_valid_credentials() if len(valid_credentials) > 0: counter += 1 msg += '\n[%d] %s%s' % (counter, target.get_identity(), ' (default)' if counter == 1 else '') targets_dict[counter] = (target, valid_credentials) msg += '\n> ' choice = read_input(msg, counter) user_target, valid_credentials = targets_dict[int(choice)] counter = 0 credentials_dict = {} msg = 'Which credentials do you want to use to connect?' for credential in valid_credentials: counter += 1 msg += '\n[%d] %s%s' % (counter, credential.get_identity(), ' (default)' if counter == 1 else '') credentials_dict[counter] = credential msg += '\n> ' choice = read_input(msg, counter) user_credentials = credentials_dict[int(choice)] if sys.platform.lower() == 'win32' and have_readline: try: _outputfile = readline.GetOutputFile() except AttributeError: logger.debug('Failed GetOutputFile when using platform\'s readline library') have_readline = False uses_libedit = False if sys.platform.lower() == 'darwin' and have_readline: import commands (status, result) = commands.getstatusoutput('otool -L %s | grep libedit' % readline.__file__) if status == 0 and len(result) > 0: readline.parse_and_bind('bind ^I rl_complete') debugMsg = 'Leopard libedit detected when using platform\'s ' debugMsg += 'readline library' logger.debug(debugMsg) uses_libedit = True try: shell = InteractiveShell(user_target, user_credentials, conf.name) shell.cmdloop() except RuntimeError, e: logger.error('Runtime error: %s' % str(e)) except Exception, _: # traceback.print_exc() pass
def __init__(self, original_flow): self.__original_flow = original_flow if sys.platform == 'win32': import pyreadline self.__console = pyreadline.GetOutputFile()