Skip to content

Commit 9ce2619

Browse files
committed
Lots more NOT matches for generic secret pattern
1 parent d9be9d5 commit 9ce2619

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

generic/passwords.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ var password="itisaSEKRIT";
22

33
var secret="thisisalsonottobetold";
44

5-
let ok="notasecret";
5+
let ok=secret;
66

77
if (secret == "hardcodedsecret") {
88
do_admin();
99
}
10+

generic/patterns.yml

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,69 @@ patterns:
77
regex:
88
version: 0.4
99
pattern: |
10-
[a-zA-Z0-9\t !.,$%&*+?^_`{|}()[\]\\/~-]+
10+
[a-zA-Z0-9!.,$%&*+?^_`{|}()[\]\\/~-][a-zA-Z0-9\t !.,$%&*+?^_`{|}()[\]\\/~-]*
1111
start: |
12-
(?i)(?:api|jwt|mysql)?[_.-]?(?:pass?(?:wo?r?d|code|phrase)?|pwd|secret|token)[\t ]*[=:][\t ]*["']?
12+
(?i)(?:api|jwt|mysql)?[_.-]?(?:pass?(?:wo?r?d|code|phrase)?|pwd?|secret)[\t ]*(={1,3}|:)[\t ]*["']?
1313
end: |
1414
(\z|[\r\n'"])
15-
additional_not_match:
16-
- \b((?i)(?:pass?(wo?r?d|code|phrase)?|pwd|secret|token|write|read|on|off|true|false|placeholder|dummy|none)\b
17-
- ^[\t \r\n"'()${}].*
18-
15+
additional_not_match:
16+
# something that means "password" or a placeholder name - either a variable or a placeholder
17+
- ^(?i)(?:[A-Za-z0-9_.]*,\s*)?(?:str\()?[[<(]?(?:(?:user|key)_?)?(?:pass?(wo?r?d|code|phrase)|pass|pwd|secret|token|tok|redacted|placeholder|dummy|pw|thephrase),?[\]>)]?\\?$
18+
- ^.*token.*$
19+
- ^[a-zA-Z0-9._]+[_.](?:password|passphrase|secret|key).*$
20+
- ^.* passphrase .*$
21+
# a literal value or config switch
22+
- ^(?i)(?:[a-zA-Z0-9_.]*,\s*)?[[<(]?(?:write|read|on|off|true|false|none|null|nil|undefined|eof|ignore|eol|git),?[\]>)]?(?:\)\s*\{)?\\?$
23+
- ^\s*%[sr]\s*$ # format string placeholder
24+
- ^\s*$ # whitespace
25+
- ^\s*(?:int|str|Any|None|bytes|bool)\s*([,|].*)?\s*$ # Python basic type hints
26+
# Python container type hints
27+
- ^\s*(?:[Tt]uple|[Ll]ist|[Dd]ict|Callable|Iterable|Sequence|Optional)\[.*\]\s*$
28+
- ^\s*\.\.\.\s*$ # ...
29+
- ^\s*\\\s*$ # a bare backslash
30+
- ^\s*,s*$ # a bare comma
31+
- ^\\0$ # literal \0
32+
# function definitions, e.g. Javascript
33+
- ^function\s*\([^)]*\)\s*{\s*
34+
- ^\([^)]*\)\s*=>\s*(?:{\s*|[^;)]+[;)])$
35+
# short numbers, possibly followed by a comment (some kind of tokenisation)
36+
- ^\s*[0-9]{1,4}(?:\s*(?:/\*|#|//).*)?$
37+
# function calls or a new variable
38+
- ^(?:new )?[a-zA-Z0-9_.]+\(.*$
39+
# reference to a member variable
40+
- ^\s*(?:self|this)\.[a-zA-Z_][a-zA-Z0-9_]+[,[]?\s*$
41+
# index into a variable
42+
- ^\s*[a-zA-Z0-9_.]+\[(?:[a-zA-Z0-9_.]+)?\]?\s*$
43+
# directories
44+
- ^\s*(?:~|/tmp|\.\.|\.)\s*$
45+
# regex
46+
- ^\\{1,2}w\+/g,( \\?)?$
47+
# a variable substitution
48+
- ^\s*\$\{[^}]+}\s*$
49+
# surrounded by {}
50+
- ^\s*\{[^}]*\}\s*$
51+
# surrounded by []
52+
- ^\s*\[[^\]]*\]\s*$
53+
# - ^["'()${}].* # check this!
54+
# stray single chars
55+
- ^[,()[\]{}`.]\\?$
56+
# urllib demo passphrase
57+
- ^geheim\$parole$
58+
# docs
59+
- ^\s*\([Oo]ptional\).*$
60+
# smilies
61+
- ^-[)(]$
62+
1963
expected:
2064
- name: passwords.js
2165
start_offset: 14
2266
end_offset: 25
2367
- name: passwords.js
2468
start_offset: 41
2569
end_offset: 62
70+
- name: passwords.js
71+
start_offset: 97
72+
end_offset: 112
2673

2774
comments:
2875
- "`password`, `secret`, `key`, or password like prefix (fuzzy)"
@@ -35,7 +82,16 @@ patterns:
3582
regex:
3683
version: 0.1
3784
pattern: |
38-
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
85+
(?i)[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
86+
start: |
87+
\A|[^0-9A-Fa-f-]
88+
end: |
89+
\z|[^0-9A-Fa-f-]
90+
additional_not_match:
91+
- ^12345678-1234-5678-1234-567812345678$
92+
- ^00000000-0000-0000-0000-000000000000$
93+
- ^(?i)00010203-0405-0607-0809-0a0b0c0d0e0f$
94+
- ^(?i)12345678-1234-1234-1234-123456789abc$
3995
expected:
4096
- name: uuids.txt
4197
start_offset: 12
@@ -46,3 +102,4 @@ patterns:
46102
- name: uuids.txt
47103
start_offset: 131
48104
end_offset: 167
105+

testing/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, name: str, description: str, start: str, pattern: str, end: s
4646
] if additional_not_matches is not None else []
4747
self.additional_matches = [add_match.strip() for add_match in additional_matches
4848
] if additional_matches is not None else []
49+
4950
self.expected = expected
5051

5152
def regex_string(self) -> bytes:
@@ -199,7 +200,7 @@ def pcre_result_match(pattern: Pattern,
199200

200201
if not dry_run:
201202
if not any([path_offsets_match(file_details, loc) for loc in pattern.expected]):
202-
if not quietn:
203+
if not quiet:
203204
LOG.log(logging.ERROR if pattern.expected else logging.INFO,
204205
"%s result '%s' for '%s' in path '%s'; %s:%d-%d",
205206
"❌ unexpected" if pattern.expected else "ℹ️ found", parts['pattern'], pattern.name,

0 commit comments

Comments
 (0)