-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpatterns.yml
189 lines (175 loc) · 8.63 KB
/
patterns.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Database passwords
# We have two Database Connection String patterns: one with Password= before any other keyword, and one with Password= after any other keyword
# we define the pattern by what we don't want it to match
# - ; or ", since those are the end of the password/secret field and the end of the connection string respectively
# - control characters, \x00-\x08, since those are not valid in ASCII or UTF-8, or other common character sets we'll come across
# We don't account for connection strings encoded in UTF-16, but that will be a rare case, if it happens at all
patterns:
- name: Database Connection String (full string)
type: database_connection_string_full
description: "Database connection strings are used to connect to databases, often with embedded credentials."
regex:
pattern: |
[^"'`\x00-\x08\r\n|]*([Ss]erver|[Pp]rovider|[Dd]atabase|[Uu]ser [Ii]d|[Dd]ata [Ss]ource|[Ee]ndpoint|[Dd]efault[Ee]nd[Pp]oints[Pp]rotocol|[Aa]ccountName|[Da]ata[Ss]ource|[Aa]uthentication|[Ll]ogin|[Ii]nitial[Cc]atalog|DB|Trusted_Connection|authenticationType|DSN|[Dd]ata[Ss]ource[Nn]ame|[Ii]ntegrated[Ss]ecurity|[Ll]ocation|[Ee]ncrypt|[Ss]ystem|[Pp]rotocol|[Hh]ost|[Pp]ort|SRVR|[Dd]river|Dbq|[Ss]sl[Mm]ode|SSL|[Uu]id|DBNAME|SystemDB|[Pp]ersist [Ss]ecurity [Ii]nfo|[Cc]onnection [Tt]ype|[Dd]ata[Ss]ource[Nn]ame|[Ee]xcel [Ff]ile|[Ss]erver [Nn]ame|URL)=[^"'`\x00-\x08\r\n|]*
start: |
\A|["'`]|"|[\r\n]|[=:-]
end: |
\z|["'`]|"|[\r\n]
additional_match:
- (^|;)([Pp]assword|[Pp]wd|[Ss]hared[Ss]ecret[Vv]alue|[Aa]ccount[Kk]ey|PW|pw|[Cc]ipher [Kk]ey|OAuth Access Token Secret)=
additional_not_match:
# placeholders, variable substitutions, etc.
- (^|;)([Pp]assword|[Pp]wd|[Ss]hared[Ss]ecret[Vv]alue|[Aa]ccount[Kk]ey|PW|pw|[Cc]ipher [Kk]ey|OAuth Access Token Secret)=(%s\b|\{\{[^}]+\}\}|\{[0-9]+\}|\$?\{[^}]+\}|\[[A-Z_]+\]|['"`]|$)
test:
data: connection_string = "Data Source=eee,1433;Initial Catalog=bbb;Integrated Security=False;User ID=ccc@aaa;Password=ddd;"
start_offset: 21
end_offset: 117
- name: Database Connection String (1)
type: database_connection_string_1
description: "Database connection strings are used to connect to databases, often with embedded credentials."
regex:
pattern: |
[^;"\x00-\x08]+
start: |
("|")(([Ss]erver|[Pp]rovider|[Dd]atabase|[Uu]ser [Ii]d|[Dd]ata [Ss]ource|[Ee]ndpoint|[Dd]efault[Ee]nd[Pp]oints[Pp]rotocol|[Aa]ccountName|[Da]ata[Ss]ource|[Aa]uthentication|[Ll]ogin|[Ii]nitial[Cc]atalog|DB|Trusted_Connection|authenticationType|DSN|[Dd]ata[Ss]ource[Nn]ame|[Ii]ntegrated[Ss]ecurity|[Ll]ocation|[Ee]ncrypt|[Ss]ystem|[Pp]rotocol|[Hh]ost|[Pp]ort|SRVR|[Dd]river|Dbq|[Ss]sl[Mm]ode|SSL|[Uu]id|DBNAME|SystemDB|[Pp]ersist [Ss]ecurity [Ii]nfo|[Cc]onnection [Tt]ype|[Dd]ata[Ss]ource[Nn]ame|[Ee]xcel [Ff]ile|[Ss]erver [Nn]ame|URL)=[^"]+;) ?([Pp]assword|[Pp]wd|[Ss]hared[Ss]ecret[Vv]alue|[Aa]ccount[Kk]ey|PW|pw|[Cc]ipher [Kk]ey|OAuth Access Token Secret)=
end: |
(;|"|")
additional_not_match:
# placeholders, variable substitutions and regex matches
- ^(%(\.\*)?s|\$[a-zA-Z_]+|<[a-zA-Z_]+>|\{[a-zA-Z_]*\}|\[[a-zA-Z_]+\]|%[A-Z_]+%|\.\*|\[\^])$
# parameterized query
- parameters\('[^']+'\)
expected:
- name: connection_strings.txt
start_offset: 126
end_offset: 129
- name: connection_strings.txt
start_offset: 172
end_offset: 225
test:
data: |
connection_string = "Data Source=eee,1433;Initial Catalog=bbb;Integrated Security=False;User ID=ccc@aaa;Password=ddd;"
start_offset: 113
end_offset: 116
comments:
- This will spot connection strings for many databases, including MySQL, PostgreSQL, Oracle, SQL Server
- To cut FPs, we require the start of the string to be a database-specific keyword
- name: Database Connection String (2)
type: database_connection_string_2
description: "Database connection strings are used to connect to databases, often with embedded credentials."
regex:
pattern: |
[^;"\x00-\x08]+
start: |
(?i)("|")([Pp]assword|[Pp]wd|[Ss]hared[Ss]ecret[Vv]alue|[Aa]ccount[Kk]ey|PW|pw|[Cc]ipher [Kk]ey|OAuth Access Token Secret)=
end: |
;[^";]* ?([Ss]erver|[Pp]rovider|[Dd]atabase|[Uu]ser [Ii]d|[Dd]ata [Ss]ource|[Ee]ndpoint|[Dd]efault[Ee]nd[Pp]oints[Pp]rotocol|[Aa]ccountName|[Da]ata[Ss]ource|[Aa]uthentication|[Ll]ogin|[Ii]nitial[Cc]atalog|DB|Trusted_Connection|authenticationType|DSN|[Dd]ata[Ss]ource[Nn]ame|[Ii]ntegrated[Ss]ecurity|[Ll]ocation|[Ee]ncrypt|[Ss]ystem|[Pp]rotocol|[Hh]ost|[Pp]ort|SRVR|[Dd]river|Dbq|[Ss]sl[Mm]ode|SSL|[Uu]id|DBNAME|SystemDB|[Pp]ersist [Ss]ecurity [Ii]nfo|[Cc]onnection [Tt]ype|[Dd]ata[Ss]ource[Nn]ame|[Ee]xcel [Ff]ile|[Ss]erver [Nn]ame|URL)=
additional_not_match:
# placeholders
- ^(%(\.\*)?s|\$[a-zA-Z_]+|<[a-zA-Z_]+>|\{[a-zA-Z_]+\}|\[[a-zA-Z_]+\]|%[A-Z_]+%|\.\*)$
# parameterized query
- parameters\('[^']+'\)
test:
data: |
connection_string = "Password=ddd;Data Source=eee,1433;Initial Catalog=bbb;Integrated Security=False;User ID=ccc@aaa;"
start_offset: 30
end_offset: 33
comments:
- This will spot connection strings for many databases, including MySQL, PostgreSQL, Oracle, SQL Server
- To cut FPs, we require part of the string after the password to be a database-specific keyword
- name: Database Connection String (3)
type: database_connection_string_3
description: "Database connection strings are used to connect to databases, often with embedded credentials."
regex:
pattern: |
[^;\r\n"'\x00-\x08]+
start: |
(\A|\b)ConnectionStrings__Default=[^\r\n]*([Pp]assword|[Pp]wd|[Ss]hared[Ss]ecret[Vv]alue|[Aa]ccount[Kk]ey|PW|pw|[Cc]ipher [Kk]ey|OAuth Access Token Secret)=
end: |
([;\n]|\z)
additional_not_match:
# placeholders
- ^(%(\.\*)?s|\$[a-zA-Z_]+|<[a-zA-Z_]+>|\$?\{[a-zA-Z_]+\}|\[[a-zA-Z_]+\]|%[A-Z_]+%|\.\*)$
test:
data: |
ConnectionStrings__Default="Data Source=eee,1433;Initial Catalog=bbb;Integrated Security=False;User ID=ccc@aaa;Password=ddd;"
start_offset: 120
end_offset: 123
comments:
- This will spot the ConnectionStrings__Default env var being set with a Password
expected:
- name: docker_sqlserver.yml
start_offset: 394
end_offset: 405
- name: TSQL CREATE LOGIN/USER
type: tsql_create_login_or_user
description: "A TSQL CREATE LOGIN or USER command using a password"
regex:
pattern: |
[^'\x00-\x08]{8,128}
start: |
(\A|\b)CREATE\s+(LOGIN|USER)\s+[^\s\x00-\x08]+\s+WITH\s+PASSWORD\s+=\s+N?'
end: |
\'
test:
data: |
CREATE USER phony WITH PASSWORD = 'mynewcreds';
start_offset: 35
end_offset: 45
expected:
- name: tsql_create_user.sql
start_offset: 35
end_offset: 45
comments:
- This is specific to Microsoft SQL Server TSQL syntax
- name: SQLAlchemy Database Connection String
type: sqlalchemy_connection_string
description: SQLAlchemy connection strings are used to connect to databases, often with embedded credentials.
regex:
pattern: |
[^$/?#@\s][^/?#@\s\x00-\x08]*
start: |
(\A|\b)mysql\+[a-z]+://[^/?#:@\s\x00-\x08]*:
end: |
@
additional_not_match:
- (?i)^[[{(<]?(?:password|passwd|secret)[\]})>]?$
- ^\$?\{[^}+]\}i\}$
- ^%(?:\.\*)?s$
test:
data: |
engine = create_engine('mysql+mysqlconnector://scott:tiger@localhost/foo')
start_offset: 53
end_offset: 58
- name: MongoDB connection string
type: mongodb_connection_string
regex:
version: 0.2
pattern: |
mongodb(\+[a-z]+)?://[^'"`<>/:@\s\x00-\x08]+:[^'"`<>/@\s\x00-\x08]+@[^?'"`\s\x00-\x08]+
start: |
\A|\b
end: |
\z|\s|['"`?]
additional_not_match:
- (?i):(test|a|my)?[_-]?pass(word)?@
- :%(?:\.\*)?[sv]@
- :\$?\{[^}+]\}@
- ^mongodb\+srv://b\*b%40f3tt%3D:%244to%40L8%[email protected]/mydb%3F\?replicaSet=repl0
test:
data: mongodb+srv://foo:[email protected]/
- name: JDBC Database Connection String
type: jdbc_connection_string
regex:
version: 0.1
pattern: |
jdbc:[^:\x00-\x08]+:\/\/[^\/\x00-\x08]+\/[^?\x00-\x08]+\?user=[^&\x00-\x08]+&password=[^\s'"`<{$%*\x00-\x08]+
start: |
\A|\b
end: |
\z|\s|['"`<]
test:
data: |
jdbc:mysql://localhost:3306/mydb?user=root&password=toor
start_offset: 0
end_offset: 56