Jump to content

Automate SSH login with expect or sshpass?


vailixi

Recommended Posts

I want to automate an SSH login. I was looking at sshpass or expect. But I haven't been able to find a working example of either. Anyboy use either of these?

Also something of note. I don't know the hostname of the remote machine yet. I'm trying to get that in an automated way as well. I've tried raceroute, smbclient, nslookup, host, arp, and finger. Expect needs to expect  user@host before it can send any commands over SSH but I don't know the hostname at this point.

 

Edited by vailixi
Link to comment
Share on other sites

Nmap can get the hostname ;) and you can output it in grepable format to use later

Hostnames will only work if netbios or samba is enabled, or is in it's dns name as far as I know. MDNSrecon, is also be able to get the names for you while scanning for devices. You have to start avahi service first, then run "./mdnsrecon.rb x.x.x.x/x" to scan the subnet where x.x.x.x is the subnet and /x the subnet mask. I use it to scan my network to get machines and their names when I'm doing VulnHub CTF's. - https://github.com/darkoperator/MDNSRecon Mdnsrecon gives you some more info about the device as well, and is pretty fast at what it does.

Expect requires a separate file for the expect commands and uses a different header than bash's #!/bin/bash. You can call it form a bash script, but can't use the expect commands directly in the bash script. Expect is not my strong suit. I've used it with a SMTP script before, but it's not something I'm fluent in. Might help you a bit - http://www.admin-magazine.com/Articles/Automating-with-Expect-Scripts

Edited by digip
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...