Egress-Assess/protocols/servers/ftp_server.py

57 lines
1.7 KiB
Python
Raw Normal View History

2014-12-24 13:37:31 +00:00
'''
This is the code for the ftp server
'''
import os
import socket
import sys
2014-12-24 13:37:31 +00:00
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
class Server:
def __init__(self, cli_object):
self.protocol = "ftp"
self.username = cli_object.username
self.password = cli_object.password
self.data_directory = ""
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(('', 21), handler)
server.serve_forever()
except socket.error:
print "[*][*] Error: Port 80 is currently in use!"
print "[*][*] Error: Please restart when port is free!\n"
sys.exit()
2014-12-24 13:37:31 +00:00
except ValueError:
print "[*] Error: The directory you provided may not exist!"
print "[*] Error: Please re-run with a valid FTP directory."
sys.exit()
return