-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdacl_check.py
executable file
·70 lines (54 loc) · 1.87 KB
/
dacl_check.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import sys
import os
from time import sleep
from subprocess import Popen,PIPE
accesschk = 'C:\\SysinternalsSuite\\accesschk.exe'
if not os.path.exists(accesschk):
print "get accesschk from sysinternals and place in %s" % accesschk
exit(1)
def access_check(name, flags=[]):
args = [accesschk,'-q']
args.extend(flags)
args.append(name)
proc = Popen(args, shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
log.write(stdout + "\n")
# log.write('"%s","%s","%s"\r\n' %
# (name,
# ":".join( stdout.replace('"','\\"').split('\r\n')[1:]),
# stderr.replace('\r\n',':')))
#log = open('dacl_check.csv', 'w')
log = open('dacl_check.log', 'w')
#log.write('"File","stdout","stderr"\r\n')
if len(sys.argv) < 2:
print "usage: %s name_of_regshot_file" % sys.argv[0]
sys.exit(1)
fd = open(sys.argv[1])
buff = fd.read(1024) # fd.read() works on Linux, seems to be buggy
# on this python on Windows
diff = ""
while buff:
diff += buff
buff = fd.read(1024)
diff = diff.split('----------------------------------')
diff = dict( (diff[x].strip().split(':')[0],
diff[x+1].strip().split('\n'))
for x in xrange(1,len(diff), 2)
if diff[x+1].strip() )
if 'Keys added' in diff:
keys_to_check = diff['Keys added']
for k in ['Values added','Values Added', 'Values modified']:
if k in diff:
keys_to_check.extend(okv[0]
for okv in ( kv.split(':') for kv in diff[k] )
if len(okv) > 1)
files_to_check = []
for k in ['Files added', 'Files [attributes?] modified', 'Folders added']:
if k in diff:
files_to_check.extend(diff[k])
for f in files_to_check:
access_check(f)
for k in keys_to_check:
access_check(k, ['-k'])
log.flush()