diff --git a/setup.py b/setup.py index 1343f01..acd3ef9 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read(fname): setup( name='pymetasploit', author='Nadeem Douba', - version='2.0', + version='2.1', author_email='ndouba@gmail.com', description='A full-fledged msfrpc library for Metasploit framework.', license='GPL', diff --git a/src/metasploit/__init__.py b/src/metasploit/__init__.py index 065e507..f7ef39a 100644 --- a/src/metasploit/__init__.py +++ b/src/metasploit/__init__.py @@ -5,7 +5,7 @@ __credits__ = [] __license__ = 'GPL' -__version__ = '2.0' +__version__ = '2.1' __maintainer__ = 'Nadeem Douba' __email__ = 'ndouba@gmail.com' __status__ = 'Development' diff --git a/src/metasploit/msfconsole.py b/src/metasploit/msfconsole.py index 0155095..7e36e51 100644 --- a/src/metasploit/msfconsole.py +++ b/src/metasploit/msfconsole.py @@ -8,7 +8,7 @@ __credits__ = [] __license__ = 'GPL' -__version__ = '2.0' +__version__ = '2.1' __maintainer__ = 'Nadeem Douba' __email__ = 'ndouba@cygnos.com' __status__ = 'Development' diff --git a/src/metasploit/msfrpc.py b/src/metasploit/msfrpc.py index d012f70..d9b5874 100644 --- a/src/metasploit/msfrpc.py +++ b/src/metasploit/msfrpc.py @@ -11,7 +11,7 @@ __credits__ = [] __license__ = 'GPL' -__version__ = '2.0' +__version__ = '2.1' __maintainer__ = 'Nadeem Douba' __email__ = 'ndouba@gmail.com' __status__ = 'Development' @@ -228,7 +228,7 @@ def call(self, method, *args): self.client.request('POST', self.uri, packb(l), self._headers) r = self.client.getresponse() if r.status == 200: - return unpackb(r.read()) + return unpackb(r.read(), raw=False) raise MsfRpcError('An unknown error has occurred while logging in.') elif self.authenticated: l.insert(1, self.sessionid) @@ -311,9 +311,22 @@ def login(self, username, password): """ if self.sessionid is None: r = self.call(MsfRpcMethod.AuthLogin, username, password) + # in case r is actually encoded in bytes, this is a safe way to turn it back to string for the try/catch + str_data = {} + for key, val in r.items(): + if isinstance(key, bytes): + key_temp = key.decode() + else: + key_temp = key + if isinstance(val, bytes): + val_temp = val.decode() + else: + val_temp = val + str_data[key_temp] = val_temp + try: - if r['result'] == 'success': - self.sessionid = r['token'] + if str_data['result'] == 'success': + self.sessionid = str_data['token'] except KeyError: raise MsfRpcError('Login failed.') else: diff --git a/src/metasploit/utils.py b/src/metasploit/utils.py index 846946a..d241241 100644 --- a/src/metasploit/utils.py +++ b/src/metasploit/utils.py @@ -7,7 +7,7 @@ __credits__ = [] __license__ = 'GPL' -__version__ = '2.0' +__version__ = '2.1' __maintainer__ = 'Nadeem Douba' __email__ = 'ndouba@gmail.com' __status__ = 'Development' diff --git a/src/scripts/pymsfconsole b/src/scripts/pymsfconsole index 48c5a10..33b2db8 100755 --- a/src/scripts/pymsfconsole +++ b/src/scripts/pymsfconsole @@ -15,7 +15,7 @@ __copyright__ = 'Copyright 2021, PyMetasploit Project' __credits__ = [] __license__ = 'GPL' -__version__ = '2.0' +__version__ = '2.1' __maintainer__ = 'Nadeem Douba' __email__ = 'ndouba@cygnos.com' __status__ = 'Development' diff --git a/src/scripts/pymsfrpc b/src/scripts/pymsfrpc index 0851ce7..f4b3f7e 100755 --- a/src/scripts/pymsfrpc +++ b/src/scripts/pymsfrpc @@ -13,7 +13,7 @@ __copyright__ = 'Copyright 2021, PyMetasploit Project' __credits__ = [] __license__ = 'GPL' -__version__ = '2.0' +__version__ = '2.1' __maintainer__ = 'Nadeem Douba' __email__ = 'ndouba@cygnos.com' __status__ = 'Development'