當前位置: 首頁>>代碼示例>>Python>>正文


Python paramiko.Agent方法代碼示例

本文整理匯總了Python中paramiko.Agent方法的典型用法代碼示例。如果您正苦於以下問題:Python paramiko.Agent方法的具體用法?Python paramiko.Agent怎麽用?Python paramiko.Agent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在paramiko的用法示例。


在下文中一共展示了paramiko.Agent方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: agent_auth

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Agent [as 別名]
def agent_auth(transport, username):
    """
    Attempt to authenticate to the given transport using any of the private
    keys available from an SSH agent.
    """
    
    agent = paramiko.Agent()
    agent_keys = agent.get_keys()
    if len(agent_keys) == 0:
        return
        
    for key in agent_keys:
        print('Trying ssh-agent key %s' % hexlify(key.get_fingerprint()))
        try:
            transport.auth_publickey(username, key)
            print('... success!')
            return
        except paramiko.SSHException:
            print('... nope.') 
開發者ID:svenlu,項目名稱:conn,代碼行數:21,代碼來源:connection.py

示例2: _ssh_agent_auth

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Agent [as 別名]
def _ssh_agent_auth(self, transport, username):
        """
        Attempt to authenticate to the given transport using any of the private
        keys available from an SSH agent
        """
   
        logger.debug('[SSH] Attempting to authenticate')
        agent = paramiko.Agent()
        agent_keys = agent.get_keys()
        if len(agent_keys) == 0:
            return
    
        for key in agent_keys:
            logger.debug('[SSH] Trying ssh-agent key %s' % key.get_fingerprint().hex())
            try:
                transport.auth_publickey(username, key)
                logger.debug('[SSH]... success!')
                return
            except paramiko.SSHException as e:
                logger.debug('[SSH]... failed!', e)

    # Extract specific keys and return a list of their values.
    # Useful to extract empire unique users, workstations or operating systems 
開發者ID:GoSecure,項目名稱:gophish-cli,代碼行數:25,代碼來源:report.py

示例3: get_agent_keys

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Agent [as 別名]
def get_agent_keys(logger=None):
        """ Load public keys from any available SSH agent

        Arguments:
            logger (Optional[logging.Logger])

        Return:
            list
        """
        paramiko_agent = paramiko.Agent()
        agent_keys = paramiko_agent.get_keys()
        if logger:
            logger.info('{0} keys loaded from agent'.format(len(agent_keys)))
        return list(agent_keys) 
開發者ID:pahaz,項目名稱:sshtunnel,代碼行數:16,代碼來源:sshtunnel.py

示例4: _cli_main

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Agent [as 別名]
def _cli_main(args=None):
    """ Pass input arguments to open_tunnel

        Mandatory: ssh_address, -R (remote bind address list)

        Optional:
        -U (username) we may gather it from SSH_CONFIG_FILE or current username
        -p (server_port), defaults to 22
        -P (password)
        -L (local_bind_address), default to 0.0.0.0:22
        -k (ssh_host_key)
        -K (private_key_file), may be gathered from SSH_CONFIG_FILE
        -S (private_key_password)
        -t (threaded), allow concurrent connections over tunnels
        -v (verbose), up to 3 (-vvv) to raise loglevel from ERROR to DEBUG
        -V (version)
        -x (proxy), ProxyCommand's IP:PORT, may be gathered from config file
        -c (ssh_config), ssh configuration file (defaults to SSH_CONFIG_FILE)
        -z (compress)
        -n (noagent), disable looking for keys from an Agent
        -d (host_pkey_directories), look for keys on these folders
    """
    arguments = _parse_arguments(args)
    # Remove all "None" input values
    _remove_none_values(arguments)
    verbosity = min(arguments.pop('verbose'), 4)
    levels = [logging.ERROR,
              logging.WARNING,
              logging.INFO,
              logging.DEBUG,
              TRACE_LEVEL]
    arguments.setdefault('debug_level', levels[verbosity])
    with open_tunnel(**arguments) as tunnel:
        if tunnel.is_alive:
            input_('''

            Press <Ctrl-C> or <Enter> to stop!

            ''') 
開發者ID:pahaz,項目名稱:sshtunnel,代碼行數:41,代碼來源:sshtunnel.py

示例5: __init__

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Agent [as 別名]
def __init__(self, server, username, password, remote_server, local_port=0, private_key=None, missing_host_key_policy=None):
		"""
		:param tuple server: The SSH server to connect to.
		:param str username: The username to authenticate with.
		:param str password: The password to authenticate with.
		:param tuple remote_server: The remote server to connect to through the specified SSH server.
		:param int local_port: The local port to forward, if not set a random one will be used.
		:param str private_key: An RSA key to prefer for authentication.
		:param missing_host_key_policy: The policy to use for missing host keys.
		"""
		super(SSHTCPForwarder, self).__init__()
		self.logger = logging.getLogger('KingPhisher.' + self.__class__.__name__)
		self.server = (server[0], int(server[1]))
		self.remote_server = (remote_server[0], int(remote_server[1]))
		client = paramiko.SSHClient()
		if missing_host_key_policy is None:
			missing_host_key_policy = paramiko.AutoAddPolicy()
		elif isinstance(missing_host_key_policy, paramiko.RejectPolicy):
			self.logger.info('reject policy in place, loading system host keys')
			client.load_system_host_keys()
		client.set_missing_host_key_policy(missing_host_key_policy)
		self.client = client
		self.username = username
		self.__connected = False

		# an issue seems to exist in paramiko when multiple keys are present through the ssh-agent
		agent_keys = paramiko.Agent().get_keys()

		if not self.__connected and private_key:
			private_key = self.__resolve_private_key(private_key, agent_keys)
			if private_key:
				self.logger.debug('attempting ssh authentication with user specified key')
				self.__try_connect(look_for_keys=False, pkey=private_key)
			else:
				self.logger.warning('failed to identify the user specified key for ssh authentication')

		if not self.__connected and agent_keys:
			self.logger.debug("attempting ssh authentication with {:,} agent provided key{}".format(len(agent_keys), '' if len(agent_keys) == 1 else 's'))
			for key in agent_keys:
				if self.__try_connect(look_for_keys=False, pkey=key):
					break

		if not self.__connected:
			self.logger.debug('attempting ssh authentication with user specified credentials')
			self.__try_connect(password=password, look_for_keys=True, raise_error=True)

		transport = self.client.get_transport()
		self._forward_server = ForwardServer(self.remote_server, transport, ('127.0.0.1', local_port), ForwardHandler) 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:50,代碼來源:ssh_forward.py

示例6: _agentAuth

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Agent [as 別名]
def _agentAuth(transport, username, rsa_private_key):
    """ Attempt to authenticate to the given transport using any of the private keys available from an SSH 
        agent or from a local private RSA key file (assumes no pass phrase).

    Arguments:
        transport: [paramiko.Transport object] Connection handle.
        username: [str] Username which will be used to connect to the host.
        rsa_private_key: [str] Path to the RSA private key on the system.

    Return:
        [bool] True if successfull, False otherwise.
    """

    # Try loading the private key
    ki = None
    try:
        ki = paramiko.RSAKey.from_private_key_file(rsa_private_key)

    except Exception as e:
        log.error('Failed loading ' + rsa_private_key + str(e))

    # Find all available keys
    agent = paramiko.Agent()
    agent_keys = agent.get_keys() + (ki,)

    if len(agent_keys) == 0:
        return False

    # Try a key until finding the one which works
    for key in agent_keys:

        if key is not None:
            log.info('Trying ssh-agent key ' + str(binascii.hexlify(key.get_fingerprint())))

            # Try the key to authenticate
            try:
                transport.auth_publickey(username, key)
                log.info('... success!')
                return True

            except paramiko.SSHException as e:
                log.warning('... failed! - %s', e)

    return False 
開發者ID:CroatianMeteorNetwork,項目名稱:RMS,代碼行數:46,代碼來源:UploadManager.py


注:本文中的paramiko.Agent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。