Python paramiko.MissingHostKeyPolicy() Examples

The following are 5 code examples of paramiko.MissingHostKeyPolicy(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module paramiko , or try the search function .
Example #1
Source File: ssh-brute-force-threded.py    From Effective-Python-Penetration-Testing with MIT License 7 votes vote down vote up
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 
Example #2
Source File: ssh_host_key.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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__() 
Example #3
Source File: __init__.py    From lokey with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #4
Source File: hammr_utils.py    From hammr with Apache License 2.0 5 votes vote down vote up
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)) 
Example #5
Source File: tasks.py    From DevOps with GNU General Public License v2.0 4 votes vote down vote up
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()