Ejemplo n.º 1
0
    def test_honeypot_sql(self):
        """Objective: Testing overall Honeypot integration.
        Input: Loads the honeypot module with mongodb as main database.
        Expected Response: Honeypot responses with a non-empty HTTP response.
        Note: This test verifies the overall functionality."""

        db_file = tempfile.mkstemp()[1]
        conn_string = "sqlite:///{0}".format(db_file)
        sql_engine = create_engine(conn_string)
        helpers.populate_main_sql_testdatabase(sql_engine)

        config_file = tempfile.mkstemp()[1]

        with open(config_file, 'w') as f:
            f.writelines(helpers.gen_config(conn_string))

        try:
            raw_request = "GET /honeypot_test HTTP/1.1\r\nHost: honeypot\r\n\r\n"
            source_address = ["127.0.0.1", "12345"]
            self.glastopf = glastopf.GlastopfHoneypot(test=True, config=config_file)
            self.glastopf.options["enabled"] = "False"
            print "Sending request: http://localhost:8080/"
            connection = FakeCon()
            connection.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            response = self.glastopf.handle_request(raw_request,
                                                    source_address,
                                                    connection)
            connection.sock.close()
            self.assertIsNot(response, None)
        finally:
            if os.path.isfile(config_file):
                os.remove(config_file)
            if os.path.isfile(db_file):
                os.remove(db_file)
Ejemplo n.º 2
0
    def test_hpfeeds_event_with_file(self):
        """Objective: Testing if a event containing a file can be transmitted using hpfriends."""

        config_file = tempfile.mkstemp()[1]
        with open(config_file, 'w') as f:
            f.writelines(helpers.gen_config(''))

        #create dummy file
        file_name = 'dummy_file'
        with open(os.path.join(self.files_dir, file_name), 'w') as f:
            f.write('test_test_test_test_test')

        logger = HPFeedsLogger(self.tmpdir,
                               config=config_file,
                               reconnect=False)
        event = attack.AttackEvent()
        event.http_request = HTTPHandler('', None)
        event.raw_request = "GET /honeypot_test HTTP/1.1\r\nHost: honeypot\r\n\r\n"
        event.file_name = file_name
        logger.insert(event)
        gevent.sleep(2)
        # if None we did not connect
        self.assertIsNotNone(logger.hpc.wait)
        error_message = logger.hpc.wait(2)
        self.assertIsNone(error_message)
Ejemplo n.º 3
0
    def test_hpfeeds_event(self):
        """Objective: Testing if a basic event can be transmitted using hpfriends."""

        config_file = tempfile.mkstemp()[1]
        with open(config_file, "w") as f:
            f.writelines(helpers.gen_config(""))

        logger = HPFeedsLogger(self.tmpdir, config=config_file, reconnect=False)
        event = attack.AttackEvent()
        event.http_request = HTTPHandler("", None)
        event.raw_request = "GET /honeypot_test HTTP/1.1\r\nHost: honeypot\r\n\r\n"
        logger.insert(event)
        error_message = logger.hpc.wait(2)
        self.assertIsNone(error_message)
Ejemplo n.º 4
0
    def test_hpfeeds_event(self):
        """Objective: Testing if a basic event can be transmitted using hpfriends."""

        config_file = tempfile.mkstemp()[1]
        with open(config_file, 'w') as f:
            f.writelines(helpers.gen_config(''))

        logger = HPFeedsLogger(self.tmpdir, os.getcwd(), config=config_file, reconnect=False)
        event = attack.AttackEvent()
        event.http_request = HTTPHandler('', None)
        event.raw_request = "GET /honeypot_test HTTP/1.1\r\nHost: honeypot\r\n\r\n"
        logger.insert(event)
        gevent.sleep(2)
        # if None we did not connect
        self.assertIsNotNone(logger.hpc.wait)
        error_message = logger.hpc.wait(2)
        self.assertIsNone(error_message)
Ejemplo n.º 5
0
    def test_hpfeeds_event_with_file(self):
        """Objective: Testing if a event containing a file can be transmitted using hpfriends."""

        config_file = tempfile.mkstemp()[1]
        with open(config_file, "w") as f:
            f.writelines(helpers.gen_config(""))

        # create dummy file
        file_name = "dummy_file"
        with open(os.path.join(self.files_dir, file_name), "w") as f:
            print self.files_dir
            f.write("test_test_test_test_test")

        logger = HPFeedsLogger(self.tmpdir, config=config_file, reconnect=False)
        event = attack.AttackEvent()
        event.http_request = HTTPHandler("", None)
        event.raw_request = "GET /honeypot_test HTTP/1.1\r\nHost: honeypot\r\n\r\n"
        event.file_name = file_name
        logger.insert(event)
        error_message = logger.hpc.wait(2)
        self.assertIsNone(error_message)
Ejemplo n.º 6
0
    def test_hpfeeds_event_with_file(self):
        """Objective: Testing if a event containing a file can be transmitted using hpfriends."""

        config_file = tempfile.mkstemp()[1]
        with open(config_file, 'w') as f:
            f.writelines(helpers.gen_config(''))

        #create dummy file
        file_name = 'dummy_file'
        with open(os.path.join(self.files_dir, file_name), 'w') as f:
            f.write('test_test_test_test_test')

        logger = HPFeedsLogger(self.tmpdir, os.getcwd(), config_file, reconnect=False)
        event = attack.AttackEvent()
        event.http_request = HTTPHandler('', None)
        event.raw_request = "GET /honeypot_test HTTP/1.1\r\nHost: honeypot\r\n\r\n"
        event.file_name = file_name
        logger.insert(event)
        gevent.sleep(2)
        # if None we did not connect
        self.assertIsNotNone(logger.hpc.wait)
        error_message = logger.hpc.wait(2)
        self.assertIsNone(error_message)