Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way using Paramiko and Python to get the banner of the SSH server you connected to?

Is there a way using Paramiko and Python to get the banner of the SSH server you attempt to connect to?

I am dealing with an ultra secure server setup process for many machines and the passwords are generated via a predefined cipher key which get's printed out at with the SSH banner. I have access to the utility that will give me the password, but I need the text in the banner to actually generate the initial password.

like image 859
Rusty Weber Avatar asked Mar 21 '23 22:03

Rusty Weber


1 Answers

Looks like this wasn't a feature. Good thing I requested it and the totally awesome developers put it in...
https://github.com/paramiko/paramiko/issues/273

# !/usr/bin/python

import paramiko


def grab_banner(ip_address, port):
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        client.connect(ip_address, port=port, username='username', password='bad-password-on-purpose')
    except:
        return client._transport.get_banner()


if __name__ == '__main__':
    print grab_banner('192.168.1.26', 22)
like image 65
Rusty Weber Avatar answered Apr 06 '23 04:04

Rusty Weber