How to use the paramiko.AutoAddPolicy function in paramiko

To help you get started, we’ve selected a few paramiko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CloudScale-Project / CloudStore / deployment-scripts / cloudscale / deployment_scripts / scripts / infrastructure / openstack / openstack_create_mongodb_instances.py View on Github external
def upload_mongo_dump(self, ip_address):
        self.logger.log("Connecting to ssh on %s" % ip_address)
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        while True:
            try:
                ssh.connect(ip_address, username=self.remote_user, key_filename=os.path.abspath(self.key_pair))
                break
            except:
                time.sleep(5)

        scp = paramiko.SFTPClient.from_transport(ssh.get_transport())
        self.logger.log("Uploading mysql dump")
        cmd = "wget -T90 -q %s -O dump.sql" % self.dump_url
        ssh.exec_command(cmd)

        ssh.exec_command("sudo mv dump.sql /root/dump.sql")
github fp7-ofelia / ocf / vt_manager / src / python / vt_manager / utils / contextualization / vm_contextualize.py View on Github external
def create_client(self):
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # Re-initialize RNG after fork to avoid connectivity problems with Paramiko
        Random.atfork()
        client.connect(self.vm_address, username=self.vm_user, port=22, password=self.vm_user_password)
        return client
github Logos01 / admin-tools / bin / add_users.py View on Github external
def runRemoteShell():
    host = sys.argv[1]
    user = sys.argv[2]
    global chan
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(host,username=user,password=decrypted_pass)
    chan = ssh.invoke_shell()
    while not chan.recv_ready():
        print "Connecting..."
        time.sleep(2)
    print(chan.recv(1024))
    chan.send('sudo su -\n')
    time.sleep(1)
    chan.send('%s\n' % decrypted_pass)
    print chan.recv(1024)
    while not chan.recv_ready():
        time.sleep(2)
    chan.send('pwd\n')
    print chan.recv(1024)
    print chan.recv(1024)
    addGroups()
github ktbyers / netmiko / base_connection.py View on Github external
def establish_connection(self, sleep_time=3):
        '''
        Establish SSH connection to the network device
        '''

        # Create instance of SSHClient object
        self.remote_conn_pre = paramiko.SSHClient()

        # Automatically add untrusted hosts (make sure appropriate for your environment)
        self.remote_conn_pre.set_missing_host_key_policy(
             paramiko.AutoAddPolicy())

        # initiate SSH connection
        print "SSH connection established to {0}:{1}".format(self.ip, self.port)
        self.remote_conn_pre.connect(hostname=self.ip, port=self.port, 
                        username=self.username, password=self.password)

        # Use invoke_shell to establish an 'interactive session'
        self.remote_conn = self.remote_conn_pre.invoke_shell()
        print "Interactive SSH session established"

        # Strip the initial router prompt
        time.sleep(sleep_time)
        output = self.remote_conn.recv(MAX_BUFFER)
github ycg / mysql_web / monitor / server.py View on Github external
def create_remote_ssh_client(self, host_info):
        host_client = paramiko.SSHClient()
        host_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        host_client.connect(host_info.host, port=host_info.ssh_port, username=host_info.ssh_user, password=host_info.ssh_password)
        host_client.get_transport().set_keepalive(1)
        return host_client
github grnet / synnefo / snf-tools / synnefo_tools / burnin / cyclades_common.py View on Github external
def _ssh_execute(self, hostip, username, password, command):
        """Execute a command via ssh"""
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        try:
            ssh.connect(hostip, username=username, password=password)
        except (paramiko.SSHException, socket.error, EOFError) as err:
            self.warning("%s", err.message)
            raise Retry()
        _, stdout, _ = ssh.exec_command(command)
        status = stdout.channel.recv_exit_status()
        output = stdout.readlines()
        ssh.close()
        return output, status
github fabric / fabric / fabric / network.py View on Github external
#

    # Init client
    client = ssh.SSHClient()

    # Load system hosts file (e.g. /etc/ssh/ssh_known_hosts)
    known_hosts = env.get('system_known_hosts')
    if known_hosts:
        client.load_system_host_keys(known_hosts)

    # Load known host keys (e.g. ~/.ssh/known_hosts) unless user says not to.
    if not env.disable_known_hosts:
        client.load_system_host_keys()
    # Unless user specified not to, accept/add new, unknown host keys
    if not env.reject_unknown_hosts:
        client.set_missing_host_key_policy(ssh.AutoAddPolicy())

    #
    # Connection attempt loop
    #

    # Initialize loop variables
    connected = False
    password = get_password(user, host, port)
    tries = 0
    sock = None

    # Loop until successful connect (keep prompting for new password)
    while not connected:
        # Attempt connection
        try:
            tries += 1
github Luxoft / Twister / lib / TscSshLib.py View on Github external
self.session = None
        self.host = host
        self.port = port
        self.loginAccount = {
            'user': user,
            'pass': password
        }
        self.name = name
        self.timeout = 0.2

        self.nbytes = 4096
        self.prompt = ''

        try:
            self.connection = paramiko.SSHClient()
            self.connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            self.connection.connect(host,
                                    username=self.loginAccount['user'],
                                    password=self.loginAccount['pass'])
            self.session = self.connection.invoke_shell(term='xterm', width=256, height=24)
            self.session.settimeout(self.timeout)
            self.setPrompt()

            print('CC_LIB: ssh connection created!')
        except Exception as e:
            print('CC_LIB: ssh connection failed: {er}'.format(er=e))
github ThomasTJdev / WMD / modules / bruteforce / bruteforcessh.py View on Github external
def run():
    global connCounter
    # Check if logfile exists
    saveLogCheck()
    # Setting SSH
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    # Check if proxy is needed
    if sop.proxyActive == 'y':
        sock = getProxy()
    # Open user- and passlist and loop through them
    with open(sop.userlist, 'r') as fuser, open(sop.passlist, 'r') as fpass:
        for uline in fuser:
            for pline in fpass:
                if sop.proxyActive == 'y':
                    connCounter += 1
                    # !!!!!! Make userspecified conn count
                    if connCounter > 30:
                        sock = getProxy()
                        connCounter = 0
                    bf = bruteforce(ssh, uline.strip('\n'), pline.strip('\n'), sock)
                else:
                    bf = bruteforce(ssh, uline.strip('\n'), pline.strip('\n'), None)
github luiscovar / worm-ssh / extorter_worm.py View on Github external
def attackSystem(host):
	
	# The credential list
	global credList
	
	# Create an instance of the SSH client
	ssh = paramiko.SSHClient()

	# Set some parameters to make things easier.
	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
	
				
	# Go through the credential
	for (username, password) in credList:
		
		# TODO: here you will need to
		# call the tryCredentials function
		# to try to connect to the
		# remote system using the above 
		# credentials.  If tryCredentials
		# returns 0 then we know we have
		# successfully compromised the
		# victim. In this case we will
		# return a tuple containing an
		# instance of the SSH connection
		# to the remote system.