forked from elastic/detection-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_compress_sensitive_files.py
34 lines (28 loc) · 1.3 KB
/
linux_compress_sensitive_files.py
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
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
# Name: Compression of sensitive files
# RTA: linux_compress_sensitive_files.py
# Description: Uses built-in commands for *nix operating systems to compress known sensitive
# files, such as etc/shadow and etc/passwd
from . import common
@common.requires_os(common.LINUX)
def main():
common.log("Compressing sensitive files")
files = ['totally-legit.tar', 'official-business.zip', 'expense-reports.gz']
# we don't want/need these to actually work, since the rule is only looking for command line, so no need for sudo
commands = [
['tar', '-cvf', files[0], '/etc/shadow'],
['zip', files[1], '/etc/passwd'],
['gzip', '/etc/group', files[2]]
]
for command in commands:
try:
common.execute(command)
except OSError as exc:
# command doesn't exist on distro - the rule only needs one to trigger
# also means we will eventually need to explore per distro ground truth when we expand as counts will vary
common.log(str(exc))
if __name__ == '__main__':
main()