1

I am trying to connect setup a ssh connection with a host machine. Here is my code:

def make_connection_paramiko(Username, Password):
    ssh = paramiko.SSHClient()
    hostname = "[email protected]"
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
    try:
        ssh.connect(hostname, port = 22, username = 'username', password = 'password')
    except paramiko.AuthenticationException:
        print "Login failed! %s\t%s" %(username, password)
    except socket.timeout:
        print "Socket connection failed"
        #print str(value) +"\t"+ message
    else:
        print "Login Successful! %s\t%s" %(username, password)
    ssh.close()

But for some reason I keep on getting the following error:

Traceback (most recent call last):
  File "pass_crack.py", line 56, in <module>
    begin_cracking(wordlist, username)
  File "pass_crack.py", line 45, in begin_cracking
    make_connection_paramiko(username, "hello")
  File "pass_crack.py", line 29, in make_connection_paramiko
    ssh.connect(hostname, port = 3600, username = 'xxxxxxx', password = 'xxxxxx')
  File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 282, in connect
    for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
socket.error: [Errno 2] No such file or directory

I am trying to connect using paramiko with python, and I am using Ubuntu 13.04. I am not sure what is wrong, when I have tried to connect using the same values for the hostname, username, and password using pxssh the connection works, so why doesn't it work with paramiko?

Thanks in advance

2
  • 3
    pass_crack.py? I'm all for learning by exploration when it comes to network security, but isn't asking for help with a dictionary attack tool a bit audacious? Commented Nov 19, 2013 at 22:21
  • @LukasGraf its for my security class where my prof has set up fake user accounts and we need to try to get in. I was going to use pxssh but it is a bit too slow, I was hoping that paramiko would be faster Commented Nov 19, 2013 at 23:50

1 Answer 1

2

Answer

That's not a hostname:

hostname = "[email protected]"

Instead, that's a connection string. Remove the username@ section, and it should connect again.

Further Information

Remember, you can always look at the source code. Here, you can see that hostname is passed directly into the raw socket call:

socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM)

Looking at the help for socket.getaddrinfo, we can see it's trying to resolve an actual hostname, similar to the syntax required for nslookup:

>>> print socket.getaddrinfo.__doc__
getaddrinfo(host, port [, family, socktype, proto, flags])
    -> list of (family, socktype, proto, canonname, sockaddr)

Resolve host and port into addrinfo struct.

Lastly, I would recommend looking at enabling debugging in paramiko, and other underlying libraries:

>>> import logging
>>> logger = paramiko.util.logging.getLogger()
>>> logger.setLevel(logging.DEBUG)
Sign up to request clarification or add additional context in comments.

2 Comments

When I remove the username@ from the host, i get a gui popup asking to put in the password for the private key and then its my email address
Ok, then it's working correctly. You have a password protected private key, and must give the password to decrypt it. Your function currently doesn't do anything except connect, and close the connection. You should try and execute a remote command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.