This repository has been archived by the owner on Jun 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoring.py
executable file
·62 lines (56 loc) · 1.92 KB
/
scoring.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
#!/usr/bin/python3
import subprocess, platform, fnmatch, os, time
# Search linux system starting at specified root location for file matching
# given pattern
def linux_search(root, pattern):
matches = []
for root, dirs, files, in os.walk(root):
for filename in fnmatch.filter(files, pattern):
matches.append(os.path.join(root, filename))
return matches
# Strip name from each ownership.txt file listed in matches
# Return list of "owners"
def get_owners(matches):
owners = []
for match in matches:
file = open(match, 'r')
owner = file.read().strip()
if owner and not owner.isspace():
owners.append(owner)
return owners
# Check for ownership.txt files and for running services
# Status list is packaged as tuples to send to the server
def run_check():
status = []
if system == 'Linux':
output = str(subprocess.check_output(['ps', '-A']))
if 'httpd' in output:
print("Httpd is running!")
status.append(('httpd', 'on'))
else:
print("Httpd is down...")
status.append(('httpd', 'off'))
if 'sshd' in output:
print("SSH is running!")
status.append(('ssh', 'on'))
else:
print("SSH is down...")
status.append(('ssh', 'off'))
owners = []
owners.extend(get_owners(linux_search('/home', 'ownership.txt')))
return status,owners
# Lists running processes for now, but will have same functionality as Linux case
elif system == 'Windows':
cmd = 'WMIC PROCESS get Caption,Commandline,Processid'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
for line in proc.stdout:
print(line)
system = platform.system()
# List OS
print(system + ' system')
# Loop every 30 seconds
while True:
status, owners = run_check()
print(status)
print(owners)
time.sleep(30)