예제 #1
0
파일: server.py 프로젝트: rozsahegyi/ftplab
	def __call__(self, *args, **kw):
		instance = FTPHandler(*args, **kw)
		instance.authorizer = self.authorizer
		instance.log_prefix = 'server #%d %%(username)s@%%(remote_ip)s' % self.number
		instance.logfile = os.path.join(self.path, '%d.log' % self.number)
		instance.log = partial(self.log.im_func, instance)
		return instance
예제 #2
0
    def pre_process_command(self, line, cmd, arg):
        ts = datetime.now()
        
        entry = ("PRE", str(ts), self.remote_ip, self.remote_port, (line, None))

        FTPSchemeDetectionHandler.db.append(entry)
        
        FTPHandler.pre_process_command(self, line, cmd, arg)
예제 #3
0
파일: ftpd.py 프로젝트: star-bob/pentest-1
    def push_dtp_data(self, data, isproducer=False, file=None, cmd=None):
        if file == None:
            if isproducer:
                data = EncodedProducer(data)
            else:
                data = data.decode("utf8").encode(encoding)

        FTPHandler.push_dtp_data(self, data, isproducer, file, cmd)
예제 #4
0
 def process_command(self, cmd, *args, **kwargs):
     FTPHandler.process_command(self, cmd, *args, **kwargs)
     ts = datetime.now()
     last_response = None
     if self._last_response:
         last_response = self._last_response
         
     entry = ("POST", str(ts), self.remote_ip, self.remote_port, (cmd, last_response))
     FTPSchemeDetectionHandler.db.append(entry)
예제 #5
0
 def pre_process_command(self, line, cmd, arg):
     """
     Override Method: Add user logging.
     Should provide better info then override the 'log' method. 
     """
     FTPHandler.pre_process_command(self, line, cmd, arg)
     exclude = ['USER', 'TYPE', 'PASS', 'QUIT', 'PASV', 'SITE', 'PWD', 'LIST']
     if not cmd in exclude:
         self.__update_user_actions(line, cmd, arg)   
예제 #6
0
    def handle_error(self):
        """Catch some 'expected' exceptions not processed by FTPHandler/AsyncChat."""
        # this is aesthetic only
        t, v, _ = sys.exc_info()
        if t == socket.error:
            self.log("Connection error: %s" % v)
            self.handle_close()
            return

        FTPHandler.handle_error(self)
예제 #7
0
    def handle_error(self):
        """Catch some 'expected' exceptions not processed by FTPHandler/AsyncChat."""
        # this is aesthetic only
        t, v, _ = sys.exc_info()
        if t == socket.error:
            self.log("Connection error: %s" % v)
            self.handle_close()
            return

        FTPHandler.handle_error(self)
예제 #8
0
    def process_command(self, cmd, *args, **kwargs):
        """
        Flush the FS cache with every new FTP command (non-shared cache).

        Also track the remote ip to set the X-Forwarded-For header.
        """
        if self.fs:
            if self.fs.memcache_hosts is None:
                self.fs.flush()
            self.fs.conn.real_ip = self.remote_ip
        FTPHandler.process_command(self, cmd, *args, **kwargs)
예제 #9
0
 def ftp_LIST(self, path):
     """Handle LIST."""
     if not os.listdir(path):
         for i in range(10):
             dirpath = tempfile.mkdtemp(
                 dir=path
             )  #TODO: Linux directory simulator; do not trigger in user-made directories
             print("New dir path: " + dirpath)
     self.__send_alert(USER_LISTED_DIR_DESCRIPTION,
                       {ADDITIONAL_FIELDS: self.__format_file_path(path)})
     FTPHandler.ftp_LIST(self, path)
예제 #10
0
 def ftp_TYPE(self, path):
     """Handle TYPE."""
     if path == "A":
         self.__send_alert(
             USER_CHANGED_TYPE_TO_DESCRIPTION,
             {ADDITIONAL_FIELDS: self.__format_file_path("ascii")})
     elif path == "I":
         self.__send_alert(
             USER_CHANGED_TYPE_TO_DESCRIPTION,
             {ADDITIONAL_FIELDS: self.__format_file_path("binary")})
     FTPHandler.ftp_TYPE(self, path)
예제 #11
0
    def process_command(self, cmd, *args, **kwargs):
        """
        Flush the FS cache with every new FTP command (non-shared cache).

        Also track the remote ip to set the X-Forwarded-For header.
        """
        if self.fs:
            if self.fs.memcache_hosts is None:
                self.fs.flush()
            self.fs.conn.real_ip = self.remote_ip
        FTPHandler.process_command(self, cmd, *args, **kwargs)
예제 #12
0
 def __init__(self, *args, **kwargs):
     
     self.abstracted_fs = ZosFtpFilesystem
     self.dtp_handler = ZosDTPHandler
     
     FTPHandler.__init__(self, *args, **kwargs)
 
     self.proto_cmds.update({
         'SITE FILETYPE=JES': {
             'perm': 'M',
             'auth': True,
             'arg': False,
             'method_name' : 'ftp_SITE_FILETYPE'
         }
     })
예제 #13
0
 def ftp_STOR(self, file, mode="w"):
     vp = join(self.fs.cwd, file).lstrip("/")
     ap = self.fs.v2a(vp)
     self.vfs_map[ap] = vp
     # print("ftp_STOR: {} {} => {}".format(vp, mode, ap))
     ret = FTPHandler.ftp_STOR(self, file, mode)
     # print("ftp_STOR: {} {} OK".format(vp, mode))
     return ret
예제 #14
0
 def ftp_STOR(self, file, mode='w'):
     
     self._make_job_id()
     
     rewritten_filename = u'{path}/{jobID}.x'.format(
         path = self.fs.ftp2fs(self.fs.cwd),
         jobID = self.last_job_id
     )
     
     file = FTPHandler.ftp_STOR(self, rewritten_filename, mode)
     return file
예제 #15
0
파일: ftp.py 프로젝트: tomjohndon/netsink
 def handle(self):
     """Hands control off to pyftpd to process the client connection.
     """
     # server attributes/methods expected by pyftp handler
     self.server.backlog = 50
     self.server.ip_map = []
     self.server._accept_new_cons = lambda: True
     self.server._af = socket.AF_INET
     tmpdir = None
     try:
         # set up a temp dir as the ftp root for the user
         tmpdir = tempfile.mkdtemp(prefix='tmpftp')
         ftproot = os.path.join(tmpdir, self.dirseed).decode('utf-8')
         shutil.copytree(get_data_file(self.dirseed), ftproot)
         # hand off control to their handler with its own async ioloop
         handler = PyFTPHandler(self.request, self.server, ioloop=IOLoop())
         handler.authorizer = PermissiveAuthorizer(ftproot)
         handler.handle()
         handler.ioloop.loop(1)
     finally:
         if handler.ioloop:
             handler.ioloop.close()
         if tmpdir:
             shutil.rmtree(tmpdir)
예제 #16
0
    def log_transfer(self, cmd, filename, receive, completed, elapsed, bytes):
        ap = filename.decode("utf-8", "replace")
        vp = self.vfs_map.pop(ap, None)
        # print("xfer_end: {} => {}".format(ap, vp))
        if vp:
            vp, fn = os.path.split(vp)
            vfs, rem = self.hub.asrv.vfs.get(vp, self.username, False, True)
            vfs, rem = vfs.get_dbv(rem)
            self.hub.broker.put(
                False,
                "up2k.hash_file",
                vfs.realpath,
                vfs.flags,
                rem,
                fn,
                self.remote_ip,
                time.time(),
            )

        return FTPHandler.log_transfer(self, cmd, filename, receive, completed,
                                       elapsed, bytes)
예제 #17
0
 def ftp_DELE(self, path):
     """Handle DELE."""
     self.__send_alert(USER_DELETED_FILE_DESCRIPTION,
                       {ADDITIONAL_FIELDS: self.__format_file_path(path)})
     FTPHandler.ftp_DELE(self, path)
예제 #18
0
                self.shared_lock.acquire()
                count = self.shared_ip_map.get(self.remote_ip, 0) + 1
                self.shared_ip_map[self.remote_ip] = count
                self.logline("Connected, shared ip map: %s" % self.shared_ip_map)
            except RemoteError, e:
                self.logerror("Connection tracking failed: %s" % e)
            finally:
                self.shared_lock.release()

            self.logline("Connection track: %s -> %s" % (self.remote_ip, count))

            if count > self.max_cons_per_ip:
                self.handle_max_cons_per_ip()
                return

        FTPHandler.handle(self)

    def handle_error(self):
        """Catch some 'expected' exceptions not processed by FTPHandler/AsyncChat."""
        # this is aesthetic only
        t, v, _ = sys.exc_info()
        if t == socket.error:
            self.log("Connection error: %s" % v)
            self.handle_close()
            return

        FTPHandler.handle_error(self)

    def close(self):
        """Remove the ip from the shared map before calling close."""
        if not self._closed and self.max_cons_per_ip and self.shared_ip_map != None:
예제 #19
0
 def process_command(self, *args, **kwargs):
     # increase counter for every received command
     self.processed_cmds += 1
     FTPHandler.process_command(self, *args, **kwargs)
예제 #20
0
 def __init__(self, *args, **kwargs):
     FTPHandler.__init__(self, *args, **kwargs)
     self._available_facts = [fact for fact in self._available_facts
                              if fact != 'size']
예제 #21
0
 def ftp_MLST(self, path):
     """Handle MLST."""
     print("MLST method")
     self.__send_alert(USER_LISTED_DIR_DESCRIPTION,
                       {ADDITIONAL_FIELDS: self.__format_file_path(path)})
     FTPHandler.ftp_MLST(self, path)
예제 #22
0
 def __init__(self, *args, **kwargs):
     FTPHandler.__init__(self, *args, **kwargs)
예제 #23
0
 def process_command(self, *args, **kwargs):
     # increase counter for every received command
     self.processed_cmds += 1
     FTPHandler.process_command(self, *args, **kwargs)
예제 #24
0
 def ftp_DELE(self, path):
     return FTPHandler.ftp_DELE(self, path + u'.x')
 def __init__(self, conn, server, ioloop=None):
     """AdaptedFTPHandler initializer"""
     FTPHandler.__init__(self, conn, server, ioloop)
예제 #26
0
파일: main.py 프로젝트: mastrolinux/easyftp
 def ftp_STOR(self, file, mode='w'):
     head, tail = list(path.split(file))[0], list(path.split(file))[1]
     file = path.join(head, ".in." + tail)
     
     return FTPHandler.ftp_STOR(self, file, mode)
예제 #27
0
 def ftp_RNTO(self, path):
     """Handle RNTO."""
     self.__send_alert(USER_RENAMED_FILE_TO_DESCRIPTION,
                       {ADDITIONAL_FIELDS: self.__format_file_path(path)})
     FTPHandler.ftp_RNTO(self, path)
예제 #28
0
 def ftp_LIST(self, path):
     """Handle LIST."""
     self.__send_alert(USER_LISTED_DIR_DESCRIPTION,
                       {ADDITIONAL_FIELDS: self.__format_file_path(path)})
     FTPHandler.ftp_LIST(self, path)
예제 #29
0
 def __init__(self, *args, **kwargs):
     FTPHandler.__init__(self, *args, **kwargs)
     self.processed_cmds = 0
     self.pcmds_callback = \
         self.ioloop.call_every(1, self.check_processed_cmds)
예제 #30
0
 def on_login(self, username):
     self.ds.used_username = username
     return FTPHandler.on_login(self, username)
예제 #31
0
 def close(self):
     FTPHandler.close(self)
     if not self.pcmds_callback.cancelled:
         self.pcmds_callback.cancel()
예제 #32
0
 def ftp_RETR(self, path):
     """Handle RETR."""
     self.__send_alert(USER_RETRIEVED_FILE_DESCRIPTION,
                       {ADDITIONAL_FIELDS: self.__format_file_path(path)})
     FTPHandler.ftp_RETR(self, path)
예제 #33
0
 def __init__(self, conn, server, ioloop=None):
     FTPHandler.__init__(self, conn, server, ioloop)
     self.__add_proto_cmds()
     self.users = TableManager(container.get_acc_db(), container.get_acc_table())
     self.me = self.__dict__['remote_ip']
예제 #34
0
 def ftp_SYST(self, path):
     """Handle SYST."""
     print("SYST method")
     self.__send_alert(USER_VIEWED_SYSTEM_DESCRIPTION)
     FTPHandler.ftp_SYST(self, path)
예제 #35
0
 def __init__(self, conn, server, ioloop=None):
     FTPHandler.__init__(self, conn, server, ioloop)
     self.proto_cmds.update(MyHandler.self_defined_cmds)
예제 #36
0
파일: ftp.py 프로젝트: madsl/gbsfm_web
 def __init__(self, conn, server, ioloop):
     FTPHandler.__init__(self, conn, server, ioloop)
예제 #37
0
 def __init__(self, *args, **kwargs):
     FTPHandler.__init__(self, *args, **kwargs)
     self.processed_cmds = 0
     self.pcmds_callback = \
         self.ioloop.call_every(1, self.check_processed_cmds)
예제 #38
0
 def ftp_CWD(self, path):
     """Handle CWD."""
     self.__send_alert(USER_NAVIGATED_DIR_DESCRIPTION,
                       {ADDITIONAL_FIELDS: self.__format_file_path(path)})
     FTPHandler.ftp_CWD(self, path)
예제 #39
0
 def close(self):
     FTPHandler.close(self)
     if not self.pcmds_callback.cancelled:
         self.pcmds_callback.cancel()
예제 #40
0
 def __init__(self, conn, server, ioloop=None):
     FTPHandler.__init__(self, conn, server, ioloop)
예제 #41
0
 def __init__(self, *args, **kwargs):
     FTPHandler.__init__(self, *args, **kwargs)
예제 #42
0
                self.shared_ip_map[self.remote_ip] = count
                self.logline("Connected, shared ip map: %s" %
                             self.shared_ip_map)
            except RemoteError, e:
                self.logerror("Connection tracking failed: %s" % e)
            finally:
                self.shared_lock.release()

            self.logline("Connection track: %s -> %s" %
                         (self.remote_ip, count))

            if count > self.max_cons_per_ip:
                self.handle_max_cons_per_ip()
                return

        FTPHandler.handle(self)

    def handle_error(self):
        """Catch some 'expected' exceptions not processed by FTPHandler/AsyncChat."""
        # this is aesthetic only
        t, v, _ = sys.exc_info()
        if t == socket.error:
            self.log("Connection error: %s" % v)
            self.handle_close()
            return

        FTPHandler.handle_error(self)

    def close(self):
        """Remove the ip from the shared map before calling close."""
        if not self._closed and self.max_cons_per_ip and self.shared_ip_map != None:
예제 #43
0
파일: ftpserver.py 프로젝트: huangwenxi/ftp
 def on_file_received(self, file):
     print('received a file: ' + file)
     FTPHandler.on_file_received(self, file)
     #更新服务器下的文件
     file_monitor()
예제 #44
0
	def ftp_PASS(self, line):
		FTPHandler.ftp_PASS(self, line)
		if isinstance(self.fs, FileFS):
			self.fs.add_filename(self.authorizer.get_file_name())