Exemplo n.º 1
0
def main():
    # 新建一个用户组
    authorizer = DummyAuthorizer()
    # 将用户名,密码,指定目录,权限 添加到里面
    authorizer.add_user("root", "123456", ".", perm="elradfmwMT")  # adfmw
    # 这个是添加匿名用户,任何人都可以访问,如果去掉的话,需要输入用户名和密码,可以自己尝试
    authorizer.add_anonymous(".")

    # 带宽限制
    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit = 1024 * 1024  # 1M/sec (1024 * 1024)
    dtp_handler.write_limit = 1024 * 1024  # 1M/sec (1024 * 1024)

    # FTP初始参数设置
    handler = MyHandler
    handler.timeout = 300
    handler.authorizer = authorizer
    handler.banner = "Ftp Ready......"  # 进入欢迎语
    handler.dtp_handler = dtp_handler

    # 日志
    logging.basicConfig(filename='Ftp.log', level=logging.INFO)

    # 开启服务器
    server = ThreadedFTPServer(("0.0.0.0", 21), handler)
    server.max_cons = 500
    server.max_cons_per_ip = 10
    server.serve_forever()
Exemplo n.º 2
0
def ftpServer(dirPath, account, password):
    # 实例化用户授权管理
    authorizer = DummyAuthorizer()
    authorizer.add_user(account, password, dirPath, perm='elradfmwMT')  # 添加用户 参数:username,password,允许的路径,权限
    authorizer.add_anonymous(os.getcwd())  # 这里是允许匿名用户,如果不允许删掉此行即可

    # 实例化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 = ('0.0.0.0', 21)  # FTP一般使用21,20端口
    server = ThreadedFTPServer(address, handler)  # FTP服务器实例

    # set a limit for connections
    server.max_cons = 256
    server.max_cons_per_ip = 5

    # 开启服务器
    server.serve_forever()
Exemplo n.º 3
0
    def run_pot(self):
        # Get config
        config = configparser.ConfigParser()
        config.read('./ftp/config.ini')
        section = 'DEFAULT'
        FTP_PORT = config[section]['ftp_port']
        FTP_USER = config[section]['ftp_user']
        FTP_PASSWORD = config[section]['ftp_password']
        FTP_DIR = config[section]['ftp_directory']
        ####################

        print("Starting FTP honeypot on port ", FTP_PORT, '...', sep='')
        authorizer = DummyAuthorizer()
        authorizer.add_user(FTP_USER, FTP_PASSWORD, FTP_DIR, perm="elradfmw")
        authorizer.add_anonymous(FTP_DIR, perm="elr")

        handler = FTPHandler
        handler.authorizer = authorizer
        #handler.log_prefix = 'XXX [%(username)s]@%(remote_ip)s'

        handler.banner = "Welcome to the FTP Server :)"

        logging.basicConfig(filename='./ftp/logs/ftp.log', level=logging.DEBUG)

        server = ThreadedFTPServer(('127.0.0.1', FTP_PORT), handler)
        server.max_cons = 10
        server.max_cons_per_ip = 5

        self.is_running = True
        print('FTP server started')
        server_thread = threading.Thread(target=server.serve_forever,
                                         daemon=True)
        server_thread.start()
Exemplo n.º 4
0
def ftpStart(anoDir="",
             anoPerm="elr",
             ip="127.0.0.1",
             port=21,
             pasvPortBegin=60000,
             pasvPortEnd=65535,
             users=[],
             maxCons=512,
             maxConsPerIp=0):
    try:
        # step1:实例化用户授权管理
        authorizer = DummyAuthorizer()
        # step2:添加匿名用户,任何人都可以访问
        if len(anoDir) > 0:
            authorizer.add_anonymous(anoDir, perm=anoPerm)
        # step3:添加非匿名用户名,密码,指定目录,权限
        for user in users:
            authorizer.add_user(user["name"],
                                user["pwd"],
                                user["dir"],
                                perm=user["perm"])
        # step4:实例化FTPHandler
        handler = FTPHandler
        handler.authorizer = authorizer
        handler.passive_ports = range(pasvPortBegin, pasvPortEnd)
        # step5:配置服务器
        server = ThreadedFTPServer((ip, port), handler)
        server.max_cons = maxCons
        server.max_cons_per_ip = maxConsPerIp
        # step6:开启服务器
        server.serve_forever()
    except:
        print("Exception: ftp_server.ftpStart =>\n           " +
              str(sys.exc_info()))
Exemplo n.º 5
0
def main():
    authorizer = DummyAuthorizer()
    global authorizer
    authorizer.add_user('client', 'vina2cluster', '.', perm='elradfmwM')
    authorizer.add_anonymous(os.getcwd())
    handler = MyHandler
    handler.authorizer = authorizer
    handler.banner = "Vina2Cluster FTP Server."
    handler.timeout = 30
    address = ('', port)
    server = ThreadedFTPServer(address, handler)
    server.max_cons = 10000
    server.max_cons_per_ip = 10000
    server.serve_forever()
Exemplo n.º 6
0
def start_ftp(ftp_folder):
    """Start FTP server."""

    authorizer = DummyAuthorizer()
    authorizer.add_anonymous(str(ftp_folder), perm='elradfmw')

    handler = FTPHandler
    handler.authorizer = authorizer

    server = ThreadedFTPServer(('0.0.0.0', 21), handler)
    server.max_cons = 100
    server.max_cons_per_ip = 2

    server.serve_forever()
Exemplo n.º 7
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user(username, password, root_path, perm='elradfmwM')
    authorizer.add_anonymous(os.getcwd())

    handler = FTPHandler
    handler.authorizer = authorizer

    handler.banner = "welcom to ftp"

    address = (host, port)
    server = ThreadedFTPServer(address, handler)

    server.max_cons = 256
    server.max_cons_per_ip = 5

    server.serve_forever()
Exemplo n.º 8
0
def main():
    # create simple FTP servers
    # see how here http://pythonhosted.org/pyftpdlib/tutorial.html
    authorizer = DummyAuthorizer()

    authorizer.add_user("user", "12345", '.', perm="elradfmwM")

    handler = FTPHandler
    handler.authorizer = authorizer

    handler.banner = "pyftpdlib based ftpd ready."

    address = ('', 2121)
    server = ThreadedFTPServer(address, handler)

    server.max_cons = 256
    server.max_cons_per_ip = 5

    server.serve_forever()
Exemplo n.º 9
0
def hanshu(user, password, ftppath):
    authorizer = DummyAuthorizer()
    authorizer.add_user(user, password, ftppath, perm='elr')
    #下面这一句是任何人都可以访问的
    # authorizer.add_anonymous(ftppath)
    #头部
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.banner = "pyftpdlib based ftpd ready"
    #ssl认证
    handler.tls_control_required = True
    handler.tls_data_required = True
    #开启服务器
    #获取本机ip地址
    ip = socket.gethostbyname(socket.gethostname())

    #多线程
    server = ThreadedFTPServer((ip, 21), handler)
    server.max_cons = 48  #ip总连接数
    server.max_cons_per_ip = 3  #每个ip连接总数
    server.serve_forever()  #一直打开
Exemplo n.º 10
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user(
        'user', '12345', './ftphome',
        perm='elradfmwMT')  # 新增使用者 引數:username,password,允許的路徑,許可權
    # authorizer.add_anonymous(os.getcwd())  # 這裡是允許匿名使用者,如果不允許刪掉此行即可
    # 例項化FTPHandler
    handler = MyHandler
    handler.authorizer = authorizer
    # 設定一個客戶端連結時的標語
    handler.banner = "pyftpdlib based ftpd ready."
    # handler.masquerade_address = '151.25.42.11'#指定偽裝ip地址
    # handler.passive_ports = range(60000, 65535)#指定允許的埠範圍
    address = ("0.0.0.0", 21)  # FTP一般使用21,20埠
    server = ThreadedFTPServer(('', 21), handler)

    # set a limit for connections
    server.max_cons = 256
    server.max_cons_per_ip = 5
    # 開啟伺服器
    server.serve_forever()
Exemplo n.º 11
0
def main(username, password, base_dir):
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()
    # Define a new user having full r/w permissions
    authorizer.add_user(username, password, base_dir, perm='elradfmwM')

    # 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 = ('0.0.0.0', 2121)
    server = ThreadedFTPServer(address, handler)

    # set a limit for connections
    server.max_cons = 256
    server.max_cons_per_ip = 5

    # start ftp server
    server.serve_forever()
Exemplo n.º 12
0
def main(user,password,ftppath=".",port=21):
    #新建一个用户组
    authorizer = DummyAuthorizer()
    
    #将用户名,密码,用户访问指定目录,权限 添加到里面,当目录用"."表示.py文件当前所在的目录
    authorizer.add_user(user, password, ftppath, perm="elr") #elr只读,perm="elradfmw",windows 路径用 /
    # authorizer.add_user(user, password, ftppath, perm="elradfmw") #全部权限elradfmw
    
    #这个是添加匿名用户,任何人都可以访问,如果去掉的话,需要输入用户名和密码,可以自己尝试
    authorizer.add_anonymous(ftppath) #windows 路径用 /
    
    #下载速度限制
    # dtp_handler = ThrottledDTPHandler
    # dtp_handler.read_limit = 30720  # 30 Kb/sec (30 * 1024)
    # dtp_handler.write_limit = 30720  # 30 Kb/sec (30 * 1024)
       
    #头部
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.banner = "pyftpdlib based ftpd ready."
    
    #ssl 认证
    handler.tls_control_required = True
    handler.tls_data_required = True
    
    #开启服务器
    ip = socket.gethostbyname(socket.gethostname()) # 获取本机ip地址
    # server = FTPServer((ip, 21), handler) #ip、端口、协议
    
    server = ThreadedFTPServer((ip, port), handler) # 多线程
    # server = MultiprocessFTPServer((ip, 21), handler) #多进程,多进程,3.x貌似去掉了
    
    #连接数
    server.max_cons = 48 #ip连接总数
    server.max_cons_per_ip = 3 #每个ip连接总数  
    
    server.serve_forever() #一直打开
Exemplo n.º 13
0

options = parse_options(argv[1:])
path = options.root_path if options.root_path else '.'
authorizer = DummyAuthorizer()
authorizer.add_user('john', 'john', path, perm='elradfmwM')
authorizer.add_anonymous(path)

handler = FTPHandler
handler.authorizer = authorizer
handler.banner = "pyftpdlib based ftpd ready."

logging.basicConfig(stream=stdout)
address = ('127.0.0.1', options.port)
server = ThreadedFTPServer(address, handler)
server.max_cons = 256
server.max_cons_per_ip = 5


def start_server():
    global server
    server.serve_forever()

def main():
    global server
    t = Thread(target=start_server)
    t.start()
    sleep(3)
    server.close_all()

if __name__ == "__main__":
Exemplo n.º 14
0
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import ThreadedFTPServer
import logging

authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions
authorizer.add_user('yana', 'network', 'test', perm="elradfmwMT")
authorizer.add_user('admin', 'admin', 'admin', perm="elradfmwMT")
# Define a read-only anonymous user
authorizer.add_anonymous('shared')

handler = FTPHandler
handler.authorizer = authorizer
handler.banner = 'Welcome to FTP-server'
handler.passive_ports = range(60000, 65535)
handler.active_dtp
handler.timeout = 600
handler.log_prefix = 'XXX [%(username)s]@%(remote_ip)s'
logging.basicConfig(level=logging.INFO)

server = ThreadedFTPServer(('127.0.0.1', '1027'), handler)
server.max_cons = 50
server.max_cons_per_ip = 5
server.serve_forever()
Exemplo n.º 15
0
def run_ftp_server(para=None):
    # 初始化参数
    server_ip = gol.get_value('ftp_ip')
    server_port = gol.get_value('ftp_port')
    server_model = gol.get_value('ftp_model')
    masquerade_ip = gol.get_value('ftp_masquerade_ip')
    passive_ports = gol.get_value('ftp_passive_ports')
    max_cons = gol.get_value('ftp_max_cons')
    max_cons_per_ip = gol.get_value('ftp_max_cons_per_ip')

    # FTP日志
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    log_handler = TimedRotatingFileHandler(filename='app_ftpserver.log',
                                       when='d',
                                       interval=1,
                                       backupCount=7)
    formatter = logging.Formatter('[%(asctime)s-%(levelname)s] - %(message)s')
    log_handler.setFormatter(formatter)
    logger.addHandler(log_handler)


    #实例化虚拟用户,这是FTP验证首要条件
    authorizer = DummyAuthorizer()

    #添加用户
    for i in ['update','pdf','equip']:
        user = gol.get_value('%s_user' %i)
        passwd = gol.get_value('%s_passwd' % i)
        path = gol.get_value('%s_path' % i)
        perm = gol.get_value('%s_perm' % i)
        # 添加用户权限和路径,括号内的参数是(用户名, 密码, 用户目录, 权限)
        authorizer.add_user(user, passwd, path, perm=perm)

    # 匿名账户
    # authorizer.add_anonymous("D:/")
    #初始化ftp句柄
    handler = MyHandler
    handler.authorizer = authorizer
    handler.max_login_attempts=20

    # 如果你在NAT之后,就用这个指定被动连接的参数
    if  not masquerade_ip:
        logger.info("FTP服务:主动模式!")
    else:
        handler.masquerade_address = masquerade_ip
        handler.passive_ports =  [int(i) for i in passive_ports]
        logger.info("FTP服务:被动模式!端口号:%s" %handler.passive_ports)

    # handler.passive_ports =range(10000,10005)
    #是否启用FXP特性,也就是文件交换协议,从此FTP服务器到另外的FTP服务器,默认False
    # handler.permit_foreign_addresses=True

    # 上传下载速度限制
    # dtp_handler = ThrottledDTPHandler
    # dtp_handler.read_limit = 30720  # 30 Kb/sec (30 * 1024)
    # dtp_handler.write_limit = 30720  # 30 Kb/sec (30 * 1024)
    # handler.dtp_handler = dtp_handler

    address = (server_ip,server_port)
    if server_model:
        server = ThreadedFTPServer(address, handler)
    else:
        server = FTPServer(address, handler)

    server.max_cons = int(max_cons)  # 给链接设置限制
    server.max_cons_per_ip = int(max_cons_per_ip)
    #开始服务
    server.serve_forever()
Exemplo n.º 16
0

options = parse_options(argv[1:])
path = options.root_path if options.root_path else '.'
authorizer = DummyAuthorizer()
authorizer.add_user('john', 'john', path, perm='elradfmwM')
authorizer.add_anonymous(path)

handler = FTPHandler
handler.authorizer = authorizer
handler.banner = "pyftpdlib based ftpd ready."

logging.basicConfig(stream=stdout)
address = ('127.0.0.1', options.port)
server = ThreadedFTPServer(address, handler)
server.max_cons = 256
server.max_cons_per_ip = 5


def start_server():
    global server
    server.serve_forever()


def main():
    global server
    t = Thread(target=start_server)
    t.start()
    sleep(3)
    server.close_all()