def main(): """ Main ftp server code """ with open("ABSOLUTE_PATH_OF_config.yaml", 'r') as stream: config = yaml.load(stream) authorizer = DummyAuthorizer() if config.get('user'): for each_user in config['user']: if not os.path.exists(each_user['details']['home_directory']): os.makedirs(each_user['details']['home_directory']) authorizer.add_user( each_user['details']['username'], each_user['details']['password'], each_user['details']['home_directory'], perm=each_user['details']['permission'] ) authorizer.add_anonymous('.') handler = MyHandler handler.certfile = config['certfile'] handler.authorizer = authorizer handler.masquerade_address = config['masquerade_address'] # requires SSL for both control and data channel handler.tls_control_required = True handler.tls_data_required = True handler.passive_ports = range(60000, 60099) server = FTPServer(('', 21), handler) server.serve_forever()
def startftp(username,password,port): authorizer = DummyAuthorizer() if username!='' and password!='': authorizer.add_user(username,password, os.getcwd(), perm='elradfmwMT') else: authorizer.add_user('ss', 'ss', os.getcwd(), perm='elradfmwMT') authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." if port == '': port = 21 address = ('0.0.0.0', port) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 200 server.max_cons_per_ip = 50 # start ftp server server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user('user', '12345', os.getcwd(), perm='elradfmwM') authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." # Specify a masquerade address and the range of ports to use for # passive connections. Decomment in case you're behind a NAT. #handler.masquerade_address = '151.25.42.11' #handler.passive_ports = range(60000, 65535) # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('', 2121) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
def start_FTP_server(): global authorizer, handler, server # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define two users with full r/w permissions, one for each camera user_home_folder = os.getenv("HOME") authorizer.add_user('camright', 'miaa', user_home_folder, perm='elradfmwM') authorizer.add_user('camleft', 'miaa', user_home_folder, perm='elradfmwM') print(user_home_folder) # Instantiate FTP handler class handler = CamerasFTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." handler.permit_privileged_ports = True # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('192.168.125.60', 21) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 512 server.max_cons_per_ip = 0 # 0 == no limit # start ftp server server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user('user', '12345', '.', perm='elradfmwMT') authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = MyHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." # Specify a masquerade address and the range of ports to use for # passive connections. Decomment in case you're behind a NAT. # handler.masquerade_address = '151.25.42.11' # handler.passive_ports = range(60000, 65535) # Instantiate FTP server class and listen on 0.0.0.0:2121 # Use 0.0.0.0 if you want to make it accessible, so that everyone in the network can access the ftp server address = ('0.0.0.0', 21) # Use 127.0.0.1 to test it locally # address = ('127.0.0.1', 21) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
def run(self): """Start the FTP Server for pulsar search.""" self._log.info('Starting Pulsar Search Interface') # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user(self._config['login']['user'], self._config['login']['psswd'], '.', perm=self._config['login']['perm']) authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer handler.abstracted_fs = PulsarFileSystem # Define a customized banner (string returned when client connects) handler.banner = "SKA SDP pulsar search interface." # Instantiate FTP server class and listen on 0.0.0.0:7878 address = (self._config['address']['listen'], self._config['address']['port']) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user('user', '12345', 'files', perm='elradfmwMT') authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." logging.basicConfig(filename='pyftpd.log', level=logging.INFO) handler.log_prefix = 'XXX [%(username)s]@%(remote_ip)s' # Specify a masquerade address and the range of ports to use for # passive connections. Decomment in case you're behind a NAT. #handler.masquerade_address = '151.25.42.11' #handler.passive_ports = range(60000, 65535) # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('0.0.0.0', 2121) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
class FTPd(threading.Thread): def __init__(self, root_dir, address=None, timeout=0.001, dtp_handler=None): threading.Thread.__init__(self) self.__flag = threading.Event() self.__timeout = timeout authorizer = DummyAuthorizer() authorizer.add_anonymous(root_dir) handler = FTPHandler handler.authorizer = authorizer if dtp_handler is not None: handler.dtp_handler = dtp_handler self.server = FTPServer(address, handler) def start(self): self.__flag.clear() threading.Thread.start(self) self.__flag.wait() def run(self): self.__flag.set() while self.__flag.is_set(): self.server.serve_forever(timeout=self.__timeout, blocking=False) self.server.close_all() self.server.close() def stop(self): self.__flag.clear() self.join()
def serve(self): # current directory exfil_directory = os.path.join(os.getcwd(), "data") loot_path = exfil_directory + "/" # Check to make sure the agent directory exists, and a loot # directory for the agent. If not, make them if not os.path.isdir(loot_path): os.makedirs(loot_path) try: authorizer = DummyAuthorizer() authorizer.add_user(self.username, self.password, loot_path, perm="elradfmwM") handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "Connecting to Egress-Assess's FTP server!" try: server = FTPServer(('', self.port), handler) server.serve_forever() except socket.error: print "[*][*] Error: Port %d is currently in use!" % self.port print "[*][*] Error: Please restart when port is free!\n" sys.exit() except ValueError: print "[*] Error: The directory you provided may not exist!" print "[*] Error: Please re-run with a valid FTP directory." sys.exit() return
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user('admin', '12345', '.', perm='elradfmwM') #authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "Simple FTPServer." # Specify a masquerade address and the range of ports to use for # passive connections. Decomment in case you're behind a NAT. #handler.masquerade_address = '151.25.42.11' #handler.passive_ports = range(60000, 65535) # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('', 2121) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
def ftpServer(): # 实例化用户授权管理 authorizer = DummyAuthorizer() authorizer.add_user( 'getUploadFile', 'getUploadFile', "%s/uploads" % LogConfig.dirfilePath, perm='elradfmwMT') # 添加用户 参数:username,password,允许的路径,权限 authorizer.add_user( 'setAPITaskReports', 'setAPITaskReports', "%s/reports" % LogConfig.dirfilePath, perm='elradfmwMT') # 添加用户 参数:username,password,允许的路径,权限 # authorizer.add_anonymous("%s/AutotestWebD/reports" % rootDir, perm='elradfmwMT') # 这里是允许匿名用户,如果不允许删掉此行即可 # 实例化FTPHandler handler = FTPHandler handler.authorizer = authorizer # 设定一个客户端链接时的标语 handler.banner = "pyftpdlib based ftpd ready." # handler.masquerade_address = '151.25.42.11'#指定伪装ip地址 # handler.passive_ports = range(60000, 65535)#指定允许的端口范围 address = (TcpServerConf.ip, TcpServerConf.ftpport) # FTP一般使用21,20端口 server = FTPServer(address, handler) # FTP服务器实例 # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # 开启服务器 server.serve_forever(handle_exit=False)
def main(): # 实例化一个虚拟授权者来管理“虚拟”用户 authorizer = DummyAuthorizer() # 定义一个拥有完整权限的新用户 authorizer.add_user('dabolau', '123456', '.', perm='elradfmwMT') # 匿名用户 authorizer.add_anonymous(os.getcwd()) # 实例化FTP处理程序类 handler = FTPHandler handler.authorizer = authorizer # 定义一个自定义的横幅(客户端连接时返回的字符串) handler.banner = 'pyftpdlib based ftpd ready.' # 指定一个伪装的地址和端口范围使用被动连接 # 如果你在一个NAT后面去分解 # handler.masquerade_address = '151.25.42.11' # handler.passive_ports = range(60000, 65535) # 实例化FTP服务器类并在0.0.0.0:2121上监听 address = ('', 2121) server = FTPServer(address, handler) # 设置连接限制 server.max_cons = 256 server.max_cons_per_ip = 5 # 启动FTP服务器 server.serve_forever()
class PecaServer: def __init__(self, bindaddress, bindport, username, password, datafolder): self.bindaddress = bindaddress self.bindport = bindport self.username = username self.password = password self.datafolder = datafolder self.authorizer = None self.handler = None self.server = None def check_data_folder(self): if os.path.isdir(self.datafolder) is False: os.makedirs(self.datafolder) def config_server(self): self.authorizer = DummyAuthorizer() self.authorizer.add_user(self.username, self.password, self.datafolder, perm='elradfmwM') self.handler = FTPHandler self.handler.authorizer = self.authorizer self.handler.banner = "PECA Server" self.server = FTPServer((self.bindaddress, self.bindport), self.handler) # set a limit for connections self.server.max_cons = 1000 self.server.max_cons_per_ip = 1000 def run(self): self.check_data_folder() self.config_server() self.server.serve_forever()
def ftp_server(): authorizer = DummyAuthorizer() user_list = get_user('conf/user.conf') for user in user_list: name, password, permit, homedir = user try: authorizer.add_user(name, password, homedir, perm=permit) except Exception as e: print(e) if setting.enable_anonymous == 'on': authorizer.add_anonymous('/home/') dtp_handler = ThrottledDTPHandler dtp_handler.read_limit = setting.max_download dtp_handler.write_limit = setting.max_upload handler = FTPHandler handler.authorizer = authorizer if setting.enable_logging == 'on': logger.config_logger() handler.banner = setting.welcome_msg handler.passive_ports = range(setting.passive_ports[0], setting.passive_ports[1]) server = FTPServer((SERVER_IP, SERVER_PORT), handler) server.max_cons = setting.max_cons server.max_cons_per_ip = setting.max_per_ip server.serve_forever()
class FTPListener(threading.Thread): """ Simple thread to run the FTP Server """ def __init__(self, user=DEFAULT_USER, pwd=DEFAULT_PWD, port=DEFAULT_FTP_PORT, addr=DEFAULT_FTP_ADDR): """ Constructor """ self.user = user self.pwd = pwd self.port = port self.addr = addr threading.Thread.__init__(self) def run(self): """ Starts the FTP server """ authorizer = DummyAuthorizer() authorizer.add_user(self.user, self.pwd, ".", perm="elradfmw") handler = OneTimeFTPHandler handler.authorizer = authorizer self.server = FTPServer((self.addr, self.port), handler) self.server.serve_forever() def stop(self): """ Stops the FTP server """ if self.server is not None: self.server.close()
class FTPServerDaemon: def __init__(self): self.authorizer = DummyAuthorizer() self.handler = FTPHandler self.handler.timeout = None def add_user(self, userid, password, homedir, perm="elradfmw"): self.authorizer.add_user(userid, password, homedir, perm=perm) def add_anonymous(self, homedir, perm="elradfmw"): self.authorizer.add_anonymous(homedir, perm=perm) def start_server(self, ip="0.0.0.0", port=33333, timeout=None, blocking=True, handle_exit=True, uselog=True, logpath='/var/log/ftpserver.log', loglevel=logging.INFO): self.handler.authorizer = self.authorizer if uselog: logging.basicConfig( filename=logpath, format='%(asctime)s.%(msecs)03d %(levelname)s %(message)s', level=loglevel, datefmt='%Y-%m-%d,%H:%M:%S') self.server = FTPServer((ip, port), self.handler) self.server.serve_forever(timeout, blocking, handle_exit)
def startserver(self): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user(self.user, self.password, './sharefolder',msg_login="******", msg_quit="Goodbye.", perm='elradfmwM') authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = MyHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "A client is connected with your server." # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('', PORT) server = FTPServer(address, handler) # set a limit for connections server.max_cons = allowed_connection server.max_cons_per_ip = allowed_connection_per_ip # start ftp server server.serve_forever()
def start(): # Engine authorization comes from the accounts. authorizer = BiostarAuthorizer() # Instantiate FTP and DTP handler class. handler = BiostarFTPHandler handler.authorizer = authorizer handler.abstracted_fs = BiostarFileSystem # requires SSL for both control and data channel #handler.tls_control_required = True #handler.tls_data_required = True #handler.certfile = 'keycert.pem' # Define a customized banner (string returned when client connects) handler.banner = "Welcome to Biostar-Engine" address = (FTP_HOST, FTP_PORT) server = FTPServer(address, handler) # FTP connection settings. server.max_cons = 256 server.max_cons_per_ip = 5 # Start ftp server. server.serve_forever()
def main(): users = get_users() authorizer = DummyAuthorizer() private_files = "/Repository/" shared_files = "/Repository/Shared/" # Sets home folder and permissions for each user for user in users: if user.user_type == "admin": home = os.getcwd() + private_files permissions = "elradfmwMT" elif user.user_type == "friend": home = os.getcwd() + shared_files permissions = "elrafmwMT" else: print("Error: user type '" + user.user_type + "' is invalid.") continue authorizer.add_user(user.username, user.password, home, permissions) handler = FTPHandler handler.banner = "Hello World!" handler.authorizer = authorizer handler.masquerade_address = get_local_ip() handler.passive_ports = range(60000, 65535) server = FTPServer(("0.0.0.0", 21), handler) server.max_cons = 200 server.max_cons_per_ip = 10 server.serve_forever()
def main(): # Instancia un autorizador dummy para controlar usuarios "virtuales" authorizer = DummyAuthorizer() # Define un nuevo usuario teniendo todos los permisos y otro para usuarios de solo lectura authorizer.add_user('user', '12345', '.', perm='elradfmwMT') authorizer.add_anonymous(os.getcwd()) # Obtener la direcccion del archivo actual # Instancia una clase controladora de FTP handler = FTPHandler handler.authorizer = authorizer # Define un string predeterminado que se envia al cliente cuando se conecte handler.banner = 'pyftpdlib basado en FTP, listo' # Informacion sobre las conexiones y acciones dentro de la carpeta # logging.basicConfig(filename='pyftpd.log', level=logging.INFO) logging.basicConfig(level=logging.INFO, format='(ServidorTCP) %(message)s',) # Instancia una clase servidor FTP address = ('127.0.0.1', 2121) # Direccion IP y puerto de escucha del servidor (puerto por default 21) server = FTPServer(address, handler) # Se crea el socket # configura un limite de conexiones server.max_cons = 10 # Numero maximo de conexiones simultanesas server.max_cons_per_ip = 5 # Numero maximo de conexiones aceptadas por la misma dirección IP (default=0 (sin limite)) # Inicia el servidor FTP server.serve_forever() # (timeout=None, blocking=True, handle_exit=True)
def start_ftp_server(ftp_tuple): host, port, user, password, path = ftp_tuple port = int(port) if user == "": ftp_exit(1, "User is empty") pass if not (1 <= port <= 65535): ftp_exit(1, "Port is invalid") pass if path == '': path = "./" pass authorizer = DummyAuthorizer() authorizer.add_user(user, password, path, perm='elradfmw') handler = FTPHandler handler.authorizer = authorizer if host != '': handler.masquerade_address = host handler.passive_ports = range(50000, 51000) server = FTPServer(('0.0.0.0', port), handler) print("FTP Server Start") server.serve_forever() ftp_exit(0, "FTP Server Exit")
def server_start(is_verbose=False, port=None): if not os.path.isfile('conf.json'): print 'Conf file not found, please run setup.' sys.exit(1) with open('conf.json') as jd: template = json.load(jd) container.set_acc_db(str(template['user_db']), str(template['user_table'])) container.set_shares_db(str(template['user_logs'])) container.set_root_dir(str(template['root'])) container.set_log_file(str(template['root']) + '/pyftpd.log') auth = authorizer() handle = handler handle.user_sendfile = True handle.timeout = None handle.authorizer = auth handle.banner = 'this is the banner' if port: # untested address = ('', 1024) else: address = ('', 21) server = FTPServer(address, handle) server.max_cons = 256 server.maxcons_per_ip = 1000000 if not is_verbose: logging.basicConfig(filename=container.get_log_file(), level=logging.INFO) server.serve_forever()
def run(self): ftpd_config_logging(level=self._ftp_log_level) self._l.info( 'Creating dummy authorizer for user "%s" identified by "%s".' % (self._accepted_login, self._accepted_password)) self._l.info('Home path is "%s"' % self._home_path) self._l.info('Local path is "%s"' % self._local_path) authorizer = DummyAuthorizer() authorizer.add_user(self._accepted_login, self._accepted_password, str(self._home_path), 'elradfmwM') ReceiverHandler.authorizer = authorizer ReceiverHandler.abstracted_fs = ReceiverAbstractedFS self._l.info('Starting server (Ctrl+C to break)...') server = FTPServer((str(self._listening_ip), self._listening_port), ReceiverHandler) server.owner_instance = self server.serve_forever() if self._home_path_auto_delete and self._home_path.parent == pathlib.Path( tempfile.gettempdir()): self._l.info( 'Removing home directory "%s", because it was created automatically.', self._home_path) shutil.rmtree(self._home_path, ignore_errors=True)
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions authorizer.add_user('test', 'test', './', perm='elradfmwM') # Define a read-only anonymous user authorizer.add_anonymous('./') # Instantiate TLS FTP handler class handler = TLS_FTPHandler handler.authorizer = authorizer handler.certfile = './server.crt' handler.keyfile = './server.key' # Define a customized banner (string returned when client connects) handler.banner = "Welcome to test's FTPS." # Instantiate FTP server class and listen on 127.0.0.1:21 address = ('127.0.0.1', 21) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user('user', 'user', 'test_user/', perm='elradfmwMT') # authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." # Specify a masquerade address and the range of ports to use for # passive connections. Decomment in case you're behind a NAT. #handler.masquerade_address = '151.25.42.11' #handler.passive_ports = range(60000, 65535) # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('0.0.0.0', 8080) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server try: server.serve_forever() except KeyboardInterrupt: print('exiting...')
def init_ftp_server(): #用于FTPHandler类的管理员 authorizer = DummyAuthorizer() #读权限e:改变目录,l:列出文件,r:从服务器接收文件 #写权限a:文件上传,d:删除文件,f:文件重命名,m:创建文件,w:写权限 for user in user_list: name, passwd, permit, homedir = user try: authorizer.add_user(name, passwd, homedir, perm=permit) except: print("配置文件错误请检查是否正确匹配了相应的用户名、密码、权限、路径") print(user) dtp_handler = ThrottledDTPHandler # 上传速度 下载速度 dtp_handler.read_limit = max_download dtp_handler.write_limit = max_upload #创建服务器 #handler用于处理接受到的命令,参数包括超时机制(300s)、最大登陆尝试(3) #handler = TLS_FTPHandler #handler.certfile = 'keycert.pem' 如果我们有证书的话,这就是证书地址,但是证书太贵了 handler = FTPHandler handler.authorizer = authorizer #是否打开记录 if enable_logging: logging.basicConfig(filename=logging_name, level=logging.INFO) handler.masquerade_address = masquerade_address #处理NAT时的私有地址和共有地址,这里即本机公网ip handler.passive_ports = range(passive_ports[0], passive_ports[1]) #被动连接 server = FTPServer((ip, port), handler) server.max_cons = max_cons server.max_cons_per_ip = max_pre_ip server.serve_forever()
def main(): user_dir = os.path.join(FTP_ROOT, USER) if not os.path.isdir(user_dir): os.mkdir(user_dir) authorizer = DummyAuthorizer() authorizer.add_user(USER, PASSWORD, user_dir, perm="elradfmw") if ANONYMOUS: authorizer.add_anonymous("/ftp_root/nobody") handler = FTPHandler handler.authorizer = authorizer handler.permit_foreign_addresses = True passive_ports = map(int, PASSIVE_PORTS.split('-')) handler.passive_ports = range(passive_ports[0], passive_ports[1]) print('*************************************************') print('* *') print('* Docker image: mikatux *') print('* https://github.com/mikatux/ftp-server *') print('* *') print('*************************************************') print('SERVER SETTINGS') print('---------------') print "FTP User: "******"FTP Password: ",PASSWORD server = FTPServer((HOST, PORT), handler) server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # anonymous use (WARNING, this will give an anonymous user write access for convienience.) # Use at your own risk. authorizer.add_anonymous(os.path.join(os.getcwd(), './uploads'), perm='elradfmwMT') # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." # Specify a masquerade address and the range of ports to use for # passive connections. Decomment in case you're behind a NAT. #handler.masquerade_address = '151.25.42.11' #handler.passive_ports = range(60000, 65535) # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('', 21) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server print("Serving {} with anonymous read/write access".format(os.getcwd())) server.serve_forever()
def custom_server(self, start=1): # TODO: finish me from pyftpdlib.authorizers import DummyAuthorizer from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer # Generate random username and password for ftp session logging.debug('generating arguments') if not os.path.isdir(self.path): logging.info('%s create directory: %s' % ('device.name', self.path)) os.makedirs(self.path) # Add ftp user authorizer = DummyAuthorizer() logging.debug('generated args: user=%s password=%s path=%s perm=%s' % (self.user, self.password, self.path, self.password)) authorizer.add_user(self.user, self.password, self.path, perm=self.perm) handler = FTPHandler handler.authorizer = authorizer # Instantiate FTP server class and listen logging.debug('%s ftp server listen on: %s %s' % ('device.name', self.address, self.port)) addr = (self.address, self.port) server = FTPServer(addr, handler) # Set a limit for connections server.max_cons = 32 server.max_cons_per_ip = 5 # Start ftp server logging.debug('starting disposable ftp server') server.serve_forever(timeout=600, blocking=False)
def ftp_server(command_line_object): # current directory exfil_directory = os.path.join(os.getcwd(), "data") loot_path = exfil_directory + "/" # Check to make sure the agent directory exists, and a loot # directory for the agent. If not, make them if not os.path.isdir(loot_path): os.makedirs(loot_path) try: authorizer = DummyAuthorizer() authorizer.add_user( command_line_object.username, command_line_object.password, loot_path, perm="lrw") handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "Connecting to Egress-Assess's FTP server!" server = FTPServer(('', 21), handler) server.serve_forever() except ValueError: print "[*] Error: The directory you provided may not exist!" print "[*] Error: Please re-run with a valid FTP directory." sys.exit()
def main(): port = 3334 user = '' password = '' l = sys.argv if (len(l) > 1 and l[1]): user = l[1] if (len(l) > 2 and l[2]): password = l[2] if (len(l) > 3 and l[3]): port = int(l[3]) authorizer = DummyAuthorizer() authorizer.add_user(user, password, os.getcwd(), perm='elradfmwM') authorizer.add_anonymous('.') handler = TLS_FTPHandler handler.certfile = CERTFILE handler.authorizer = authorizer server = FTPServer(("127.0.0.1", port), handler) server.serve_forever()
def serve(self): # current directory exfil_directory = os.path.join(os.getcwd(), "data") loot_path = exfil_directory + "/" # Check to make sure the agent directory exists, and a loot # directory for the agent. If not, make them if not os.path.isdir(loot_path): os.makedirs(loot_path) try: authorizer = DummyAuthorizer() authorizer.add_user( self.username, self.password, loot_path, perm="elradfmwM") handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "Connecting to Egress-Assess's FTP server!" try: server = FTPServer(('', self.port), handler) server.serve_forever() except socket.error: print "[*][*] Error: Port %d is currently in use!" % self.port print "[*][*] Error: Please restart when port is free!\n" sys.exit() except ValueError: print "[*] Error: The directory you provided may not exist!" print "[*] Error: Please re-run with a valid FTP directory." sys.exit() return
def main(): port = 3334 user = '' password = '' l = sys.argv if (len(l) > 1 and l[1]): user = l[1] if (len(l) > 2 and l[2]): password = l[2] if (len(l) > 3 and l[3]): port = int(l[3]) authorizer = DummyAuthorizer() authorizer.add_user(user, password, os.getcwd(), perm='elradfmwM') #authorizer.add_anonymous("/home/nobody") handler = FTPHandler handler.authorizer = authorizer logging.basicConfig(level=logging.DEBUG) server = FTPServer(("127.0.0.1", port), handler) server.serve_forever()
def main(profiles): authorizer = DummyAuthorizer() # 将每个profile映射为一个用户 uploadTmpRoot = tempfile.gettempdir() for p, c in profiles.items(): # perm权限定义说明: # Read permissions: # "e" = change directory (CWD, CDUP commands) # "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE commands) # "r" = retrieve file from the server (RETR command) # Write permissions: # "a" = append data to an existing file (APPE command) # "d" = delete file or directory (DELE, RMD commands) # "f" = rename file or directory (RNFR, RNTO commands) # "m" = create directory (MKD command) # "w" = store a file to the server (STOR, STOU commands) # "M" = change mode/permission (SITE CHMOD command) New in 0.7.0 # 注意:投产时权限似乎应限制为只写,即:'w' uploadTmp = path.join(uploadTmpRoot, p) print uploadTmp if not path.isdir(uploadTmp): mkdir(uploadTmp) authorizer.add_user(p, c["upload"].get("password", ""), uploadTmp, perm="ledw") handler = UploadHandler handler.authorizer = authorizer handler.banner = "OSO fileserv" address = ("", int(getenv("FTP_PORT", "2121"))) logging.basicConfig(filename="logs/ftp.log", level=logging.INFO) server = FTPServer(address, handler) server.max_cons = 256 server.max_cons_per_ip = 5 server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions authorizer.add_user('test', 'test','./', perm='elradfmwM') # Define a read-only anonymous user authorizer.add_anonymous('./') # Instantiate TLS FTP handler class handler = TLS_FTPHandler handler.authorizer = authorizer handler.certfile = './server.crt' handler.keyfile = './server.key' # Define a customized banner (string returned when client connects) handler.banner = "Welcome to test's FTPS." # Instantiate FTP server class and listen on 127.0.0.1:21 address = ('127.0.0.1', 21) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user(konf.ftp_username, konf.ftp_password, 'ftp/', perm='elradfmwM') # authorizer.add_anonymous(os.getcwd()) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." # Instantiate FTP server class and listen on 0.0.0.0:2121 address = ('', 2121) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server server.serve_forever()
def main(): # Instantiate a dummy authorizer for managing 'virtual' users authorizer = DummyAuthorizer() # Define a new user having full r/w permissions authorizer.add_user("user_name", "pass_word", "./", perm="elradfmwM", msg_login="******", msg_quit="bye") # Define a read-only anonymous user authorizer.add_anonymous("./") # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer handler.max_login_attempts = 3 handler.permit_foreign_addresses = True handler.tcp_no_delay = True # Define a customized banner (string returned when client connects) handler.banner = "Welcome to my FTP." # Instantiate FTP server class and listen on 127.0.0.1:21 address = ("0.0.0.0", 2121) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 128 server.max_cons_per_ip = 2 absfs = AbstractedFS(u"./", handler) absfs.cwd = u"/bbb/ss/" # start ftp server server.serve_forever()
def main(): authorizer = UnixAuthorizer(rejected_users=["root"], require_valid_shell=True) handler = FTPHandler handler.authorizer = authorizer handler.abstracted_fs = UnixFilesystem server = FTPServer(('', 21), handler) server.serve_forever()
def handle(self, *args, **options): handler = TLS_FTPHandler handler.certfile = Config.objects.get(key='certfile').value handler.authorizer = DjangoFtpAuthorizer() handler.abstracted_fs = CloudFS server = FTPServer(("0.0.0.0", 21), handler) server.serve_forever()
def start_ftp_server(): cs.CSClient().log(APP_NAME, 'start_ftp_server()...') try: authorizer = DummyAuthorizer() # Define a new user having full r/w permissions and a read-only # anonymous user authorizer.add_user('user', '12345', FTP_DIR, perm='elradfmwM') authorizer.add_anonymous(FTP_DIR) # Instantiate FTP handler class handler = FTPHandler handler.authorizer = authorizer # Define a customized banner (string returned when client connects) handler.banner = "pyftpdlib based ftpd ready." # Instantiate FTP server class and listen on 0.0.0.0:2121. # Application can only use ports higher that 1024 and the port # will need to be allowed in the router firewall address = ('', 2121) server = FTPServer(address, handler) # set a limit for connections server.max_cons = 256 server.max_cons_per_ip = 5 # start ftp server cs.CSClient().log(APP_NAME, 'Starting FTP server...') server.serve_forever() # This will run the server in another thread # t = Thread(target=server.serve_forever()) # t.start() except Exception as e: cs.CSClient().log(APP_NAME, 'Exception occurred! exception: {}'.format(e))
def start_ftp_server(): authorizer = DummyAuthorizer() authorizer.add_anonymous("ftpvista/test") handler = FTPHandler handler.authorizer = authorizer server = FTPServer(("127.0.0.1", 2121), handler) server.serve_forever()
def main(args): user = DEFAULT_USER password = DEFAULT_PASSWORD ip = DEFAULT_IP port = DEFAULT_PORT directory = args.directory permissions = DEFAULT_PERM if args.user: user = args.user if args.password: password = args.password if args.ip: ip = args.ip if args.port: port = args.port authorizer = DummyAuthorizer() authorizer.add_user(user, password, directory, perm=permissions) #handler = TLS_FTPHandler #handler.certfile = 'server.crt' handler = FTPHandler handler.authorizer = authorizer server = FTPServer((ip, port), handler) server.serve_forever()
def main(): authorizer = DummyAuthorizer() authorizer.add_anonymous("/opt/anonymous/", perm="lr") handler = FTPSchemeDetectionHandler handler.authorizer = authorizer server = FTPServer(('', 2121), handler) server.serve_forever()
def run(): authorizer = DummyAuthorizer() authorizer.add_user("user", "12345", r"D:\tmp", perm="elradfmw") authorizer.add_anonymous(r"D:\tmp") handler = FTPHandler handler.authorizer = authorizer server = FTPServer(("127.0.0.1", 5555), handler) server.serve_forever()
def ftp_server_hanlder(username, passwd, homedir, port): authorizer = DummyAuthorizer() authorizer.add_user(username=username, password=passwd, homedir=homedir) handler = FTPHandler handler.authorizer = authorizer handler.passive_ports = range(2000, 4000) server = FTPServer(('0.0.0.0', port), handler) server.serve_forever()
def main(): authorizer = QSFSAuthorizer() handler = QFTPHandler handler.authorizer = authorizer handler.abstracted_fs = AbstractedQSFS server = FTPServer(('127.0.0.1', 21), handler) pyftpdlib.log.LEVEL = logging.DEBUG server.serve_forever()
def main(): authorizer = DummyAuthorizer() authorizer.add_user("user", "12345", ".", perm="elradfmw") authorizer.add_anonymous(".") handler = AntiFloodHandler handler.authorizer = authorizer server = FTPServer(("", 2121), handler) server.serve_forever(timeout=1)
def main(): authorizer = DummyAuthorizer() authorizer.add_user('user', '12345', '.', perm='elradfmwMT') authorizer.add_anonymous('.') handler = AntiFloodHandler handler.authorizer = authorizer server = FTPServer(('', 2121), handler) server.serve_forever(timeout=1)
def connect(host,port,user,password,pathroot): autho = DummyAuthorizer() autho.add_user(user, password, pathroot, perm="elradfmwMT") autho.add_anonymous(".", perm="elradfmwMT") handler = FTPHandler handler.authorizer = autho serv = FTPServer((host, port), handler) serv.serve_forever()
def run_ftpd(host, port, alert_bot, username, password, homedir): authorizer = FTPAuthorizer() authorizer.set_credentials(username, password, homedir) handler = MyFTPHandler handler.bot_queue = alert_bot handler.authorizer = authorizer server = FTPServer((host, port), handler) server.serve_forever()
def main(): authorizer = DummyAuthorizer() authorizer.add_user('user', '12345', '.', perm='elradfmw') authorizer.add_anonymous('.') handler = AntiFloodHandler handler.authorizer = authorizer server = FTPServer(('', 2121), handler) server.serve_forever(timeout=1)
def run_server(): tempdir = tempfile.mkdtemp() authorizer = DummyAuthorizer() authorizer.add_user(FTP_USERNAME, FTP_PASSWORD, tempdir, perm="elradfmw") handler = S3FtpUploadHandler handler.authorizer = authorizer server = FTPServer((BIND_ADDRESS, PORT), handler) server.serve_forever()
def main(): authorizer = UsernameIsPathAuthorizer() authorizer.add_anonymous("/") handler = FTPHandler handler.authorizer = authorizer server = FTPServer(('*', 21), handler) server.serve_forever()
def handle(self, *args, **options): authorizer = DummyAuthorizer() authorizer.add_user('user', '12345', '.', perm='elradfmw') ftp_handler = FTPHandler ftp_handler.authorizer = authorizer ftp_handler.abstracted_fs = YourFS ftpd = FTPServer(('', 21), ftp_handler) ftpd.serve_forever()
def create(path, addr, port): _log('create, path=%s' % path) auth = DummyAuthorizer() auth.add_user("virthub", "virthub", path, perm="elradfmwM") handler = FTPHandler handler.authorizer = auth logging.basicConfig(level=logging.ERROR) srv = FTPServer((addr, port), handler) srv.serve_forever()