当前位置: 首页>>代码示例>>Python>>正文


Python paramiko.MissingHostKeyPolicy方法代码示例

本文整理汇总了Python中paramiko.MissingHostKeyPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python paramiko.MissingHostKeyPolicy方法的具体用法?Python paramiko.MissingHostKeyPolicy怎么用?Python paramiko.MissingHostKeyPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在paramiko的用法示例。


在下文中一共展示了paramiko.MissingHostKeyPolicy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: attempt

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import MissingHostKeyPolicy [as 别名]
def attempt(Password):

    IP = "127.0.0.1"
    USER = "rejah"
    PORT=22
      
    try:

        ssh = paramiko.SSHClient()
        ssh.load_system_host_keys()
        ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
 
        try:
            ssh.connect(IP , port=PORT, username=USER, password=Password)
            print "Connected successfully. Password = "+Password
        except paramiko.AuthenticationException, error:
            print "Incorrect password: "+Password
            pass
        except socket.error, error:
            print error
            pass 
开发者ID:PacktPublishing,项目名称:Effective-Python-Penetration-Testing,代码行数:23,代码来源:ssh-brute-force-threded.py

示例2: __init__

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import MissingHostKeyPolicy [as 别名]
def __init__(self, application):
		"""
		:param application: The application which is using this policy.
		:type application: :py:class:`.KingPhisherClientApplication`
		"""
		self.application = application
		self.logger = logging.getLogger('KingPhisher.Client.' + self.__class__.__name__)
		super(MissingHostKeyPolicy, self).__init__() 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:10,代码来源:ssh_host_key.py

示例3: ssh

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import MissingHostKeyPolicy [as 别名]
def ssh(ctx, domain_name):
    """Get the public key for a SSH server.

    Example:

        $ lokey fetch ssh chat.shazow.net
    """

    class FetchKeyPolicy(paramiko.MissingHostKeyPolicy):
        def __init__(self):
            self.key = None

        def missing_host_key(self, client, hostname, key):
            self.key = key

    fetch_key_policy = FetchKeyPolicy()
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(fetch_key_policy)
    try:
        client.connect(domain_name, username='lokey', timeout=5)
        key = fetch_key_policy.key.public_numbers
        key = ErisPublic(e=key.e, n=key.n)
        print key.to('ssh')
    except Exception as e:
        msg = ('Got "{message}" when attempting '
               'to connect to {domain_name}').format(
            domain_name=domain_name,
            message=str(e))
        raise click.ClickException(msg) 
开发者ID:jpf,项目名称:lokey,代码行数:31,代码来源:__init__.py

示例4: upload_binary_to_client

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import MissingHostKeyPolicy [as 别名]
def upload_binary_to_client(hostname, port, username, password, file_src_path, binary_path, id_file):
    try:
        t = paramiko.Transport((hostname, port))
        pkey = None
        if id_file:
            pkey = paramiko.RSAKey.from_private_key_file(id_file)
            t.connect(username=username, pkey=pkey)
        else:
            t.connect(username=username, password=password)
        sftp = paramiko.SFTPClient.from_transport(t)

        # upload binary
        sftp.put(file_src_path, binary_path)
        t.close()

        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
        client.connect(hostname, port, username, password, pkey)

    except paramiko.AuthenticationException as e:
        raise Exception("Authentification error: " + e[0])
    except Exception, e:
        try:
            t.close()
            client.close()
        except:
            pass
        raise Exception("Caught exception when uploading binary [" + binary_path + "]: " + str(e)) 
开发者ID:usharesoft,项目名称:hammr,代码行数:31,代码来源:hammr_utils.py

示例5: jumper_status_flush

# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import MissingHostKeyPolicy [as 别名]
def jumper_status_flush(obj):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(settings.SSH_TIMEOUT)
    try:
        s.connect((str(obj.connect_ip), int(obj.sshport)))
    except socket.timeout as e:
        obj._status = settings.STATUS_JUMPER_UNREACHABLE
        obj.save()
        return
    except ConnectionRefusedError as e:
        obj._status = settings.STATUS_JUMPER_UNREACHABLE
        obj.save()
        return
    except Exception as e:
        obj._status = settings.STATUS_JUMPER_UNREACHABLE
        obj.save()
        return
    try:
        if obj.group is None or obj.group.key is None:
            obj._status = settings.STATUS_JUMPER_NO_KEY
            obj.save()
            return
    except Exception as e:
        obj._status = settings.STATUS_JUMPER_NO_KEY
        obj.save()
        return

    # 创建临时目录
    TMP = settings.OPS_ROOT + '/' + str(time.time()) + '/'
    if not os.path.exists(TMP):
        os.makedirs(TMP)

    KEY = TMP + str(time.time()) + '.key'
    write_key(obj.group.key, KEY)

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy)
    try:
        ssh.connect(hostname=obj.connect_ip, port=obj.sshport, username='root', key_filename=KEY)
    except paramiko.AuthenticationException as e:
        obj._status = settings.STATUS_JUMPER_WRONG_KEY
        obj.save()
        return

    obj._status = settings.STATUS_JUMPER_CAN_BE_USE
    obj.save() 
开发者ID:YoLoveLife,项目名称:DevOps,代码行数:48,代码来源:tasks.py


注:本文中的paramiko.MissingHostKeyPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。