From 9c42372bf91502bba138ed22819f4c9e2569e91f Mon Sep 17 00:00:00 2001 From: Dan Breakiron Date: Tue, 13 Jun 2023 18:48:38 -0400 Subject: [PATCH 1/2] Fixed an exception caused by trying to parse the expiration date of a token that never expires --- CHANGELOG.md | 6 ++++++ sync.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 285a100..9256ca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +* Handled an exception caused by `_check_token()` trying to parse the expiration date from a token that never expires + ## [3.0.1] - 17 May 2023 ### Changed diff --git a/sync.py b/sync.py index 96b4c24..29be16a 100644 --- a/sync.py +++ b/sync.py @@ -289,7 +289,11 @@ async def _execute_query(self, query: DocumentNode, variable_values: dict = None async def _check_token(self) -> None: """Send a `whoami` query to Ghostwriter to check authentication and token expiration.""" whoami = await self._execute_query(self.whoami_query) - expiry = datetime.fromisoformat(whoami["whoami"]["expires"]) + try: + expiry = datetime.fromisoformat(whoami["whoami"]["expires"]) + except Exception: + expiry = whoami["whoami"]["expires"] + await mythic.send_event_log_message( mythic=self.mythic_instance, message=f"Mythic Sync has successfully authenticated to Ghostwriter. Your configured token expires at: {expiry}", @@ -299,7 +303,7 @@ async def _check_token(self) -> None: # Check if the token will expire within 24 hours now = datetime.now(timezone.utc) - if expiry - now < timedelta(hours=24): + if isinstance(expiry, datetime) and expiry - now < timedelta(hours=24): mythic_sync_log.debug(f"The provided Ghostwriter API token expires in less than 24 hours ({expiry})!") await mythic.send_event_log_message( mythic=self.mythic_instance, From 2fba564001e9d25043822e3451d506de1df08084 Mon Sep 17 00:00:00 2001 From: Dan Breakiron Date: Tue, 13 Jun 2023 18:55:24 -0400 Subject: [PATCH 2/2] Bumped version number in CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9256ca2..3f19d58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## [3.0.2] - 13 June 2023 ### Fixed