# Path: beeswarm/drones/client/baits/clientbase.py
# class ClientBase(object):
#     """ Base class for Bees. This should only be used after sub-classing. """
# 
#     def __init__(self, options):
#         """
#             Initializes common values.
#         :param sessions: A dict which is updated every time a new session is created.
#         :param options: A dict containing the options entry for this bait
#         """
#         self.options = options
#         self.sessions = {}
# 
#     def create_session(self, server_host, server_port, honeypot_id):
#         """
#             Creates a new session.
# 
#         :param server_host: IP address of the server
#         :param server_port: Server port
#         :return: A new `BaitSession` object.
#         """
#         protocol = self.__class__.__name__.lower()
#         session = BaitSession(protocol, server_host, server_port, honeypot_id)
#         self.sessions[session.id] = session
#         return session
# 
#     def close_session(self, session):
#         session.end_session()
#         if session.id in self.sessions:
#             del self.sessions[session]
#         else:
#             assert False
# 
# Path: beeswarm/shared/misc/rfbes.py
# class RFBDes(pyDes.des):
#     def setKey(self, key):
#         """RFB protocol for authentication requires client to encrypt
#            challenge sent by server with password using DES method. However,
#            bits in each byte of the password are put in reverse order before
#            using it as encryption key."""
#         newkey = []
#         for ki in range(len(key)):
#             bsrc = ord(key[ki])
#             btgt = 0
#             for i in range(8):
#                 if bsrc & (1 << i):
#                     btgt = btgt | (1 << 7 - i)
#             newkey.append(chr(btgt))
#         super(RFBDes, self).setKey(newkey)


import logging
import socket
from beeswarm.drones.client.baits.clientbase import ClientBase
from beeswarm.shared.vnc_constants import *
from beeswarm.shared.misc.rfbes import RFBDes
        server_host = self.options['server']
        server_port = self.options['port']
        honeypot_id = self.options['honeypot_id']

        session = self.create_session(server_host, server_port, honeypot_id)
        self.sessions[session.id] = session

        logger.debug(
            'Sending {0} bait session to {1}:{2}. (bait id: {3})'.format('vnc', server_host, server_port, session.id))
        client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            client_socket.connect((server_host, int(server_port)))
            session.source_port = client_socket.getsockname()[1]

        except socket.error as e:
            logger.debug('Caught exception: {0} ({1})'.format(e, str(type(e))))
        else:
            session.did_connect = True
            protocol_version = client_socket.recv(1024)
            client_socket.send(RFB_VERSION)
            supported_auth_methods = client_socket.recv(1024)

            # \x02 implies that VNC authentication method is to be used
            # Refer to http://tools.ietf.org/html/rfc6143#section-7.1.2 for more info.
            if '\x02' in supported_auth_methods:
                client_socket.send(VNC_AUTH)
            challenge = client_socket.recv(1024)

            # password limit for vnc in 8 chars
            aligned_password = (password + '\0' * 8)[:8]

# Path: beeswarm/drones/client/baits/clientbase.py
# class ClientBase(object):
#     """ Base class for Bees. This should only be used after sub-classing. """
# 
#     def __init__(self, options):
#         """
#             Initializes common values.
#         :param sessions: A dict which is updated every time a new session is created.
#         :param options: A dict containing the options entry for this bait
#         """
#         self.options = options
#         self.sessions = {}
# 
#     def create_session(self, server_host, server_port, honeypot_id):
#         """
#             Creates a new session.
# 
#         :param server_host: IP address of the server
#         :param server_port: Server port
#         :return: A new `BaitSession` object.
#         """
#         protocol = self.__class__.__name__.lower()
#         session = BaitSession(protocol, server_host, server_port, honeypot_id)
#         self.sessions[session.id] = session
#         return session
# 
#     def close_session(self, session):
#         session.end_session()
#         if session.id in self.sessions:
#             del self.sessions[session]
#         else:
#             assert False
# 
# Path: beeswarm/shared/misc/rfbes.py
# class RFBDes(pyDes.des):
#     def setKey(self, key):
#         """RFB protocol for authentication requires client to encrypt
#            challenge sent by server with password using DES method. However,
#            bits in each byte of the password are put in reverse order before
#            using it as encryption key."""
#         newkey = []
#         for ki in range(len(key)):
#             bsrc = ord(key[ki])
#             btgt = 0
#             for i in range(8):
#                 if bsrc & (1 << i):
#                     btgt = btgt | (1 << 7 - i)
#             newkey.append(chr(btgt))
#         super(RFBDes, self).setKey(newkey)


# Path: beeswarm/drones/client/baits/vnc.py
import logging
import socket
from beeswarm.drones.client.baits.clientbase import ClientBase
from beeswarm.shared.vnc_constants import *
from beeswarm.shared.misc.rfbes import RFBDes

        server_host = self.options['server']
        server_port = self.options['port']
        honeypot_id = self.options['honeypot_id']

        session = self.create_session(server_host, server_port, honeypot_id)
        self.sessions[session.id] = session

        logger.debug(
            'Sending {0} bait session to {1}:{2}. (bait id: {3})'.format('vnc', server_host, server_port, session.id))
        client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            client_socket.connect((server_host, int(server_port)))
            session.source_port = client_socket.getsockname()[1]

        except socket.error as e:
            logger.debug('Caught exception: {0} ({1})'.format(e, str(type(e))))
        else:
            session.did_connect = True
            protocol_version = client_socket.recv(1024)
            client_socket.send(RFB_VERSION)
            supported_auth_methods = client_socket.recv(1024)

            # \x02 implies that VNC authentication method is to be used
            # Refer to http://tools.ietf.org/html/rfc6143#section-7.1.2 for more info.
            if '\x02' in supported_auth_methods:
                client_socket.send(VNC_AUTH)
            challenge = client_socket.recv(1024)

            # password limit for vnc in 8 chars
            aligned_password = (password + '\0' * 8)[:8]

            des = RFBDes(aligned_password)