Skip to content

Commit 19e8b6e

Browse files
committed
Improved generic password pattern
1 parent f6acd34 commit 19e8b6e

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

generic/patterns.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ patterns:
99
pattern: |
1010
[a-zA-Z0-9!.,$%&*+?^_`{|}()[\]\\/~-][a-zA-Z0-9\t !.,$%&*+?^_`{|}()[\]\\/~-]*
1111
start: |
12-
(?i)(?:api|jwt|mysql)?[_.-]?(?:pass?(?:wo?r?d|code|phrase)|pwd|secret)[\t ]*(={1,3}|:)[\t ]*(?:["']|b["'])?
12+
(?:\A|[^a-zA-Z0-9])(?i)(?:api|jwt|mysql)?[_.-]?(?:pass?(?:wo?r?d|code|phrase)|pwd|secret)[\t ]*(={1,3}|:)[\t ]*(?:["']|b["'])?
1313
end: |
1414
(\z|[\r\n'"])
1515
additional_not_match:

testing/test.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import platform
2121
from colorama import Fore, Style
2222
from threading import Lock
23-
from random import randbytes
24-
from base64 import b64encode
23+
from random import randbytes, choices
24+
from string import printable
2525
from itertools import zip_longest
2626
from tqdm import tqdm
2727

@@ -442,46 +442,50 @@ def random_test_patterns(tests_path: str, include: Optional[list[str]], exclude:
442442
LOG.error("❌ hyperscan pattern compilation error in '%s'", dirpath)
443443
exit(1)
444444

445-
goal = 100000000000
446-
chunk_size = 100000000
445+
binary_goal = 1000000000
446+
ascii_goal = 1000000000
447+
binary_chunk_size = 100000000
448+
ascii_chunk_size = 100000000
447449

448450
if progress:
449-
pb = tqdm(total=goal, unit_scale=True, unit='B')
451+
pb = tqdm(total=binary_goal + ascii_goal, unit_scale=True, unit='B')
450452

451-
# read 100GB of random data (a mix of binary and base64 encoded)
452-
while size_read < goal:
453+
# read 100GB of random binary data
454+
while size_read < binary_goal:
453455
# read random bytes, 100MB at a time
454-
content = randbytes(chunk_size)
455-
456-
size_read += len(content)
457-
if progress:
458-
pb.update(len(content))
456+
binary_content = randbytes(binary_chunk_size)
459457

460458
scan(db,
461459
None,
462-
content,
460+
binary_content,
463461
patterns,
464462
verbose=verbose,
465463
quiet=quiet,
466464
write_to_results=True,
467465
dry_run=True)
468466

469-
# same content, base64 encoded
470-
content_b64 = b64encode(content)
471-
472-
size_read += len(content_b64)
467+
size_read += binary_chunk_size
473468
if progress:
474-
pb.update(len(content_b64))
469+
pb.update(binary_chunk_size)
470+
471+
# read 1GB of random ascii data
472+
while size_read < binary_goal + ascii_goal:
473+
# some random ASCII (printable characters)
474+
ascii_content = ''.join(choices(printable, k=ascii_chunk_size)).encode('utf-8')
475475

476476
scan(db,
477477
None,
478-
content_b64,
478+
ascii_content,
479479
patterns,
480480
verbose=verbose,
481481
quiet=quiet,
482482
write_to_results=True,
483483
dry_run=True)
484484

485+
size_read += ascii_chunk_size
486+
if progress:
487+
pb.update(ascii_chunk_size)
488+
485489
if progress:
486490
pb.close()
487491

@@ -491,7 +495,7 @@ def random_test_patterns(tests_path: str, include: Optional[list[str]], exclude:
491495
for pattern_name, results in RESULTS.items():
492496
count = sum((1 for result in results))
493497
if count > 0:
494-
LOG.info("%s: %d", pattern_name, )
498+
LOG.info("%s: %d", pattern_name, count)
495499

496500

497501
# sideffect: writes to global RESULTS

uri/patterns.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ patterns:
6262
start: |
6363
\b[A-Za-z][A-Za-z0-9+_-]*://[^/?#:@\s\p{Cc}]*:
6464
end: |
65-
@
65+
@[^/?#\s\p{Cc},_=!{}()<>~`[\]*&^$£'";|]*(?:\:[0-9]{1,5})?[/?#\s]
6666
additional_not_match:
6767
# placeholders
6868
- (?i)^[[{(<]?(?:password|passwd|secret)[\]})>]?$

0 commit comments

Comments
 (0)