Skip to content

Commit

Permalink
suppress logging + show match results. (#74)
Browse files Browse the repository at this point in the history
* version bump
  • Loading branch information
valayDave authored Apr 2, 2023
1 parent 25dfa9d commit 682313a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tell-me-your-secrets"
version = "2.4.1"
version = "2.4.2"
description = "A simple module which finds files with different secrets keys present inside a directory"
authors = ["Valay Dave <valaygaurang@gmail.com>"]
license = "MIT"
Expand Down
15 changes: 7 additions & 8 deletions tell_me_your_secrets/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __init__(self, config_object: dict, search_path: str, use_gitignore: bool, p
self.output_path = output_path
# $ Make Configuration Objects For each of the Signatures in the Config Object.
self.signatures: List[Signature] = self.load_signatures(config_object.get('signatures', {}), user_filters or [])
module_logger.info(f'Secret Sniffer Initialised For Path: {search_path}')
module_logger.debug(f'Secret Sniffer Initialised For Path: {search_path}')

# $ Create the signature objects over here.
@staticmethod
Expand All @@ -171,23 +171,23 @@ def load_signatures(raw_signatures: dict, user_filters: list) -> list:
for signature_obj in raw_signatures:
# $ Ignore Object if no Name/Part.
if 'name' not in signature_obj or 'part' not in signature_obj:
module_logger.warn('Signature definition missing either name or part')
module_logger.debug('Signature definition missing either name or part')
continue
if len(user_filters) > 0:
if len([filtered_val for filtered_val in user_filters if str(filtered_val).lower() in str(signature_obj['name']).lower()]) == 0:
module_logger.warning(f'Duplicate named used defined filter matching skipping '
f'adding {signature_obj["name"]} from config')
module_logger.debug(f'Pattern did not match filters. Skipping filter matching '
f'for signature {signature_obj["name"]} from config')
continue
if 'match' in signature_obj:
parsed_signatures.append(SimpleMatch(signature_obj['part'], signature_obj['name'], signature_obj['match']))
elif 'regex' in signature_obj:
parsed_signatures.append(RegexSignature(signature_obj['part'], signature_obj['name'], signature_obj['regex']))
else:
module_logger.warning('No Match Method Of Access')
module_logger.debug('No Match Method Of Access')
chosen_configs.append(signature_obj['name'] + " In File " + signature_obj['part'])

if len(user_filters) > 0:
module_logger.info('Applying Filtered Signatures : \n\n\t%s\n', '\n\t'.join(chosen_configs))
module_logger.debug('Applying Filtered Signatures : \n\n\t%s\n', '\n\t'.join(chosen_configs))

return parsed_signatures

Expand All @@ -197,8 +197,7 @@ def find_vulnerable_files(self):

self.process(filtered_files)

module_logger.info(f'Processed {len(filtered_files)} files and found {len(self.matched_signatures)} matches '
f'from the search_path {self.search_path} in {self._get_time()} seconds')
module_logger.debug(f'Processed {len(filtered_files)} files and found {len(self.matched_signatures)} matches from the search_path {self.search_path} in {self._get_time()} seconds')
if self.write_results:
self.write_results_to_file()

Expand Down
10 changes: 6 additions & 4 deletions tell_me_your_secrets/processor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Union

from tell_me_your_secrets.logger import get_logger
from tell_me_your_secrets.utils import get_file_data
Expand All @@ -10,11 +10,13 @@ class SignatureMatch:
name: str
part: str
path: str
contents: Union[str, None]

def __init__(self, name: str, part: str, path: str):
def __init__(self, name: str, part: str, path: str, contents: Union[str, None] = None):
self.name = name
self.part = part
self.path = path
self.contents = contents


class Processor:
Expand Down Expand Up @@ -46,8 +48,8 @@ def run_signatures(self, file_path, content) -> List[SignatureMatch]:

if self.print_results:
module_logger.info(f'Signature Matched : {signature.name} | On Part : {signature.part} | With '
f'File : {file_path}')
f'File : {file_path} | Result : {match_result.matched_value}')

matches.append(SignatureMatch(signature.name, signature.part, file_path))
matches.append(SignatureMatch(signature.name, signature.part, file_path, match_result.matched_value))

return matches
2 changes: 1 addition & 1 deletion test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def test_write_results_to_file_issues(self):
]

signature_recognizer.write_results_to_file()
self.assertEqual(b',name,part,path\n0,Match,file,/path/to/file\n', output_file.read())
self.assertEqual(b',name,part,path,contents\n0,Match,file,/path/to/file,\n', output_file.read())

0 comments on commit 682313a

Please sign in to comment.