示例#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)
示例#2
0
    def dork_generator_chain(self, dbtype, pages_dir):
        """
        Helper method to constructs chain of objects to satify dependencies for the dork_generator.
        Returns an instance of dork_page_generator.
        """

        if dbtype == "sql":
            engine = create_engine('sqlite:///')
            #Create mock of empty main db
            helpers.populate_main_sql_testdatabase(engine)
            db = database_sqla.Database(engine)
        elif dbtype == "mongodb":
            conn_string = helpers.create_mongo_database(fill=True)
            db = database_mongo.Database(create_mongo_database)
        else:
            raise Exception("Unsupported database type: {0}".format(dbtype))
        file_processor = DorkFileProcessor(db, dorks_file="testing/data/dorks_reduced.txt")

        #setting the bar low for testing
        clusterer = cluster.Cluster("/\w+", 1, 1, 1, min_df=0.0)
        dork_generator = DorkPageGenerator(db, file_processor, clusterer, pages_dir)
        return (db, engine, dork_generator)