利用Python编写FTP服务器匿名登录检查工具
本代码利用面向对象思想编写,主要用到的模块包括:
1. ftplib,为python内置模块,通过该模块与FTP服务器进行交互;
2. optparse,为python内置模块,用来处理命令行参数
import ftplib import termcolor import optparse import sys class FTPAnonymousCheck: def __init__(self) -> None: self.target = self.get_params() #通过命令行得到目标FTP服务器的IP地址 self.banner() def banner(self): banner = """ ****************************************************************** ****************************************************************** %s ****************************************************************** ****************************************************************** """ % termcolor.colored("FTP Anonymous Login Check Tool by Jason Wong V1.0",'yellow') print(banner) def get_params(self): parser = optparse.OptionParser('Usage: <Program> -t target') parser.add_option('-t', '--target', dest='target', type="string", help="Specify IP address of target") options, args = parser.parse_args() if options.target is None: print(parser.usage) sys.exit(0) return options.target def run(self): try: ftp = ftplib.FTP(self.target) ftp.login('anonymous','anonymous') print(ftp.getwelcome(),'\n') print(termcolor.colored("[-] The target allows anonymous login: %s" % self.target, 'blue')) except: pass if __name__ == "__main__": ftpobj = FTPAnonymousCheck() ftpobj.run()
STRIVE FOR PROGRESS,NOT FOR PERFECTION