From e1f9e6fce8e27ff753fb526af89c82b8182e2e4d Mon Sep 17 00:00:00 2001 From: Antoine SANSON Date: Wed, 12 Apr 2023 18:55:56 +0200 Subject: [PATCH 1/9] Can now try several encodings when decoding --- pymetasploit3/msfrpc.py | 6 ++++-- pymetasploit3/utils.py | 42 +++++++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/pymetasploit3/msfrpc.py b/pymetasploit3/msfrpc.py index f0e33a2..e0cb2d9 100755 --- a/pymetasploit3/msfrpc.py +++ b/pymetasploit3/msfrpc.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +from typing import List + from numbers import Number from pymetasploit3.utils import * import requests @@ -194,7 +196,7 @@ def __init__(self, password, **kwargs): self.host = kwargs.get('server', '127.0.0.1') self.ssl = kwargs.get('ssl', False) self.token = kwargs.get('token') - self.encoding = kwargs.get('encoding', 'utf-8') + self.encodings: List[str] = kwargs.get('encodings', ['utf-8']) self.headers = {"Content-type": "binary/message-pack"} if self.token is None: self.login(kwargs.get('username', 'msf'), password) @@ -224,7 +226,7 @@ def call(self, method, opts=None, is_raw=False): if is_raw: return r.content - return convert(decode(r.content), self.encoding) # convert all keys/vals to utf8 + return convert(decode(r.content), self.encodings) # convert all keys/vals to utf8 @retry(tries=3, delay=1, backoff=2) def post_request(self, url, payload): diff --git a/pymetasploit3/utils.py b/pymetasploit3/utils.py index a0363b6..7721c9e 100755 --- a/pymetasploit3/utils.py +++ b/pymetasploit3/utils.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +from typing import List, Tuple + from optparse import OptionParser import msgpack @@ -25,15 +27,43 @@ def parseargs(): exit(-1) return o -def convert(data, encoding="utf-8"): + +def try_convert(data: bytes, encodings: List[str]) -> Tuple[str, str]: + """Tries to decode the data with all the specified encodings, the order is perserved. + + Parameters + ---------- + data : bytes + encodings : List[str] + + Returns + ------- + Tuple[str, str] + The actual decoded data + The encoding used to decode the data + """ + + default_encoding: str = encodings[-1] + # Loop over all the encodings but the last one, which is the default one + for encoding in encodings[:-1]: + try: + decoded: str = data.decode(encoding=encoding) + return decoded, encoding + except Exception: + pass + + # If we haven't returned, try with the last one (default) and don't catch the exception + return data.decode(encoding=default_encoding), default_encoding + +def convert(data, encodings: List[str]): """ Converts all bytestrings to utf8 """ - if isinstance(data, bytes): return data.decode(encoding=encoding) - if isinstance(data, list): return list(map(lambda iter: convert(iter, encoding=encoding), data)) - if isinstance(data, set): return set(map(lambda iter: convert(iter, encoding=encoding), data)) - if isinstance(data, dict): return dict(map(lambda iter: convert(iter, encoding=encoding), data.items())) - if isinstance(data, tuple): return map(lambda iter: convert(iter, encoding=encoding), data) + if isinstance(data, bytes): return try_convert(data, encodings=encodings)[0] + if isinstance(data, list): return list(map(lambda iter: convert(iter, encodings=encodings), data)) + if isinstance(data, set): return set(map(lambda iter: convert(iter, encodings=encodings), data)) + if isinstance(data, dict): return dict(map(lambda iter: convert(iter, encodings=encodings), data.items())) + if isinstance(data, tuple): return map(lambda iter: convert(iter, encodings=encodings), data) return data def encode(data): From 78dce9a43a3f73be07bc46d27b96961b4fa260d7 Mon Sep 17 00:00:00 2001 From: Antoine SANSON Date: Mon, 17 Apr 2023 10:34:57 +0200 Subject: [PATCH 2/9] new name : knock-pymetasploit3 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f0a8453..0a41090 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read(fname): setup( - name='pymetasploit3', + name='knock-pymetasploit3', author='Dan McInerney', version='1.0', author_email='danhmcinerney@gmail.com', From cbefc05f2d8615ca1ea4eaafce97e08455583aff Mon Sep 17 00:00:00 2001 From: Antoine SANSON Date: Mon, 17 Apr 2023 13:56:39 +0200 Subject: [PATCH 3/9] Rename module to knockpymetasploit3 --- example_usage.py | 2 +- {pymetasploit3 => knockpymetasploit3}/__init__.py | 0 {pymetasploit3 => knockpymetasploit3}/msfconsole.py | 2 +- {pymetasploit3 => knockpymetasploit3}/msfrpc.py | 2 +- .../scripts/pymsfconsole.py | 6 +++--- {pymetasploit3 => knockpymetasploit3}/scripts/pymsfrpc.py | 4 ++-- {pymetasploit3 => knockpymetasploit3}/utils.py | 0 setup.py | 4 ++-- tests/test_console.py | 2 +- tests/test_db.py | 2 +- tests/test_modulemanager.py | 2 +- tests/test_msfrpc.py | 2 +- tests/test_sessions.py | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) rename {pymetasploit3 => knockpymetasploit3}/__init__.py (100%) rename {pymetasploit3 => knockpymetasploit3}/msfconsole.py (97%) rename {pymetasploit3 => knockpymetasploit3}/msfrpc.py (99%) rename {pymetasploit3 => knockpymetasploit3}/scripts/pymsfconsole.py (90%) rename {pymetasploit3 => knockpymetasploit3}/scripts/pymsfrpc.py (90%) rename {pymetasploit3 => knockpymetasploit3}/utils.py (100%) diff --git a/example_usage.py b/example_usage.py index 5eaafca..59c88ff 100755 --- a/example_usage.py +++ b/example_usage.py @@ -1,4 +1,4 @@ -from pymetasploit3.msfrpc import MsfRpcClient +from knockpymetasploit3.msfrpc import MsfRpcClient ## Usage example diff --git a/pymetasploit3/__init__.py b/knockpymetasploit3/__init__.py similarity index 100% rename from pymetasploit3/__init__.py rename to knockpymetasploit3/__init__.py diff --git a/pymetasploit3/msfconsole.py b/knockpymetasploit3/msfconsole.py similarity index 97% rename from pymetasploit3/msfconsole.py rename to knockpymetasploit3/msfconsole.py index 1619c6a..8fb0b35 100755 --- a/pymetasploit3/msfconsole.py +++ b/knockpymetasploit3/msfconsole.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from threading import Timer, Lock -from pymetasploit3.msfrpc import ShellSession +from knockpymetasploit3.msfrpc import ShellSession class MsfRpcConsoleType: diff --git a/pymetasploit3/msfrpc.py b/knockpymetasploit3/msfrpc.py similarity index 99% rename from pymetasploit3/msfrpc.py rename to knockpymetasploit3/msfrpc.py index e0cb2d9..4a660fd 100755 --- a/pymetasploit3/msfrpc.py +++ b/knockpymetasploit3/msfrpc.py @@ -3,7 +3,7 @@ from typing import List from numbers import Number -from pymetasploit3.utils import * +from knockpymetasploit3.utils import * import requests import uuid import time diff --git a/pymetasploit3/scripts/pymsfconsole.py b/knockpymetasploit3/scripts/pymsfconsole.py similarity index 90% rename from pymetasploit3/scripts/pymsfconsole.py rename to knockpymetasploit3/scripts/pymsfconsole.py index ef3e4d4..4fbc79b 100755 --- a/pymetasploit3/scripts/pymsfconsole.py +++ b/knockpymetasploit3/scripts/pymsfconsole.py @@ -6,9 +6,9 @@ from os import path import readline -from pymetasploit3.msfrpc import MsfRpcClient, MsfRpcError -from pymetasploit3.msfconsole import MsfRpcConsole -from pymetasploit3.utils import parseargs +from knockpymetasploit3.msfrpc import MsfRpcClient, MsfRpcError +from knockpymetasploit3.msfconsole import MsfRpcConsole +from knockpymetasploit3.utils import parseargs class MsfConsole(InteractiveConsole): diff --git a/pymetasploit3/scripts/pymsfrpc.py b/knockpymetasploit3/scripts/pymsfrpc.py similarity index 90% rename from pymetasploit3/scripts/pymsfrpc.py rename to knockpymetasploit3/scripts/pymsfrpc.py index c914e05..6f7e1ab 100755 --- a/pymetasploit3/scripts/pymsfrpc.py +++ b/knockpymetasploit3/scripts/pymsfrpc.py @@ -5,8 +5,8 @@ from os import path import readline -from pymetasploit3.msfrpc import MsfRpcClient, MsfRpcError -from pymetasploit3.utils import parseargs +from knockpymetasploit3.msfrpc import MsfRpcClient, MsfRpcError +from knockpymetasploit3.utils import parseargs class MsfRpc(InteractiveConsole): diff --git a/pymetasploit3/utils.py b/knockpymetasploit3/utils.py similarity index 100% rename from pymetasploit3/utils.py rename to knockpymetasploit3/utils.py diff --git a/setup.py b/setup.py index 0a41090..09c902e 100644 --- a/setup.py +++ b/setup.py @@ -17,8 +17,8 @@ def read(fname): license='GPL', packages=find_packages(exclude='tests'), scripts=[ - 'pymetasploit3/scripts/pymsfconsole.py', - 'pymetasploit3/scripts/pymsfrpc.py' + 'knockpymetasploit3/scripts/pymsfconsole.py', + 'knockpymetasploit3/scripts/pymsfrpc.py' ], install_requires=[ 'msgpack', diff --git a/tests/test_console.py b/tests/test_console.py index 6e8413f..e8d3133 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -1,7 +1,7 @@ import pytest import time -from pymetasploit3.msfrpc import * +from knockpymetasploit3.msfrpc import * @pytest.fixture() def client(): diff --git a/tests/test_db.py b/tests/test_db.py index 941655d..1c73bb8 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -2,7 +2,7 @@ import pytest import os -from pymetasploit3.msfrpc import * +from knockpymetasploit3.msfrpc import * @pytest.fixture() diff --git a/tests/test_modulemanager.py b/tests/test_modulemanager.py index 81d8e01..378c11d 100644 --- a/tests/test_modulemanager.py +++ b/tests/test_modulemanager.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import pytest -from pymetasploit3.msfrpc import * +from knockpymetasploit3.msfrpc import * @pytest.fixture() diff --git a/tests/test_msfrpc.py b/tests/test_msfrpc.py index 6b7d798..d3be26f 100644 --- a/tests/test_msfrpc.py +++ b/tests/test_msfrpc.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import pytest -from pymetasploit3.msfrpc import * +from knockpymetasploit3.msfrpc import * @pytest.fixture() diff --git a/tests/test_sessions.py b/tests/test_sessions.py index d15a88d..970a140 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -3,7 +3,7 @@ import pytest import time import os -from pymetasploit3.msfrpc import * +from knockpymetasploit3.msfrpc import * @pytest.fixture() From 16672123ae4491b19025946bad93427bbe53333e Mon Sep 17 00:00:00 2001 From: Antoine SANSON Date: Thu, 11 May 2023 10:41:58 +0200 Subject: [PATCH 4/9] Add decode_error_handling support --- knockpymetasploit3/msfrpc.py | 3 ++- knockpymetasploit3/utils.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/knockpymetasploit3/msfrpc.py b/knockpymetasploit3/msfrpc.py index 4a660fd..9c7248b 100755 --- a/knockpymetasploit3/msfrpc.py +++ b/knockpymetasploit3/msfrpc.py @@ -197,6 +197,7 @@ def __init__(self, password, **kwargs): self.ssl = kwargs.get('ssl', False) self.token = kwargs.get('token') self.encodings: List[str] = kwargs.get('encodings', ['utf-8']) + self.decode_error_handling: str = kwargs.get('decode_error_handling', 'strict') self.headers = {"Content-type": "binary/message-pack"} if self.token is None: self.login(kwargs.get('username', 'msf'), password) @@ -226,7 +227,7 @@ def call(self, method, opts=None, is_raw=False): if is_raw: return r.content - return convert(decode(r.content), self.encodings) # convert all keys/vals to utf8 + return convert(decode(r.content), self.encodings, self.decode_error_handling) # convert all keys/vals to utf8 @retry(tries=3, delay=1, backoff=2) def post_request(self, url, payload): diff --git a/knockpymetasploit3/utils.py b/knockpymetasploit3/utils.py index 7721c9e..821074c 100755 --- a/knockpymetasploit3/utils.py +++ b/knockpymetasploit3/utils.py @@ -28,7 +28,7 @@ def parseargs(): return o -def try_convert(data: bytes, encodings: List[str]) -> Tuple[str, str]: +def try_convert(data: bytes, encodings: List[str], decode_error_handling: str) -> Tuple[str, str]: """Tries to decode the data with all the specified encodings, the order is perserved. Parameters @@ -47,7 +47,7 @@ def try_convert(data: bytes, encodings: List[str]) -> Tuple[str, str]: # Loop over all the encodings but the last one, which is the default one for encoding in encodings[:-1]: try: - decoded: str = data.decode(encoding=encoding) + decoded: str = data.decode(encoding=encoding, errors=decode_error_handling) return decoded, encoding except Exception: pass @@ -55,15 +55,15 @@ def try_convert(data: bytes, encodings: List[str]) -> Tuple[str, str]: # If we haven't returned, try with the last one (default) and don't catch the exception return data.decode(encoding=default_encoding), default_encoding -def convert(data, encodings: List[str]): +def convert(data, encodings: List[str], decode_error_handling: str): """ Converts all bytestrings to utf8 """ - if isinstance(data, bytes): return try_convert(data, encodings=encodings)[0] - if isinstance(data, list): return list(map(lambda iter: convert(iter, encodings=encodings), data)) - if isinstance(data, set): return set(map(lambda iter: convert(iter, encodings=encodings), data)) - if isinstance(data, dict): return dict(map(lambda iter: convert(iter, encodings=encodings), data.items())) - if isinstance(data, tuple): return map(lambda iter: convert(iter, encodings=encodings), data) + if isinstance(data, bytes): return try_convert(data, encodings=encodings, decode_error_handling=decode_error_handling)[0] + if isinstance(data, list): return list(map(lambda iter: convert(iter, encodings=encodings, decode_error_handling=decode_error_handling), data)) + if isinstance(data, set): return set(map(lambda iter: convert(iter, encodings=encodings, decode_error_handling=decode_error_handling), data)) + if isinstance(data, dict): return dict(map(lambda iter: convert(iter, encodings=encodings, decode_error_handling=decode_error_handling), data.items())) + if isinstance(data, tuple): return map(lambda iter: convert(iter, encodings=encodings, decode_error_handling=decode_error_handling), data) return data def encode(data): From 82a70b5569cb0a8d99fd99f1cdae73da22b8287a Mon Sep 17 00:00:00 2001 From: Antoine SANSON Date: Thu, 11 May 2023 10:56:35 +0200 Subject: [PATCH 5/9] Fix decoding bug --- knockpymetasploit3/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/knockpymetasploit3/utils.py b/knockpymetasploit3/utils.py index 821074c..fe4eb16 100755 --- a/knockpymetasploit3/utils.py +++ b/knockpymetasploit3/utils.py @@ -47,13 +47,15 @@ def try_convert(data: bytes, encodings: List[str], decode_error_handling: str) - # Loop over all the encodings but the last one, which is the default one for encoding in encodings[:-1]: try: - decoded: str = data.decode(encoding=encoding, errors=decode_error_handling) + # We want it to be strict because we need to find the proper encoding + decoded: str = data.decode(encoding=encoding, errors="strict") return decoded, encoding except Exception: pass # If we haven't returned, try with the last one (default) and don't catch the exception - return data.decode(encoding=default_encoding), default_encoding + # Here and only here we use the parameter decode_error_handling which is controlled by the user of the library + return data.decode(encoding=default_encoding, errors=decode_error_handling), default_encoding def convert(data, encodings: List[str], decode_error_handling: str): """ From a657abc8332f2e364be09b066daf0bdb5a1b196b Mon Sep 17 00:00:00 2001 From: Antoine Sanson Date: Tue, 27 Feb 2024 15:37:30 +0100 Subject: [PATCH 6/9] Rename knockpymetasploit3 to pymetasploit3 --- {knockpymetasploit3 => pymetasploit3}/__init__.py | 0 {knockpymetasploit3 => pymetasploit3}/msfconsole.py | 0 {knockpymetasploit3 => pymetasploit3}/msfrpc.py | 0 {knockpymetasploit3 => pymetasploit3}/scripts/pymsfconsole.py | 0 {knockpymetasploit3 => pymetasploit3}/scripts/pymsfrpc.py | 0 {knockpymetasploit3 => pymetasploit3}/utils.py | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {knockpymetasploit3 => pymetasploit3}/__init__.py (100%) rename {knockpymetasploit3 => pymetasploit3}/msfconsole.py (100%) rename {knockpymetasploit3 => pymetasploit3}/msfrpc.py (100%) rename {knockpymetasploit3 => pymetasploit3}/scripts/pymsfconsole.py (100%) rename {knockpymetasploit3 => pymetasploit3}/scripts/pymsfrpc.py (100%) rename {knockpymetasploit3 => pymetasploit3}/utils.py (100%) diff --git a/knockpymetasploit3/__init__.py b/pymetasploit3/__init__.py similarity index 100% rename from knockpymetasploit3/__init__.py rename to pymetasploit3/__init__.py diff --git a/knockpymetasploit3/msfconsole.py b/pymetasploit3/msfconsole.py similarity index 100% rename from knockpymetasploit3/msfconsole.py rename to pymetasploit3/msfconsole.py diff --git a/knockpymetasploit3/msfrpc.py b/pymetasploit3/msfrpc.py similarity index 100% rename from knockpymetasploit3/msfrpc.py rename to pymetasploit3/msfrpc.py diff --git a/knockpymetasploit3/scripts/pymsfconsole.py b/pymetasploit3/scripts/pymsfconsole.py similarity index 100% rename from knockpymetasploit3/scripts/pymsfconsole.py rename to pymetasploit3/scripts/pymsfconsole.py diff --git a/knockpymetasploit3/scripts/pymsfrpc.py b/pymetasploit3/scripts/pymsfrpc.py similarity index 100% rename from knockpymetasploit3/scripts/pymsfrpc.py rename to pymetasploit3/scripts/pymsfrpc.py diff --git a/knockpymetasploit3/utils.py b/pymetasploit3/utils.py similarity index 100% rename from knockpymetasploit3/utils.py rename to pymetasploit3/utils.py From 3bb83510a93749b66e697825d9890d69e996cc40 Mon Sep 17 00:00:00 2001 From: Antoine Sanson Date: Tue, 27 Feb 2024 15:38:19 +0100 Subject: [PATCH 7/9] Rename knockpymetasploit3 to pymetasploit3 --- example_usage.py | 2 +- pymetasploit3/msfconsole.py | 2 +- pymetasploit3/msfrpc.py | 2 +- pymetasploit3/scripts/pymsfconsole.py | 6 +++--- pymetasploit3/scripts/pymsfrpc.py | 4 ++-- setup.py | 4 ++-- tests/test_console.py | 2 +- tests/test_db.py | 2 +- tests/test_modulemanager.py | 2 +- tests/test_msfrpc.py | 2 +- tests/test_sessions.py | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/example_usage.py b/example_usage.py index 59c88ff..5eaafca 100755 --- a/example_usage.py +++ b/example_usage.py @@ -1,4 +1,4 @@ -from knockpymetasploit3.msfrpc import MsfRpcClient +from pymetasploit3.msfrpc import MsfRpcClient ## Usage example diff --git a/pymetasploit3/msfconsole.py b/pymetasploit3/msfconsole.py index 8fb0b35..1619c6a 100755 --- a/pymetasploit3/msfconsole.py +++ b/pymetasploit3/msfconsole.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from threading import Timer, Lock -from knockpymetasploit3.msfrpc import ShellSession +from pymetasploit3.msfrpc import ShellSession class MsfRpcConsoleType: diff --git a/pymetasploit3/msfrpc.py b/pymetasploit3/msfrpc.py index 9c7248b..fc3b079 100755 --- a/pymetasploit3/msfrpc.py +++ b/pymetasploit3/msfrpc.py @@ -3,7 +3,7 @@ from typing import List from numbers import Number -from knockpymetasploit3.utils import * +from pymetasploit3.utils import * import requests import uuid import time diff --git a/pymetasploit3/scripts/pymsfconsole.py b/pymetasploit3/scripts/pymsfconsole.py index 4fbc79b..ef3e4d4 100755 --- a/pymetasploit3/scripts/pymsfconsole.py +++ b/pymetasploit3/scripts/pymsfconsole.py @@ -6,9 +6,9 @@ from os import path import readline -from knockpymetasploit3.msfrpc import MsfRpcClient, MsfRpcError -from knockpymetasploit3.msfconsole import MsfRpcConsole -from knockpymetasploit3.utils import parseargs +from pymetasploit3.msfrpc import MsfRpcClient, MsfRpcError +from pymetasploit3.msfconsole import MsfRpcConsole +from pymetasploit3.utils import parseargs class MsfConsole(InteractiveConsole): diff --git a/pymetasploit3/scripts/pymsfrpc.py b/pymetasploit3/scripts/pymsfrpc.py index 6f7e1ab..c914e05 100755 --- a/pymetasploit3/scripts/pymsfrpc.py +++ b/pymetasploit3/scripts/pymsfrpc.py @@ -5,8 +5,8 @@ from os import path import readline -from knockpymetasploit3.msfrpc import MsfRpcClient, MsfRpcError -from knockpymetasploit3.utils import parseargs +from pymetasploit3.msfrpc import MsfRpcClient, MsfRpcError +from pymetasploit3.utils import parseargs class MsfRpc(InteractiveConsole): diff --git a/setup.py b/setup.py index 09c902e..0a41090 100644 --- a/setup.py +++ b/setup.py @@ -17,8 +17,8 @@ def read(fname): license='GPL', packages=find_packages(exclude='tests'), scripts=[ - 'knockpymetasploit3/scripts/pymsfconsole.py', - 'knockpymetasploit3/scripts/pymsfrpc.py' + 'pymetasploit3/scripts/pymsfconsole.py', + 'pymetasploit3/scripts/pymsfrpc.py' ], install_requires=[ 'msgpack', diff --git a/tests/test_console.py b/tests/test_console.py index e8d3133..6e8413f 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -1,7 +1,7 @@ import pytest import time -from knockpymetasploit3.msfrpc import * +from pymetasploit3.msfrpc import * @pytest.fixture() def client(): diff --git a/tests/test_db.py b/tests/test_db.py index 1c73bb8..941655d 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -2,7 +2,7 @@ import pytest import os -from knockpymetasploit3.msfrpc import * +from pymetasploit3.msfrpc import * @pytest.fixture() diff --git a/tests/test_modulemanager.py b/tests/test_modulemanager.py index 378c11d..81d8e01 100644 --- a/tests/test_modulemanager.py +++ b/tests/test_modulemanager.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import pytest -from knockpymetasploit3.msfrpc import * +from pymetasploit3.msfrpc import * @pytest.fixture() diff --git a/tests/test_msfrpc.py b/tests/test_msfrpc.py index d3be26f..6b7d798 100644 --- a/tests/test_msfrpc.py +++ b/tests/test_msfrpc.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import pytest -from knockpymetasploit3.msfrpc import * +from pymetasploit3.msfrpc import * @pytest.fixture() diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 970a140..d15a88d 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -3,7 +3,7 @@ import pytest import time import os -from knockpymetasploit3.msfrpc import * +from pymetasploit3.msfrpc import * @pytest.fixture() From eaba0ed877095d44ea3551c3df371eed87b9f3e9 Mon Sep 17 00:00:00 2001 From: Antoine Sanson Date: Tue, 27 Feb 2024 15:42:15 +0100 Subject: [PATCH 8/9] Remove type annotations --- pymetasploit3/msfrpc.py | 4 +--- pymetasploit3/utils.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pymetasploit3/msfrpc.py b/pymetasploit3/msfrpc.py index fc3b079..74822fc 100755 --- a/pymetasploit3/msfrpc.py +++ b/pymetasploit3/msfrpc.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from typing import List - from numbers import Number from pymetasploit3.utils import * import requests @@ -196,7 +194,7 @@ def __init__(self, password, **kwargs): self.host = kwargs.get('server', '127.0.0.1') self.ssl = kwargs.get('ssl', False) self.token = kwargs.get('token') - self.encodings: List[str] = kwargs.get('encodings', ['utf-8']) + self.encodings = kwargs.get('encodings', ['utf-8']) self.decode_error_handling: str = kwargs.get('decode_error_handling', 'strict') self.headers = {"Content-type": "binary/message-pack"} if self.token is None: diff --git a/pymetasploit3/utils.py b/pymetasploit3/utils.py index fe4eb16..b9f45a9 100755 --- a/pymetasploit3/utils.py +++ b/pymetasploit3/utils.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from typing import List, Tuple - from optparse import OptionParser import msgpack @@ -28,13 +26,14 @@ def parseargs(): return o -def try_convert(data: bytes, encodings: List[str], decode_error_handling: str) -> Tuple[str, str]: +def try_convert(data, encodings, decode_error_handling): """Tries to decode the data with all the specified encodings, the order is perserved. Parameters ---------- data : bytes encodings : List[str] + decode_error_handling: str Returns ------- @@ -57,9 +56,18 @@ def try_convert(data: bytes, encodings: List[str], decode_error_handling: str) - # Here and only here we use the parameter decode_error_handling which is controlled by the user of the library return data.decode(encoding=default_encoding, errors=decode_error_handling), default_encoding -def convert(data, encodings: List[str], decode_error_handling: str): - """ - Converts all bytestrings to utf8 +def convert(data, encodings, decode_error_handling): + """Converts all bytestrings to utf8 + + Parameters + ---------- + data : Any + encodings : List[str] + decode_error_handling : str + + Returns + ------- + Any """ if isinstance(data, bytes): return try_convert(data, encodings=encodings, decode_error_handling=decode_error_handling)[0] if isinstance(data, list): return list(map(lambda iter: convert(iter, encodings=encodings, decode_error_handling=decode_error_handling), data)) From e991ce7275f46e571d55a8e94b929b405bfd6ebb Mon Sep 17 00:00:00 2001 From: Antoine Sanson Date: Tue, 27 Feb 2024 15:42:59 +0100 Subject: [PATCH 9/9] Oups --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0a41090..f0a8453 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read(fname): setup( - name='knock-pymetasploit3', + name='pymetasploit3', author='Dan McInerney', version='1.0', author_email='danhmcinerney@gmail.com',