linux tc policy 例子,Python paramiko.RejectPolicy方法代码示例

# 需要导入模块: import paramiko [as 别名]

# 或者: from paramiko import RejectPolicy [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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值