From 69e3bed5c4918ba1bdac9900d9159de0b52d9d0f Mon Sep 17 00:00:00 2001 From: Vince Rose Date: Wed, 27 Sep 2023 23:08:10 -0700 Subject: [PATCH] move string functions --- empire/server/api/v2/download/download_dto.py | 2 +- .../python/persistence/multi/desktopfile.py | 2 +- .../python/persistence/osx/CreateHijacker.py | 2 +- .../modules/python/persistence/osx/LaunchAgent.py | 2 +- .../osx/LaunchAgentUserLandPersistence.py | 2 +- empire/server/stagers/osx/application.py | 2 +- empire/server/stagers/osx/dylib.py | 2 +- empire/server/stagers/osx/pkg.py | 2 +- empire/server/utils/__init__.py | 0 empire/server/utils/data_util.py | 14 -------------- empire/server/utils/string_util.py | 12 ++++++++++++ .../{test_data_util.py => test_string_util.py} | 2 +- 12 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 empire/server/utils/__init__.py create mode 100644 empire/server/utils/string_util.py rename empire/test/{test_data_util.py => test_string_util.py} (87%) diff --git a/empire/server/api/v2/download/download_dto.py b/empire/server/api/v2/download/download_dto.py index ff79a0b2a..ad2156156 100644 --- a/empire/server/api/v2/download/download_dto.py +++ b/empire/server/api/v2/download/download_dto.py @@ -5,7 +5,7 @@ from pydantic import BaseModel from empire.server.api.v2.tag.tag_dto import Tag, domain_to_dto_tag -from empire.server.utils.data_util import removeprefix +from empire.server.utils.string_util import removeprefix def domain_to_dto_download(download): diff --git a/empire/server/modules/python/persistence/multi/desktopfile.py b/empire/server/modules/python/persistence/multi/desktopfile.py index 32befd44b..f8d2c7b15 100644 --- a/empire/server/modules/python/persistence/multi/desktopfile.py +++ b/empire/server/modules/python/persistence/multi/desktopfile.py @@ -1,7 +1,7 @@ from typing import Dict from empire.server.core.module_models import EmpireModule -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix class Module: diff --git a/empire/server/modules/python/persistence/osx/CreateHijacker.py b/empire/server/modules/python/persistence/osx/CreateHijacker.py index 27c572503..b099c273b 100644 --- a/empire/server/modules/python/persistence/osx/CreateHijacker.py +++ b/empire/server/modules/python/persistence/osx/CreateHijacker.py @@ -2,7 +2,7 @@ from typing import Dict, Optional, Tuple from empire.server.core.module_models import EmpireModule -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix class Module: diff --git a/empire/server/modules/python/persistence/osx/LaunchAgent.py b/empire/server/modules/python/persistence/osx/LaunchAgent.py index 4363320c4..5dceb51eb 100644 --- a/empire/server/modules/python/persistence/osx/LaunchAgent.py +++ b/empire/server/modules/python/persistence/osx/LaunchAgent.py @@ -2,7 +2,7 @@ from typing import Dict, Optional, Tuple from empire.server.core.module_models import EmpireModule -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix class Module: diff --git a/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py b/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py index 876eff3ea..ebee9c1ca 100644 --- a/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py +++ b/empire/server/modules/python/persistence/osx/LaunchAgentUserLandPersistence.py @@ -1,7 +1,7 @@ from typing import Dict, Optional, Tuple from empire.server.core.module_models import EmpireModule -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix class Module: diff --git a/empire/server/stagers/osx/application.py b/empire/server/stagers/osx/application.py index 4b76b36d7..b722f9e41 100644 --- a/empire/server/stagers/osx/application.py +++ b/empire/server/stagers/osx/application.py @@ -1,6 +1,6 @@ import logging -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix log = logging.getLogger(__name__) diff --git a/empire/server/stagers/osx/dylib.py b/empire/server/stagers/osx/dylib.py index aa66d984f..50fa8110b 100644 --- a/empire/server/stagers/osx/dylib.py +++ b/empire/server/stagers/osx/dylib.py @@ -1,5 +1,5 @@ from empire.server.common import helpers -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix class Stager: diff --git a/empire/server/stagers/osx/pkg.py b/empire/server/stagers/osx/pkg.py index 71d092c22..05ff5d5ec 100644 --- a/empire/server/stagers/osx/pkg.py +++ b/empire/server/stagers/osx/pkg.py @@ -1,5 +1,5 @@ from empire.server.common import helpers -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix class Stager: diff --git a/empire/server/utils/__init__.py b/empire/server/utils/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/empire/server/utils/data_util.py b/empire/server/utils/data_util.py index be695163e..0e7ecfbf7 100644 --- a/empire/server/utils/data_util.py +++ b/empire/server/utils/data_util.py @@ -86,17 +86,3 @@ def ps_convert_to_oneliner(psscript): def is_port_in_use(port: int) -> bool: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: return s.connect_ex(("localhost", port)) == 0 - - -def removeprefix(s, prefix): - # Remove when we drop Python 3.8 support - if s.startswith(prefix): - return s[len(prefix) :] - return s - - -def removesuffix(s, suffix): - # Remove when we drop Python 3.8 support - if s.endswith(suffix): - return s[: -len(suffix)] - return s diff --git a/empire/server/utils/string_util.py b/empire/server/utils/string_util.py new file mode 100644 index 000000000..33ca3b692 --- /dev/null +++ b/empire/server/utils/string_util.py @@ -0,0 +1,12 @@ +def removeprefix(s, prefix): + # Remove when we drop Python 3.8 support + if s.startswith(prefix): + return s[len(prefix) :] + return s + + +def removesuffix(s, suffix): + # Remove when we drop Python 3.8 support + if s.endswith(suffix): + return s[: -len(suffix)] + return s diff --git a/empire/test/test_data_util.py b/empire/test/test_string_util.py similarity index 87% rename from empire/test/test_data_util.py rename to empire/test/test_string_util.py index 3ea387370..18ef59649 100644 --- a/empire/test/test_data_util.py +++ b/empire/test/test_string_util.py @@ -1,4 +1,4 @@ -from empire.server.utils.data_util import removeprefix, removesuffix +from empire.server.utils.string_util import removeprefix, removesuffix def test_remove_prefix():