-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlqueries.jsonc
More file actions
403 lines (403 loc) · 14.8 KB
/
Copy pathsqlqueries.jsonc
File metadata and controls
403 lines (403 loc) · 14.8 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
[ // Tested with PasswordState 9.8 Build 9858
{
"Name": "DiscoveryJobs",
"Tablename": "DiscoveryJobs",
"MaskProperties": [
"DiscoveryTook", // This value changes all the time, which makes it a distraction.
"HostNotFound" // This value changes all the time, which makes it a distraction.
]
},
{
"Name": "ActiveDirectoryDomains",
"Tablename": "ADDomains"
},
{
"Name": "WebServers",
"TableName": "WebServers",
"Query": [
"SET NOCOUNT ON",
"DECLARE @Delim char = ':'",
"DECLARE @ServerRoles TABLE (RoleID INT, Role NVARCHAR(60))",
"INSERT INTO @ServerRoles VALUES ",
" -- ordered as shown in the UI",
" (1, 'Standard API'),",
" (2, 'Windows Integrated API'),",
" (3, 'Mobile App'),",
" (4, 'Browser Extensions'),",
" (5, 'Remote Site Locations Agent'),",
" (6, 'Password Reset Portal'),",
" (7, 'Self Destruct Messages')",
"",
"-- Inner select query inspired by SplitString function by Aaron Bertrand (https://stackoverflow.com/a/19935646/21124015), used under the terms of CC BY-SA 3.0.",
"SELECT *, ",
"(",
" SELECT COALESCE((SELECT Role FROM @ServerRoles WHERE RoleID=idx),'???') AS Role, Idx",
" FROM ",
" (",
" SELECT Value, idx = RANK() OVER (ORDER BY n)",
" FROM ",
" ( ",
" SELECT n = Number, ",
" Value = LTRIM(RTRIM(SUBSTRING(ws.FunctionalRoles, Number,",
" CHARINDEX(@Delim, ws.FunctionalRoles + @Delim, Number) - Number)))",
" FROM (SELECT Number = ROW_NUMBER() OVER (ORDER BY name)",
" FROM sys.all_objects) AS x",
" WHERE Number <= LEN(ws.FunctionalRoles)",
" AND SUBSTRING(@Delim + ws.FunctionalRoles, Number, LEN(@Delim)) = @Delim",
" ) as y",
" ) as z",
" WHERE value='True'",
" ORDER BY Idx",
" FOR JSON AUTO",
") as FunctionalRoles2",
"FROM WebServers ws",
"FOR JSON PATH, ROOT ('WebServers')"
],
"MaskProperties": [
"PollHeartbeatTime" // This value changes all the time, which makes it a distraction.
]
},
{
"Name": "BackupSettings",
"Tablename": "BackupSettings"
},
{
"Name": "BadPasswords",
"Tablename": "BadPasswords"
},
{
"Name": "BrowserExtensionSettings",
"Tablename": "BrowserExtensionSettings"
},
{
"Name": "EmailNotificationGroups",
"TableName": "EmailNotificationGroups",
"Query": [
"select eng.*,",
" (",
" select SecurityGroupID, UserID",
" from EmailNotificationGroupsACL acl",
" WHERE acl.EmailNotificationGroupID = eng.EmailNotificationGroupID",
" FOR JSON AUTO",
" ) as ACL,",
" (",
" select beng.NotificationID, beng.Category",
" from BlockedEmailNotificationGroups beng",
" WHERE beng.EmailNotificationGroupID = eng.EmailNotificationGroupID",
" FOR JSON AUTO",
" ) as BlockedEmailNotifications",
"from EmailNotificationGroups eng",
"FOR JSON PATH, root('EmailNotificationGroups')"
]
},
{
"Name": "EmailTemplates",
"Tablename": "EmailTemplates"
},
{
"Name": "FeaturesAccess",
"Tablename": "FeaturesACL"
},
{
"Name": "RestrictedFeatures",
"Tablename": "RestrictedFeatures"
},
{
"Name": "HostTypes",
"Tablename": "HostTypes"
},
{
"Name": "OperatingSystems",
"Tablename": "OperatingSystems"
},
{
"Name": "AccountTypes",
"Tablename": "AccountTypes"
},
{
"Name": "Licenses",
"Tablename": "Licenses"
},
{
"Name": "PasswordGenerators",
"Tablename": "PasswordGenerators"
},
{
"Name": "PasswordListTemplates",
"TableName": "PasswordListTemplates",
"Query": [
"select plt.*,",
"( select pltacl.permissions, pltacl.SecurityGroupID, ",
" ( select sg.SecurityGroupName ",
" from SecurityGroups sg ",
" where sg.SecurityGroupID = pltacl.SecurityGroupID",
" ) as SecurityGroupName, ",
" pltacl.UserID, pltacl.MobileAccess",
" from PasswordListTemplatesACL pltacl",
" where pltacl.PasswordListTemplateID = plt.PasswordListTemplateID",
" for json AUTO",
") as ACL",
"from PasswordListTemplates plt",
"FOR JSON PATH, root('PasswordListTemplates')"
]
},
{
"Name": "PasswordStrengthPolicies",
"Tablename": "PasswordStrengthPolicies"
},
{
"Name": "PrivilegedAccounts",
"TableName": "PrivilegedAccounts",
"Query": [
"select pa.PrivilegedAccountID, pa.Description, pa.UserName,",
" pa.Password, pa.PasswordID, pa.KeyType,",
" pa.PassPhrase, pa.PrivateKey, pa.SiteID,",
" pa.AccountType, pa.EnablePassword,",
" ( select paacl.SecurityGroupID,",
" ( select sg.SecurityGroupName",
" from SecurityGroups sg",
" where sg.SecurityGroupID = paacl.SecurityGroupID",
" ) as SecurityGroupName,",
" paacl.UserID, paacl.AccessExpiresAt",
" from PrivilegedAccountsACL paacl",
" where paacl.PrivilegedAccountID = pa.PrivilegedAccountID",
" for json AUTO",
" ) as ACL",
"from PrivilegedAccounts pa",
"FOR JSON PATH, root('PrivilegedAccounts')"
]
},
{
"Name": "ResetPasswordScripts",
"TableName": "Scripts",
"Query": [
"select ScriptID, ScriptName, ScriptDescription,",
" len(script) as ScriptLength,",
" Convert(varchar(64), HASHBYTES('SHA2_256',script), 2) as ScriptSHA256,",
" Inbuilt, Author, UpdatedBy, LastUpdated, Template, TemplateType",
"from Scripts",
"FOR JSON PATH, ROOT ('ResetPasswordScripts')"
]
},
{
"Name": "ValidationScripts",
"TableName": "ValidationScripts",
"Query": [
"select ScriptID, ScriptName, ScriptDescription,",
" len(script) as ScriptLength,",
" Convert(varchar(64), HASHBYTES('SHA2_256',script), 2) as ScriptSHA256,",
" Inbuilt, Author, UpdatedBy, LastUpdated",
"from ValidationScripts",
"FOR JSON PATH, ROOT ('ValidationScripts')"
]
},
{
"Name": "DiscoveryScripts",
"TableName": "DiscoveryScripts",
"Query": [
"select ScriptID, ScriptName, ScriptDescription,",
" len(script) as ScriptLength,",
" Convert(varchar(64), HASHBYTES('SHA2_256',script), 2) as ScriptSHA256",
"from DiscoveryScripts",
"FOR JSON PATH, ROOT ('DiscoveryScripts')"
]
},
{
"Name": "SSHTemplateScripts",
"TableName": "SSHTemplateScripts",
"Query": [
"select TemplateScriptID, ScriptName,",
" len(script) as ScriptLength, ",
" Convert(varchar(64),HASHBYTES('SHA2_256',script),2) as ScriptSHA256",
"from SSHTemplateScripts",
"FOR JSON PATH, ROOT ('SSHTemplateScripts')"
]
},
{
"Name": "RemoteSessionCredentials",
"TableName": "RemoteSessionCredentials",
"Query": [
"Select rsc.*,",
" ( select rscacl.SecurityGroupID,",
" (select sg.SecurityGroupName",
" from SecurityGroups sg",
" where sg.SecurityGroupID = rscacl.SecurityGroupID) as SecurityGroupName,",
" rscacl.UserID, rscacl.AccessExpiresAt",
" from RemoteSessionCredentialsACL rscacl",
" where rscacl.CredentialID = rsc.CredentialID",
" for json AUTO",
" ) as ACL",
"from RemoteSessionCredentials rsc",
"for JSON PATH, ROOT ('RemoteSessionCredentials')"
]
},
{
"Name": "SecurityAdmins",
"TableName": "SecurityAdmins",
"Query": [
"SET NOCOUNT ON",
"DECLARE @Delim char = ':'",
"DECLARE @AdminRoles TABLE (RoleID INT, Role NVARCHAR(60))",
"INSERT INTO @AdminRoles VALUES ",
" -- ordered as shown in the UI",
" (1, 'Account Discovery'),",
" (2, 'Active Directory Domains'),",
" (3, 'Auditing'),",
" (4, 'Auditing Graphs'),",
" (5, 'Authorized Web Servers'),",
" (6, 'Backups'),",
" (7, 'Bad Passwords'),",
" (8, 'Browser Extension Settings'),",
" (45, 'Brute Force Blocked IPs'),",
" (9, 'Email Notification Groups'),",
" (10, 'Email Templates'),",
" (11, 'Emergency Access'),",
" (12, 'Encryption Keys'),",
" (13, 'Error Console'),",
" (14, 'Export All Passwords'),",
" (18, 'Feature Access'),",
" (15, 'Host Types & Operating Systems'),",
" (16, 'Images and Account Types'),",
" (17, 'License Information'),",
" (19, 'Password Folders'),",
" (20, 'Password Generator Policies'),",
" (21, 'Password Lists'),",
" (22, 'Password List Templates'),",
" (23, 'Password Strength Policies'),",
" (24, 'Privileged Account Credentials'),",
" (25, 'PowerShell Scripts'),",
" (42, 'Remote Session Management'),",
" (26, 'Reporting'),",
" (27, 'Security Administrators'),",
" (28, 'Security Groups'),",
" (29, 'System Settings'),",
" (30, 'User Accounts'),",
" (31, 'User Account Policies'),",
" (32, 'Site Locations'),",
" (33, 'PR Portal: Active Directory Domains'),",
" (34, 'PR Portal: Auditing'),",
" (35, 'PR Portal: Auditing Graphs'),",
" (43, 'PR Portal: Bad Passwords'),",
" (44, 'PR Portal: Password Policies'),",
" (36, 'PR Portal: Privileged Account Credentials'),",
" (37, 'PR Portal: Reporting'),",
" (38, 'PR Portal: Security Groups'),",
" (39, 'PR Portal: System Settings'),",
" (40, 'PR Portal: User Account Management'),",
" (41, 'PR Portal: Verification Policies')",
"",
"-- Inner select query inspired by SplitString function by Aaron Bertrand (https://stackoverflow.com/a/19935646/21124015), used under the terms of CC BY-SA 3.0.",
"SELECT *, ",
"(",
" SELECT COALESCE((SELECT Role FROM @AdminRoles WHERE RoleID=idx),'???') AS Role, value AS Enabled, Idx",
" FROM ",
" (",
" SELECT Value, idx = RANK() OVER (ORDER BY n)",
" FROM ",
" ( ",
" SELECT n = Number, ",
" Value = LTRIM(RTRIM(SUBSTRING(sa.roles, Number,",
" CHARINDEX(@Delim, sa.roles + @Delim, Number) - Number)))",
" FROM (SELECT Number = ROW_NUMBER() OVER (ORDER BY name)",
" FROM sys.all_objects) AS x",
" WHERE Number <= LEN(sa.roles)",
" AND SUBSTRING(@Delim + sa.roles, Number, LEN(@Delim)) = @Delim",
" ) as y",
" ) as z",
" ORDER BY Role",
" FOR JSON AUTO",
") as Roles2",
"FROM SecurityAdmins sa",
"FOR JSON PATH, ROOT ('SecurityAdmins')"
]
},
{
"Name": "SystemSettings",
"Tablename": "SystemSettings",
"MaskProperties": [
"Secret3",
"Secret4",
"NewVersionNo", // This value changes due to external factors, which makes it a distraction.
"NewBuildNo", // This value changes due to external factors, which makes it a distraction.
"LastUpdateCheck" // This value changes all the time, which makes it a distraction.
]
},
{
"Name": "APIkeys",
"TableName": "APIkeys"
},
{
"Name": "UserAccountPolicies",
"Tablename": "UserAccountPolicies"
},
{
"Name": "SiteLocations",
"TableName": "SiteLocations",
"MaskProperties": [
"InTransitKey"
]
},
{
"Name": "PR_ADDomains",
"TableName": "PR_ADDomains"
},
{
"Name": "PR_BadPasswords",
"TableName": "PR_BadPasswords"
},
{
"Name": "PR_PasswordPolicies",
"TableName": "PR_PasswordPolicies",
"Query": [
"SELECT pp.*,",
" ( SELECT ppacl.SecurityGroupID,",
" (SELECT sg.SecurityGroupName",
" FROM PR_SecurityGroups sg",
" WHERE sg.SecurityGroupID = ppacl.SecurityGroupID) AS SecurityGroupName,",
" ppacl.UserID",
" FROM PR_PasswordPoliciesACL ppacl",
" WHERE ppacl.PasswordPolicyID = pp.PasswordPolicyID",
" FOR JSON AUTO",
" ) AS ACL",
"FROM PR_PasswordPolicies pp",
"FOR JSON PATH, ROOT ('PR_PasswordPolicies')"
]
},
{
"Name": "PR_PrivilegedAccounts",
"TableName": "PR_PrivilegedAccounts",
"MaskProperties": [
"Password"
]
},
{
"Name": "PR_Questions",
"TableName": "PR_Questions"
},
{
"Name": "PR_ResetReasons",
"TableName": "PR_ResetReasons"
},
{
"Name": "PR_SystemSettings",
"TableName": "PR_SystemSettings"
},
{
"Name": "PR_VerificationPolicies",
"TableName": "PR_VerificationPolicies",
"Query": [
"SELECT vp.*,",
" ( SELECT vpacl.SecurityGroupID,",
" (SELECT sg.SecurityGroupName",
" FROM PR_SecurityGroups sg",
" WHERE sg.SecurityGroupID = vpacl.SecurityGroupID) AS SecurityGroupName,",
" vpacl.UserID",
" FROM PR_VerificationPoliciesACL vpacl",
" WHERE vpacl.VerificationPolicyID= vp.VerificationPolicyID",
" FOR JSON AUTO",
" ) AS ACL",
"FROM PR_VerificationPolicies vp",
"FOR JSON PATH, ROOT ('PR_VerificationPolicies')"
]
}
]