當前位置: 首頁>>代碼示例>>Python>>正文


Python GlastopfHoneypot.handle_request方法代碼示例

本文整理匯總了Python中glastopf.glastopf.GlastopfHoneypot.handle_request方法的典型用法代碼示例。如果您正苦於以下問題:Python GlastopfHoneypot.handle_request方法的具體用法?Python GlastopfHoneypot.handle_request怎麽用?Python GlastopfHoneypot.handle_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在glastopf.glastopf.GlastopfHoneypot的用法示例。


在下文中一共展示了GlastopfHoneypot.handle_request方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestHoneypotFunctionality

# 需要導入模塊: from glastopf.glastopf import GlastopfHoneypot [as 別名]
# 或者: from glastopf.glastopf.GlastopfHoneypot import handle_request [as 別名]
class TestHoneypotFunctionality(unittest.TestCase):
    """Tests the basic honeypot functionality
    Test set-up instantiates the honeypot.
    The main Test sends a request and checks the response."""

    def setUp(self):
        self.tmpdir = tempfile.mkdtemp()

    def tearDown(self):
        if os.path.isdir(self.tmpdir):
            shutil.rmtree(self.tmpdir)

    def test_honeypot_mongo(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."""

        conn_string = helpers.create_mongo_database(fill=True)
        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"]
            sensor_address = ["1.2.3.4", "8080"]
            GlastopfHoneypot.prepare_environment(self.tmpdir)
            self.glastopf = GlastopfHoneypot(work_dir=self.tmpdir, config=config_file)
            self.glastopf.options["enabled"] = "False"
            print "Sending request: http://localhost:8080/"

            response = self.glastopf.handle_request(raw_request, source_address, sensor_address)
            self.assertIsNot(response, None)
        finally:
            helpers.delete_mongo_testdata(conn_string)
            if os.path.isfile(config_file):
                os.remove(config_file)

    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"]
            sensor_address = ["1.2.3.4", "8080"]
            GlastopfHoneypot.prepare_environment(self.tmpdir)
            self.glastopf = GlastopfHoneypot(work_dir=self.tmpdir, config=config_file)
            self.glastopf.options["enabled"] = "False"
            print "Sending request: http://localhost:8080/"
            response = self.glastopf.handle_request(raw_request, source_address, sensor_address)
            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)
開發者ID:repson,項目名稱:glastopf,代碼行數:73,代碼來源:test_honeypot.py


注:本文中的glastopf.glastopf.GlastopfHoneypot.handle_request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。