# Path: beeswarm/drones/honeypot/capabilities/handlerbase.py
# class HandlerBase(object):
#     def __init__(self, options, workdir):
#         """
#         Base class that all capabilities must inherit from.
# 
#         :param sessions: a dictionary of Session objects.
#         :param options: a dictionary of configuration options.
#         :param workdir: the directory which contains files for this
#                         particular instance of Beeswarm
#         """
#         self.options = options
#         self.sessions = {}
#         if 'users' in options:
#             self.users = options['users']
#         else:
#             self.users = {}
#         # virtual file system shared by all capabilities
#         self.vfsystem = OSFS(os.path.join(workdir, 'data/vfs'))
#         # service port
#         self.port = int(options['port'])
# 
#     def create_session(self, address):
#         protocol = self.__class__.__name__.lower()
#         session = Session(address[0], address[1], protocol, self.users)
#         self.sessions[session.id] = session
#         session.destination_port = self.port
#         logger.debug(
#             'Accepted {0} session on port {1} from {2}:{3}. ({4})'.format(protocol, self.port, address[0],
#                                                                           address[1], str(session.id)))
#         logger.debug('Size of session list for {0}: {1}'.format(protocol, len(self.sessions)))
#         return session
# 
#     def close_session(self, session):
#         logger.debug('Closing sessions')
#         session.end_session()
#         if session.id in self.sessions:
#             del self.sessions[session.id]
#         else:
#             assert False
# 
#     def handle_session(self, socket, address):
#         raise Exception('Do no call base class!')


import socket
import random
import logging
import SocketServer
from beeswarm.drones.honeypot.capabilities.handlerbase import HandlerBase
from beeswarm.shared.vnc_constants import *
    def handle(self):
        self.request.send(RFB_VERSION)
        client_version = self.request.recv(1024)
        if client_version == RFB_VERSION:
            self.security_handshake()
        else:
            self.finish()

    def security_handshake(self):
        self.request.send(SUPPORTED_AUTH_METHODS)
        sec_method = self.request.recv(1024)
        if sec_method == VNC_AUTH:
            self.do_vnc_authentication()
        else:
            self.finish()

    def do_vnc_authentication(self):
        challenge = get_random_challenge()
        self.request.send(challenge)
        client_response_ = self.request.recv(1024)

        # This could result in an ugly log file, since the des_challenge is just an array of 4 bytes
        self.session.try_auth('des_challenge', challenge=challenge, response=client_response_)
        if self.session.authenticated:
            self.request.send(AUTH_SUCCESSFUL)
        else:
            self.request.send(AUTH_FAILED)
        self.finish()



# Path: beeswarm/drones/honeypot/capabilities/handlerbase.py
# class HandlerBase(object):
#     def __init__(self, options, workdir):
#         """
#         Base class that all capabilities must inherit from.
# 
#         :param sessions: a dictionary of Session objects.
#         :param options: a dictionary of configuration options.
#         :param workdir: the directory which contains files for this
#                         particular instance of Beeswarm
#         """
#         self.options = options
#         self.sessions = {}
#         if 'users' in options:
#             self.users = options['users']
#         else:
#             self.users = {}
#         # virtual file system shared by all capabilities
#         self.vfsystem = OSFS(os.path.join(workdir, 'data/vfs'))
#         # service port
#         self.port = int(options['port'])
# 
#     def create_session(self, address):
#         protocol = self.__class__.__name__.lower()
#         session = Session(address[0], address[1], protocol, self.users)
#         self.sessions[session.id] = session
#         session.destination_port = self.port
#         logger.debug(
#             'Accepted {0} session on port {1} from {2}:{3}. ({4})'.format(protocol, self.port, address[0],
#                                                                           address[1], str(session.id)))
#         logger.debug('Size of session list for {0}: {1}'.format(protocol, len(self.sessions)))
#         return session
# 
#     def close_session(self, session):
#         logger.debug('Closing sessions')
#         session.end_session()
#         if session.id in self.sessions:
#             del self.sessions[session.id]
#         else:
#             assert False
# 
#     def handle_session(self, socket, address):
#         raise Exception('Do no call base class!')


# Path: beeswarm/drones/honeypot/capabilities/vnc.py
import socket
import random
import logging
import SocketServer
from beeswarm.drones.honeypot.capabilities.handlerbase import HandlerBase
from beeswarm.shared.vnc_constants import *

    def handle(self):
        self.request.send(RFB_VERSION)
        client_version = self.request.recv(1024)
        if client_version == RFB_VERSION:
            self.security_handshake()
        else:
            self.finish()

    def security_handshake(self):
        self.request.send(SUPPORTED_AUTH_METHODS)
        sec_method = self.request.recv(1024)
        if sec_method == VNC_AUTH:
            self.do_vnc_authentication()
        else:
            self.finish()

    def do_vnc_authentication(self):
        challenge = get_random_challenge()
        self.request.send(challenge)
        client_response_ = self.request.recv(1024)

        # This could result in an ugly log file, since the des_challenge is just an array of 4 bytes
        self.session.try_auth('des_challenge', challenge=challenge, response=client_response_)
        if self.session.authenticated:
            self.request.send(AUTH_SUCCESSFUL)
        else:
            self.request.send(AUTH_FAILED)
        self.finish()



class Vnc(HandlerBase):