2023-03-01 16:05:35 +00:00
|
|
|
-- Indicative of stored GCP service account keys just sitting around unencrypted
|
|
|
|
--
|
|
|
|
-- tags: persistent state filesystem
|
|
|
|
-- platform: darwin
|
|
|
|
SELECT
|
|
|
|
file.path,
|
|
|
|
file.size,
|
2023-05-17 21:52:55 +00:00
|
|
|
file.btime,
|
|
|
|
file.ctime,
|
|
|
|
file.mtime,
|
2023-03-01 16:05:35 +00:00
|
|
|
magic.data,
|
|
|
|
hash.sha256,
|
2023-03-14 20:05:16 +00:00
|
|
|
u.username,
|
2023-03-01 16:05:35 +00:00
|
|
|
ea.value AS url
|
|
|
|
FROM
|
|
|
|
mdfind
|
2023-03-14 20:05:16 +00:00
|
|
|
JOIN file ON mdfind.path = file.path
|
2023-03-01 16:05:35 +00:00
|
|
|
LEFT JOIN users u ON file.uid = u.uid
|
|
|
|
LEFT JOIN hash ON mdfind.path = hash.path
|
2023-03-03 12:24:42 +00:00
|
|
|
LEFT JOIN extended_attributes ea ON mdfind.path = ea.path
|
|
|
|
AND ea.key = 'where_from'
|
2023-03-01 16:05:35 +00:00
|
|
|
LEFT JOIN magic ON mdfind.path = magic.path
|
|
|
|
LEFT JOIN signature ON mdfind.path = signature.path
|
|
|
|
WHERE
|
|
|
|
mdfind.query = "kMDItemFSName == '*.json'"
|
2023-03-06 20:11:11 +00:00
|
|
|
AND (
|
|
|
|
file.filename LIKE "%-%-%.json"
|
2023-03-14 20:05:16 +00:00
|
|
|
OR file.filename LIKE '%service%.json'
|
|
|
|
OR file.filename LIKE '%acct%.json'
|
|
|
|
OR file.filename LIKE '%key%.json'
|
|
|
|
OR file.filename LIKE '%account%.json'
|
|
|
|
OR file.filename LIKE '%-sa.json'
|
2023-03-06 20:11:11 +00:00
|
|
|
OR file.filename LIKE 'sa%.json'
|
|
|
|
OR file.filename LIKE '%s%r%v%acc%t%json'
|
|
|
|
OR file.filename LIKE '%prod.json'
|
|
|
|
OR file.filename LIKE 'prod%.json'
|
|
|
|
)
|
2023-03-04 17:20:53 +00:00
|
|
|
AND file.size BETWEEN 2311 AND 2385 -- Don't alert on tokens that begin with the username-, as they may be personal
|
|
|
|
AND NOT INSTR(file.filename, CONCAT (u.username, "-")) == 1 -- Don't alert on tokens that begin with the users full name and a dash
|
2023-03-14 20:05:16 +00:00
|
|
|
AND NOT (
|
|
|
|
LENGTH(u.username) > 4
|
2023-03-16 21:29:11 +00:00
|
|
|
AND INSTR(file.filename, SUBSTR(u.username, 3, 8)) > 0
|
2023-03-14 20:05:16 +00:00
|
|
|
)
|
2023-03-01 16:05:35 +00:00
|
|
|
AND NOT INSTR(
|
|
|
|
file.filename,
|
|
|
|
REPLACE(LOWER(TRIM(u.description)), " ", "-")
|
2023-03-14 20:05:16 +00:00
|
|
|
) == 1
|
|
|
|
-- Common locations of test or demo keys
|
2023-05-11 15:29:55 +00:00
|
|
|
AND NOT file.filename = 'keys.json'
|
|
|
|
AND NOT file.directory = "/Users/Shared/LGHUB"
|
2023-03-16 21:29:11 +00:00
|
|
|
AND NOT file.directory LIKE '%/pkg/%'
|
2023-03-04 17:20:53 +00:00
|
|
|
AND NOT file.directory LIKE '%/go/src/%'
|
2023-03-06 20:11:11 +00:00
|
|
|
AND NOT file.directory LIKE '%/pkg/mod/%'
|
2023-03-04 17:20:53 +00:00
|
|
|
AND NOT file.directory LIKE '%/aws-sdk/apis'
|
|
|
|
AND NOT file.directory LIKE '%/mock-infras/%'
|
2023-03-06 20:11:11 +00:00
|
|
|
AND NOT file.directory LIKE '%/testdata%'
|
2023-03-16 21:29:11 +00:00
|
|
|
AND NOT file.directory LIKE '%/conformance/%'
|
2023-03-14 20:05:16 +00:00
|
|
|
AND NOT file.directory LIKE '%/third_party/%'
|
|
|
|
AND NOT file.directory LIKE '%/generated/%'
|
2023-03-17 14:15:07 +00:00
|
|
|
AND NOT file.directory LIKE '%/output/%'
|
|
|
|
AND NOT file.directory LIKE '%/tests%'
|
|
|
|
AND NOT file.directory LIKE '%/validation%'
|
|
|
|
AND NOT file.directory LIKE '%/data/%'
|
2023-03-14 20:05:16 +00:00
|
|
|
AND NOT file.directory LIKE '%/json%'
|
2023-03-17 14:15:07 +00:00
|
|
|
AND NOT file.directory LIKE '%/specs%'
|
2023-03-04 17:20:53 +00:00
|
|
|
AND NOT file.directory LIKE '%/schemas'
|
|
|
|
AND NOT file.directory LIKE '/Users/%/Library/Application Support/%'
|
2023-03-14 20:05:16 +00:00
|
|
|
AND NOT file.directory LIKE '%demo'
|
|
|
|
AND NOT file.filename LIKE 'ntia-conformance-%'
|
2023-03-17 14:15:07 +00:00
|
|
|
AND NOT file.filename LIKE '%-test.json'
|
|
|
|
AND NOT file.filename LIKE '%package%'
|
|
|
|
AND NOT file.filename LIKE '%expected%'
|
|
|
|
AND NOT file.filename LIKE '%.pom.%'
|
|
|
|
AND NOT file.filename LIKE '%latest%'
|
|
|
|
AND NOT file.filename LIKE '%2022%'
|
|
|
|
AND NOT file.filename LIKE '%2023%'
|
2023-05-03 20:28:00 +00:00
|
|
|
AND NOT file.filename LIKE 'host-project-%'
|
2023-03-14 20:05:16 +00:00
|
|
|
AND NOT file.filename LIKE '%spdx%'
|
2023-03-16 21:29:11 +00:00
|
|
|
AND NOT file.filename LIKE '%-v1%'
|
2023-05-03 20:28:00 +00:00
|
|
|
AND NOT file.filename LIKE 'libopenblas-%'
|
2023-03-14 20:05:16 +00:00
|
|
|
-- Well known demo keys
|
|
|
|
AND NOT hash.sha256 IN (
|
2023-04-27 16:00:08 +00:00
|
|
|
'11ffc5141b4b0071c0796914deef68d012c4f4c289931c5587fe89d7d6dca0a1',
|
2023-03-14 20:05:16 +00:00
|
|
|
'2d330d059f4af4d314a85418fb031ee628f41dcf3e31fbce46858e52e73180c4',
|
2023-04-27 16:00:08 +00:00
|
|
|
'4b4be8c1bc7e3bc7ea1f02932a024466db5faf3eaad885cf31ac7383484b1b1c',
|
|
|
|
'6e55f3eccad59a615189c82cbcbd1133ce94509f7c5d42e3e7fbd00e65f0731f',
|
2023-05-02 19:25:36 +00:00
|
|
|
'e99b4e6dfbbefa19c9ec9c82bb0c3445a443702f960c2a05f882bb5577a59ef8',
|
2023-05-23 15:31:37 +00:00
|
|
|
'421899fb9bfa0252ce7921969339918a5bbacbc7b9cd500e03a88f9c4e33bae4',
|
2023-04-27 16:00:08 +00:00
|
|
|
'81bce2313cd00ffc42303fbf7c08e4d068fccc9c0076867903ef94616d795e12',
|
2023-03-14 20:05:16 +00:00
|
|
|
'8d740893c1f9163ddfd8c193d9a95caf15da3740b42f2739c4b107ad12661809',
|
|
|
|
'998ddcb7d1a7c2931c8546576873e47b399f23cef719227052f245c8240c6528',
|
|
|
|
'af1a2f8e9d581bb1504e3d8801d15d962fdf12ee7ebcf2bb9c475c8b92da6472',
|
|
|
|
'b68896dc8e8c23ade371cf8b5c9d25853d81b4cfa5baa2bc0200d9242a903d80',
|
2023-04-27 16:00:08 +00:00
|
|
|
'bc4c0ad21d79fea9050e75e80f13dd54bfdc867236342ede901d15d815f31988',
|
2023-03-14 20:05:16 +00:00
|
|
|
'cea85342377ef1bce115629c3d9d3ec405964a43545805c9f7ace98940aa0be2',
|
2023-05-03 20:28:00 +00:00
|
|
|
'a0f925d91d2ae1d38c13305572b2bf027e09f39e8bea575d55e8fcd5f3bf8b32',
|
2023-04-27 16:00:08 +00:00
|
|
|
'ef2c928c69403e023a332002d8c5c430e1022850b12f834563f6aec111d99f14'
|
2023-03-04 17:20:53 +00:00
|
|
|
)
|
2023-03-03 12:24:42 +00:00
|
|
|
GROUP BY
|
|
|
|
file.path
|