How to use the pexpect.pxssh.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 gitgik / penetration-testing / ssh_bot.py View on Github external
def connect(self):
        """Function esptablishes a SSH connection to a target host."""
        try:
            s = pxssh.pxssh()
            s.login(self.host, self.user, self.password)
            return s
        except Exception, e:
            print e
            print '[-] Error Connecting'
github pexpect / pexpect / tests / test_pxssh.py View on Github external
def test_ssh_config_no_user(self):
        ssh = pxssh.pxssh(debug_command_string=True)
        temp_file = tempfile.NamedTemporaryFile()
        config_path = temp_file.name
        temp_file.write(b'Host server\n'
                        b'Host not-server\n')
        temp_file.seek(0)
        try:
            string = ssh.login('server', ssh_config=config_path)
            raise AssertionError('Should have failed due to no user.')
        except TypeError:
            pass
github pexpect / pexpect / tests / test_pxssh.py View on Github external
def test_ssh_config_passing_string(self):
        ssh = pxssh.pxssh(debug_command_string=True)
        temp_file = tempfile.NamedTemporaryFile()
        config_path = temp_file.name
        string = ssh.login('server', 'me', password='s3cret', spawn_local_ssh=False, ssh_config=config_path)
        if not '-F '+config_path in string:
            assert False, 'String generated from SSH config passing is incorrect.'
github avocado-framework-tests / avocado-misc-tests / io / net / virt-net / lpm_basic.py View on Github external
def login(self, ipaddr, username, password):
        '''
        SSH Login method for remote server
        '''
        pxh = pxssh.pxssh()
        # Work-around for old pxssh not having options= parameter
        pxh.SSH_OPTS = pxh.SSH_OPTS + " -o 'StrictHostKeyChecking=no'"
        pxh.SSH_OPTS = pxh.SSH_OPTS + " -o 'UserKnownHostsFile /dev/null' "
        pxh.force_password = True

        pxh.login(ipaddr, username, password)
        pxh.sendline()
        pxh.prompt(timeout=60)
        # Ubuntu likes to be "helpful" and alias grep to
        # include color, which isn't helpful at all. So let's
        # go back to absolutely no messing around with the shell
        pxh.set_unique_prompt()
        pxh.prompt(timeout=60)
        self.pxssh = pxh
github ajackal / honey-hornet / honey-hornet.py View on Github external
""" Function tests the SSH service with all of the users and passwords given """
        port = "22"
        service = "SSH"
        try:
            self.CONNECTION_LOCK.acquire()
            host = vulnerable_host.ip
            if self.verbose:
                print "[*] Testing SSH service on {0}...".format(host)
            for credential in credentials:
                try:
                    user = str(credential[0])
                    password = str(credential[1])
                    # This works for up-to-date SSH servers:
                    # ssh_conn = pxssh.pxssh()
                    # Old SSH servers running "ssh-dss" needs this option instead:
                    ssh_conn = pxssh.pxssh(options={"StrictHostKeyChecking": "no", "HostKeyAlgorithms": "+ssh-dss"})
                    ssh_conn.login(host, user, password)
                    self.log_results(host, port, user, password, service)
                    ssh_conn.logout()
                    ssh_conn.close()
                except pxssh.EOF as EOF_error:
                    self.log_service_error(host, port, service, EOF_error)
                except pxssh.ExceptionPxssh as error:
                    self.log_service_error(host, port, service, error)
                except KeyboardInterrupt:
                    exit(0)
        except threading.ThreadError as thread_error:
            self.log_error(service, thread_error)
        except KeyboardInterrupt:
            exit(0)
        finally:
            self.CONNECTION_LOCK.release()
github bing0o / Python-Scripts / ssh_crack.py View on Github external
def connect(host, user, password):
    try:
        s = pxssh.pxssh()
        s.login(host, user, password)
        print cl.red+("\n[+] Password Found: [ {} ] ".format(password))+cl.end
        print ("\n[For Connect With SSH Service Write] : ssh {}@{}".format(user,host))
	print "[Then Enter Password]: ",password
	print "\n\t* Done *\n"
        exit(0)
    except Exception:
        return None 
try:
github custom-components / sensor.ssh / custom_components / sensor / ssh.py View on Github external
def _connect(self):
        """Connect to the Unifi AP SSH server."""
        from pexpect import pxssh, exceptions

        self._ssh = pxssh.pxssh()
        try:
            self._ssh.login(self._host, self._username,
                           password=self._password, port=self._port)
            self._connected = True
        except exceptions.EOF:
            _LOGGER.error("Connection refused. SSH enabled?")
            self._disconnect()
github msfidelis / Kill-Router- / modules / ssh.py View on Github external
def attack(self, target, port, username, password, method):

        try:
            s = pxssh.pxssh()
            s.login(target,username,password,port=port)

            return True

        except Exception, e:
            return False
github PowerScript / KatanaFramework / scripts / BruteForceSSH.py View on Github external
elif actions=="back" or actions=="b":
			return
			return
		elif actions=="run"  or actions=="r":
			d.run()
			try:
				ping.live(defaulthost,defaultport)
				if True:
					try:
						d.loading_file()
						try:
							with open(defaultdicc,'r') as passs:
								for ps in passs:
									ps=ps.replace("\n","")
									try:
										connect = pxssh.pxssh()
										connect.login(defaulthost,defaultuser,ps)
										if True:
											ping.save("BruteForceSSH",defaulthost,defaultport,defaultuser,ps)
											d.Success(defaultuser,ps)
											return 1
									except:
										print " "+Alr+" Checking ("+defaultuser+"="+ps+")"
						except:
							Errors.Errors(event=sys.exc_info()[0], info=defaultdicc)
					except:
						Errors.Errors(event=sys.exc_info()[0], info=False)
			except:
				Errors.Errors(event=sys.exc_info()[0], info=defaulthost+":"+defaultport)
		else:
			d.No_actions()
	except: