def test_bufferoverflow(self): buff = '\x41' * 16793598 # sends 16,793,598 A try: lock = threading.Lock() sshServer = ssh_plugin.server_plugin(lock, PORT) except Exception as e: print("Server Failed to Start") time.sleep(1) try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy()) ssh.connect('localhost', username='' + buff + buff, password='' + buff + buff) connection = True except Exception as e: if e.message == 'Authentication failed.': connection = True else: print e connection = False finally: print(connection) ssh.close() time.sleep(1)
def test_run(self): try: lock = threading.Lock() sshServer = ssh_plugin.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") time.sleep(1) try: ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('localhost', PORT, username='******', password='******') connection = True except Exception as e: if e.message == 'Authentication failed.': connection = True else: print e connection = False finally: self.assertTrue(connection) ssh.close() time.sleep(1)
def test_shellshock (self): try: lock = threading.Lock() sshServer = ssh_plugin.server_plugin(lock, PORT) except Exception as e: print("Server Failed to Start") time.sleep(1) try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy()) ssh.connect('localhost', username='******', password='******') connection = True except Exception as e: if e.message == 'Authentication failed.': connection = True else: print e connection = False finally: print(connection) ssh.close() time.sleep(1)
def test_multithreads(self): try: lock = threading.Lock() sshServer = ssh_plugin.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") time.sleep(1) try: threads = [] for num in range(0, 4): thread = SSHClient() thread.start() threads.append(thread) for thread in threads: thread.stop() connection = True except paramiko.AuthenticationException: connection = False except Exception as e: connection = False finally: self.assertTrue(connection) time.sleep(1)
def test_teardown(self): try: lock = threading.Lock() sshServer = ssh_plugin.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") time.sleep(1) try: sshServer.tear_down() ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('localhost', PORT, username='******', password='******') connection = False sshServer.s.close() except Exception as e: # Currently SSH is design to fail on any password. if e.message == "'server_plugin' object has no attribute 'teardown'": print e.message connection = False else: connection = True finally: self.assertTrue(connection)
def test_startUp(self): try: lock = threading.Lock() sshServer = ssh_plugin.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") try: conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect(("localhost", 22)) connection = True except Exception as e: print e connection = False finally: self.assertTrue(connection) conn.close()
def test_invalidPort(self): try: lock = threading.Lock() sshServer = ssh_plugin.server_plugin(lock, PORT) except Exception as e: self.fail("Server Failed to Start") try: ssh = paramiko.SSHClient() ssh.load_host_keys('dummypublickey') # ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('localhost', 21, username='******', password='******') # ssh.connect('localhost', 22) connection = False except Exception as e: #Currently SSH is design to fail on any password. if e.message == 'Authentication failed.': connection = False else: print e connection = True try: ssh = paramiko.SSHClient() ssh.load_host_keys('dummypublickey') # ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('localhost', 23, username='******', password='******') # ssh.connect('localhost', 22) connection = False except Exception as e: #Currently SSH is design to fail on any password. if e.message == 'Authentication failed.': connection = False else: print e connection = True finally: self.assertTrue(connection) ssh.close()