Skip to content

Commit

Permalink
Merge pull request #21 from spark1security/ms/keyboard-interrupt
Browse files Browse the repository at this point in the history
Save findings before exiting due to keyboard interrupt
  • Loading branch information
blupants authored Jul 9, 2024
2 parents 4bf2a04 + e1f9cb8 commit 9ec710d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/n0s1/controllers/confluence_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def is_connected(self):
return False

def get_data(self, include_coments=False, limit=None):
from atlassian.confluence import ApiPermissionError
if not self._client:
return {}

Expand Down Expand Up @@ -150,6 +151,11 @@ def get_data(self, include_coments=False, limit=None):
while not pages_finished:
try:
pages = self._client.get_all_pages_from_space(key, start=pages_start, limit=limit)
except ApiPermissionError as e:
message = str(e) + f" get_all_pages_from_space({key}, start={pages_start}, limit={limit}). Skipping..."
self.log_message(message, logging.WARNING)
pages = [{}]
break
except Exception as e:
message = str(e) + f" get_all_pages_from_space({key}, start={pages_start}, limit={limit})"
self.log_message(message, logging.WARNING)
Expand Down
6 changes: 6 additions & 0 deletions src/n0s1/controllers/jira_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def is_connected(self):
return False

def get_data(self, include_coments=False, limit=None):
from jira.exceptions import JIRAError
if not self._client:
return {}
start = 0
Expand All @@ -85,6 +86,11 @@ def get_data(self, include_coments=False, limit=None):
while not issues_finished:
try:
issues = self._client.search_issues(ql, startAt=issue_start, maxResults=limit)
except JIRAError as e:
self.log_message(f"Error while searching issues on Jira project: [{key}]. Skipping...", logging.WARNING)
self.log_message(e)
issues = [{}]
break
except Exception as e:
message = str(e) + f" client.search_issues({ql}, startAt={issue_start}, maxResults={limit})"
self.log_message(message, logging.WARNING)
Expand Down
16 changes: 12 additions & 4 deletions src/n0s1/n0s1.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,18 @@ def main(callback=None):
message = f"Starting scan in {mode} mode..."
log_message(message)

scan(regex_config, controller, scan_arguments)
_save_report(report_format)

log_message("Done!")
try:
scan(regex_config, controller, scan_arguments)
except KeyboardInterrupt:
log_message("Keyboard interrupt detected. Saving findings and exiting...")
sys.exit(130)
except Exception as e:
log_message("Execution interrupted by an exception. Saving partial report and exiting...")
log_message(e)
sys.exit(1)
finally:
_save_report(report_format)
log_message("Done!")


if __name__ == "__main__":
Expand Down

0 comments on commit 9ec710d

Please sign in to comment.