From 1db1fe81ceb6c1366defb869a9bebe6ad1f97f06 Mon Sep 17 00:00:00 2001 From: Wlayzz <34021743+wlayzz@users.noreply.github.com> Date: Thu, 22 Sep 2022 11:38:58 +0200 Subject: [PATCH] Escaping parenthesis on regex to fix error : re.error: unbalanced parenthesis at position X --- SecretFinder.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/SecretFinder.py b/SecretFinder.py index c0ad533..1ef8fc5 100644 --- a/SecretFinder.py +++ b/SecretFinder.py @@ -42,12 +42,12 @@ 'amazon_aws_access_key_id' : r'A[SK]IA[0-9A-Z]{16}', 'amazon_mws_auth_toke' : r'amzn\\.mws\\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', 'amazon_aws_url' : r's3\.amazonaws.com[/]+|[a-zA-Z0-9_-]*\.s3\.amazonaws.com', - 'amazon_aws_url2' : r"(" \ + 'amazon_aws_url2' : r"\(" \ r"[a-zA-Z0-9-\.\_]+\.s3\.amazonaws\.com" \ r"|s3://[a-zA-Z0-9-\.\_]+" \ r"|s3-[a-zA-Z0-9-\.\_\/]+" \ r"|s3.amazonaws.com/[a-zA-Z0-9-\.\_]+" \ - r"|s3.console.aws.amazon.com/s3/buckets/[a-zA-Z0-9-\.\_]+)", + r"|s3.console.aws.amazon.com/s3/buckets/[a-zA-Z0-9-\.\_]+\)", 'facebook_access_token' : r'EAACEdEose0cBA[0-9A-Za-z]+', 'authorization_basic' : r'basic [a-zA-Z0-9=:_\+\/-]{5,100}', 'authorization_bearer' : r'bearer [a-zA-Z0-9_\-\.=:_\+\/]{5,100}', @@ -67,14 +67,14 @@ 'ssh_dc_private_key' : r'-----BEGIN EC PRIVATE KEY-----', 'pgp_private_block' : r'-----BEGIN PGP PRIVATE KEY BLOCK-----', 'json_web_token' : r'ey[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$', - 'slack_token' : r"\"api_token\":\"(xox[a-zA-Z]-[a-zA-Z0-9-]+)\"", - 'SSH_privKey' : r"([-]+BEGIN [^\s]+ PRIVATE KEY[-]+[\s]*[^-]*[-]+END [^\s]+ PRIVATE KEY[-]+)", + 'slack_token' : r"\"api_token\":\"\(xox[a-zA-Z]-[a-zA-Z0-9-]+\)\"", + 'SSH_privKey' : r"\([-]+BEGIN [^\s]+ PRIVATE KEY[-]+[\s]*[^-]*[-]+END [^\s]+ PRIVATE KEY[-]+\)", 'Heroku API KEY' : r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}', - 'possible_Creds' : r"(?i)(" \ + 'possible_Creds' : r"\(?i\)\(" \ r"password\s*[`=:\"]+\s*[^\s]+|" \ r"password is\s*[`=:\"]*\s*[^\s]+|" \ r"pwd\s*[`=:\"]*\s*[^\s]+|" \ - r"passwd\s*[`=:\"]+\s*[^\s]+)", + r"passwd\s*[`=:\"]+\s*[^\s]+\)", } _template = ''' @@ -155,6 +155,7 @@ def getContext(matches,content,name,rex='.+?'): if i not in matches2: matches2.append(i) for m in matches2: + m = m.replace('(','\\(').replace(')','\\)') # Escape parenthesis to avoid regex error context = re.findall('%s%s%s'%(rex,m,rex),content,re.IGNORECASE) item = {