-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenrules.py
executable file
·51 lines (40 loc) · 1.38 KB
/
genrules.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
#coding=utf-8
# Python 2.7
# Script Description:
# Linux audit.rules generate
# -p rwxa
# Specified trigger condition:
# r: read,w: write; x: exec; a: attr
#
# Author: Jack Liu
# DateTime: 209-01-08 18:21
#
###################################
import os, sys, json, time
sys.dont_write_bytecode = True
def gen_auditrules(app_sign = ''):
#real work path
real_work_path=os.getcwd()
#check configuration format
fconf = open(real_work_path+"/config/audit_rules_conf.json", "r")
conf = json.loads(fconf.read())
fconf.close()
current_time=time.strftime("%Y/%m/%d %H:%M:%S")
custom_audit_rules="#### " + app_sign + " Audit Rules Created By DataTime: "+current_time+" ####\n\n"
for item in conf:
custom_audit_rules+="\n#audit rule block: "+item+"\n\n"
for item_child in conf[item]:
custom_audit_rules+="-w "+item_child+" "+conf[item][item_child]+"\n"
custom_audit_rules+="#### END ####\n"
#read os defaut configs
fos_default=open(real_work_path+"/config/audit.rules.default", "r")
audit_rules_default=fos_default.read()
fos_default.close()
#write rules file
frules = open(real_work_path+"/gen_audit_rules/audit.rules", "w")
#merge rules
audit_rules=audit_rules_default+custom_audit_rules
frules.write(audit_rules)
frules.close()
return audit_rules