Ejemplo n.º 1
0
    def add_auth_attempt(self, _type, **kwargs):
        self.login_attempts += 1
        entry = {
            'timestamp': datetime.utcnow(),
            'session_id': self.id,
            'auth_id': uuid.uuid4(),
            'source_ip': self.source_ip,
            'source_port': self.source_port,
            'destination_ip': heralding.honeypot.Honeypot.public_ip,
            'destination_port': self.destination_port,
            'protocol': self.protocol,
            'username': None,
            'password': None
        }
        if 'username' in kwargs:
            entry['username'] = kwargs['username']
        if 'password' in kwargs:
            entry['password'] = kwargs['password']

        ReportingRelay.queueLogData(entry)
        self.activity()
        logger.debug(
            '{0} authentication attempt from {1}:{2}. Auth mechanism: {3}. '
            'Credentials: {4}'.format(self.protocol, self.source_ip,
                                      self.source_port, _type,
                                      json.dumps(kwargs)))
Ejemplo n.º 2
0
    def add_auth_attempt(self, _type, **kwargs):
        self.login_attempts += 1
        entry = {'timestamp': datetime.utcnow(),
                 'session_id': self.id,
                 'auth_id': uuid.uuid4(),
                 'source_ip': self.source_ip,
                 'souce_port': self.source_port,
                 'destination_port': self.destination_port,
                 'protocol': self.protocol,
                 'username': None,
                 'password': None
                 }
        if 'username' in kwargs:
            entry['username'] = kwargs['username']
        if 'password' in kwargs:
            entry['password'] = kwargs['password']

        ReportingRelay.queueLogData(entry)
        self.activity()
        logger.debug('{0} authentication attempt from {1}:{2}. Credentials: {3}'.format(self.protocol, self.source_ip,
                                                                                        self.source_port,
                                                                                        json.dumps(kwargs)))
Ejemplo n.º 3
0
class ZmqTests(unittest.TestCase):
    def setUp(self):
        self.test_running = True
        self.zmq_server_listning_event = gevent.event.Event()
        self.testing_queue = gevent.queue.Queue()
        self.reportingRelay = ReportingRelay()
        self.reportingRelay.start()

    def tearDown(self):
        self.test_running = False
        self.reportingRelay.stop()

    def test_connect(self):
        """Tests that we can connect and send data to a zmq puller"""

        # start dummy ZMQ pull server
        gevent.spawn(self._start_zmq_puller)
        self.zmq_server_listning_event.wait(5)

        # our local zmq logger
        zmq_url = 'tcp://localhost:{0}'.format(self.zmq_tcp_port)
        client_public_key = "N[DC7+%FKdW3pJUPnaCwWxt-0/jo5Lrq&U28-GG}"
        client_secret_key = "Gwt%C0a8J/:9Jy$qpDNTy8wRzlnRD-HT8H>u7F{B"
        server_public_key = "^4b:-bZ8seRC+m2p(sg{7{skOuK*jInNeH^/Le}Q"
        zmqLogger = ZmqLogger(zmq_url, client_public_key, client_secret_key, server_public_key)
        zmqLogger.start()

        # inject some data into the logging relay singleton
        self.reportingRelay.queueLogData({'somekey': 'somedata'})

        # wait until the zmq server put something into the local testing queue
        received_data = self.testing_queue.get(5)
        received_data = received_data.split(' ', 1)
        topic, message = received_data[0], jsonapi.loads(received_data[1])

        self.assertEqual(topic, ZmqMessageTypes.HERALDING_AUTH_LOG.value)
        self.assertIn('somekey', message)
        self.assertEqual(message['somekey'], 'somedata')

    def _start_zmq_puller(self):
        context = zmq.Context()

        # Authenticator runs in different greenlet.
        auth = GreenThreadAuthenticator(context)
        auth.start()
        auth.allow('127.0.0.1')
        auth.configure_curve(domain='*', location='heralding/tests/zmq_public_keys')

        # Bind our mock zmq pull server
        socket = context.socket(zmq.PULL)
        socket.curve_secretkey = "}vxNPm8lOJT1yvqu7-A<m<w>7OZ1ok<d?Qbq+a?5"
        socket.curve_server = True
        self.zmq_tcp_port = socket.bind_to_random_port('tcp://*', min_port=40000, max_port=50000, max_tries=10)

        # Poll and wait for data from test client
        poller = zmq.Poller()
        poller.register(socket, zmq.POLLIN)

        # Need to notify test client that the server is ready
        self.zmq_server_listning_event.set()

        while self.test_running:
            socks = dict(poller.poll())
            if socket in socks and socks[socket] == zmq.POLLIN:
                data = socket.recv()
                self.testing_queue.put(data)
        socket.close()
Ejemplo n.º 4
0
class ZmqTests(unittest.TestCase):
    def setUp(self):
        self.test_running = True
        self.zmq_server_listning_event = gevent.event.Event()
        self.testing_queue = gevent.queue.Queue()
        self.reportingRelay = ReportingRelay()
        self.reportingRelay.start()

    def tearDown(self):
        self.test_running = False
        self.reportingRelay.stop()

    def test_connect(self):
        """Tests that we can connect and send data to a zmq puller"""

        # start dummy ZMQ pull server
        gevent.spawn(self._start_zmq_puller)
        self.zmq_server_listning_event.wait(5)

        # our local zmq logger
        zmq_url = 'tcp://localhost:{0}'.format(self.zmq_tcp_port)
        client_public_key = "N[DC7+%FKdW3pJUPnaCwWxt-0/jo5Lrq&U28-GG}"
        client_secret_key = "Gwt%C0a8J/:9Jy$qpDNTy8wRzlnRD-HT8H>u7F{B"
        server_public_key = "^4b:-bZ8seRC+m2p(sg{7{skOuK*jInNeH^/Le}Q"
        zmqLogger = ZmqLogger(zmq_url, client_public_key, client_secret_key,
                              server_public_key)
        zmqLogger.start()

        # inject some data into the logging relay singleton
        self.reportingRelay.queueLogData({'somekey': 'somedata'})

        # wait until the zmq server put something into the local testing queue
        received_data = self.testing_queue.get(5)
        received_data = received_data.split(' ', 1)
        topic, message = received_data[0], jsonapi.loads(received_data[1])

        self.assertEqual(topic, ZmqMessageTypes.HERALDING_AUTH_LOG.value)
        self.assertIn('somekey', message)
        self.assertEqual(message['somekey'], 'somedata')

    def _start_zmq_puller(self):
        context = zmq.Context()

        # Authenticator runs in different greenlet.
        auth = GreenThreadAuthenticator(context)
        auth.start()
        auth.allow('127.0.0.1')
        auth.configure_curve(domain='*',
                             location='heralding/tests/zmq_public_keys')

        # Bind our mock zmq pull server
        socket = context.socket(zmq.PULL)
        socket.curve_secretkey = "}vxNPm8lOJT1yvqu7-A<m<w>7OZ1ok<d?Qbq+a?5"
        socket.curve_server = True
        self.zmq_tcp_port = socket.bind_to_random_port('tcp://*',
                                                       min_port=40000,
                                                       max_port=50000,
                                                       max_tries=10)

        # Poll and wait for data from test client
        poller = zmq.Poller()
        poller.register(socket, zmq.POLLIN)

        # Need to notify test client that the server is ready
        self.zmq_server_listning_event.set()

        while self.test_running:
            socks = dict(poller.poll())
            if socket in socks and socks[socket] == zmq.POLLIN:
                data = socket.recv()
                self.testing_queue.put(data)
        socket.close()