How to use the pexpect.pxssh function in pexpect

To help you get started, we’ve selected a few pexpect 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 pexpect / pexpect / tests / test_psh.py View on Github external
def test_psh(self):
        ssh = pxssh.pxssh()
        ssh.login('server', 'user', 's3cret')
        sh = psh.psh(ssh)
        res = set(sh.ls())
        self.assertEqual(res, set([b'file1.py', b'file2.html']))
github Keeper-Security / Commander / keepercommander / plugins / ssh / ssh.py View on Github external
def rotate(record, newpassword):
    """ Grab any required fields from the record """
    user = record.login
    oldpassword = record.password

    result = False

    host = record.get('cmdr:host')

    try:
        s = pxssh.pxssh()
        s.login(host, user, oldpassword)
        s.sendline('passwd')
        i = s.expect(['[Oo]ld.*[Pp]assword', 'current.*password', '[Nn]ew.*[Pp]assword'])
        if i == 0 or i == 1:
            s.sendline(oldpassword)
            s.expect('[Nn]ew.*[Pp]assword')
        s.sendline(newpassword)
        s.expect("Retype [Nn]ew.*[Pp]assword:")
        s.sendline(newpassword)
        s.prompt()

        pass_result = s.before

        if "success" in str(pass_result):
            logging.info("Password changed successfully")
            record.password = newpassword
github greenplum-db / gpdb / gpMgmt / bin / gppylib / util / ssh_utils.py View on Github external
try:
                # The sync_multiplier value is passed onto pexpect.pxssh which is used to determine timeout
                # values for prompt verification after an ssh connection is established.
                p.login(hostname, self.userName, sync_multiplier=sync_multiplier)
                p.x_peer = hostname
                p.x_pid = p.pid
                good_list.append(p)
                if self.verbose:
                    with print_lock:
                        print '[INFO] login %s' % hostname
            except Exception as e:
                with print_lock:
                    print '[ERROR] unable to login to %s' % hostname
                    if type(e) is pxssh.ExceptionPxssh:
                        print e
                    elif type(e) is pxssh.EOF:
                        print 'Could not acquire connection.'
                    else:
                        print 'hint: use gpssh-exkeys to setup public-key authentication between hosts'
github aviau / python-pass / pypass / command.py View on Github external
def connect(config, path):
    store = config['password_store']
    hostname = store.get_decrypted_password(path, entry=EntryType.hostname)
    username = store.get_decrypted_password(path, entry=EntryType.username)
    password = store.get_decrypted_password(path, entry=EntryType.password)
    s = pxssh.pxssh()
    click.echo("Connectig to %s" % hostname)
    s.login(hostname, username, password=password)
    s.sendline()
    s.interact()
github PowerScript / KatanaFramework / scripts / btf / bruteforcetosshprotocol.py View on Github external
elif getFunction.KatanaCheckActionSetValue(actions)   :initialize.DEFAULT_VARIABLE=getFunction.UpdateValue(actions,initialize.DEFAULT_VARIABLE)
		elif getFunction.KatanaCheckActionisBack(actions)     :return
		# END HEAD MODULE
		elif getFunction.runModule(actions):
			Message.run()
			# CODE MODULE    ############################################################################################
			try:
				getFunction.live(initialize.DEFAULT_VARIABLE[0][0],initialize.DEFAULT_VARIABLE[1][0])
				if True:
					try:
						Message.loading_file()
						with open(initialize.DEFAULT_VARIABLE[3][0],'r') as passwords:
							for ps in passwords:
								ps=ps.replace("\n","")
								try:
									connect = pxssh.pxssh()
									connect.login(initialize.DEFAULT_VARIABLE[0][0],initialize.DEFAULT_VARIABLE[2][0],ps)
									if True:
										getFunction.save("BruteForceSSH",initialize.DEFAULT_VARIABLE[0][0],initialize.DEFAULT_VARIABLE[1][0],initialize.DEFAULT_VARIABLE[2][0],ps)
										Message.Success(defaultuser,ps)
										break
								except:
									print " "+Alr+" Checking ("+initialize.DEFAULT_VARIABLE[2][0]+"="+ps+")"
					except:
						Errors.Errors(event=sys.exc_info(), info=initialize.DEFAULT_VARIABLE[3][0])
			except:
				Errors.Errors(event=sys.exc_info(), info=initialize.DEFAULT_VARIABLE[0][0]+":"+initialize.DEFAULT_VARIABLE[1][0])
			# END CODE MODULE ############################################################################################
		else:
			getFunction.KatanaCheckActionGlobalCommands(actions)
	# ERROR GENERAL
	except:
github home-assistant / home-assistant / homeassistant / components / cisco_ios / device_tracker.py View on Github external
def _get_arp_data(self):
        """Open connection to the router and get arp entries."""

        try:
            cisco_ssh = pxssh.pxssh()
            cisco_ssh.login(
                self.host,
                self.username,
                self.password,
                port=self.port,
                auto_prompt_reset=False,
            )

            # Find the hostname
            initial_line = cisco_ssh.before.decode("utf-8").splitlines()
            router_hostname = initial_line[len(initial_line) - 1]
            router_hostname += "#"
            # Set the discovered hostname as prompt
            regex_expression = ("(?i)^%s" % router_hostname).encode()
            cisco_ssh.PROMPT = re.compile(regex_expression, re.MULTILINE)
            # Allow full arp table to print at once
github pexpect / pexpect / examples / hive.py View on Github external
else:
            username = raw_input('%s username: ' % hostname)
        if len(hcd['password']) > 0:
            password = hcd['password']
        elif cli_password is not None:
            password = cli_password
        else:
            password = getpass.getpass('%s password: ' % hostname)
        host_names.append(hostname)
        hive_connect_info[hostname] = (hostname, username, password, port)
    # build up the list of hive connections using the connection information.
    for hostname in host_names:
        print('connecting to', hostname)
        try:
            fout = file("log_"+hostname, "w")
            hive[hostname] = pxssh.pxssh()
            # Disable host key checking.
            hive[hostname].SSH_OPTS = (hive[hostname].SSH_OPTS
                    + " -o 'StrictHostKeyChecking=no'"
                    + " -o 'UserKnownHostsFile /dev/null' ")
            hive[hostname].force_password = True
            hive[hostname].login(*hive_connect_info[hostname])
            print(hive[hostname].before)
            hive[hostname].logfile = fout
            print('- OK')
        except Exception as e:
            print('- ERROR', end=' ')
            print(str(e))
            print('Skipping', hostname)
            hive[hostname] = None
    return host_names, hive