Skip to content

Commit

Permalink
Merge pull request #4 from rapid7/FixLogin
Browse files Browse the repository at this point in the history
Fixed login and bumped version to 2.1 across the board
  • Loading branch information
pmara-r7 authored Sep 8, 2021
2 parents 1696a01 + d0434a1 commit 4a363f2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(fname):
setup(
name='pymetasploit',
author='Nadeem Douba',
version='2.0',
version='2.1',
author_email='[email protected]',
description='A full-fledged msfrpc library for Metasploit framework.',
license='GPL',
Expand Down
2 changes: 1 addition & 1 deletion src/metasploit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__credits__ = []

__license__ = 'GPL'
__version__ = '2.0'
__version__ = '2.1'
__maintainer__ = 'Nadeem Douba'
__email__ = '[email protected]'
__status__ = 'Development'
Expand Down
2 changes: 1 addition & 1 deletion src/metasploit/msfconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__credits__ = []

__license__ = 'GPL'
__version__ = '2.0'
__version__ = '2.1'
__maintainer__ = 'Nadeem Douba'
__email__ = '[email protected]'
__status__ = 'Development'
Expand Down
21 changes: 17 additions & 4 deletions src/metasploit/msfrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
__credits__ = []

__license__ = 'GPL'
__version__ = '2.0'
__version__ = '2.1'
__maintainer__ = 'Nadeem Douba'
__email__ = '[email protected]'
__status__ = 'Development'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/metasploit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = []

__license__ = 'GPL'
__version__ = '2.0'
__version__ = '2.1'
__maintainer__ = 'Nadeem Douba'
__email__ = '[email protected]'
__status__ = 'Development'
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/pymsfconsole
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ __copyright__ = 'Copyright 2021, PyMetasploit Project'
__credits__ = []

__license__ = 'GPL'
__version__ = '2.0'
__version__ = '2.1'
__maintainer__ = 'Nadeem Douba'
__email__ = '[email protected]'
__status__ = 'Development'
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/pymsfrpc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ __copyright__ = 'Copyright 2021, PyMetasploit Project'
__credits__ = []

__license__ = 'GPL'
__version__ = '2.0'
__version__ = '2.1'
__maintainer__ = 'Nadeem Douba'
__email__ = '[email protected]'
__status__ = 'Development'
Expand Down

0 comments on commit 4a363f2

Please sign in to comment.