check_sys/core/plugins/postfix.py
2023-09-10 18:08:48 +02:00

90 lines
3.1 KiB
Python

#!/usr/bin/env python3
import re
from audit.system.plugins.postfix.postfix import postfix
class Postfix:
def __init__(self, arguments):
self._objects = postfix()
self._reports = dict()
self._postfix_file = arguments["postfix_file"]
# Create the report
self._constructReports()
# Report
self._reports["filename"] = self._postfix_file
def runAudit(self):
print("Running test for postfix")
self._runParsing()
def getReports(self) -> dict:
return self._reports
def _runParsing(self):
# Check if the file exist
try:
with open(self._postfix_file, 'rb') as fdata:
self._parseFile(fdata)
except FileNotFoundError:
print("No postfix file found. Add into the report")
pass
def _parseFile(self, fdata):
data = fdata.read()
lines = data.splitlines()
for line in lines:
line = line.decode('utf-8')
for obj in self._objects:
grDirective = re.search(
f"^({obj['flag']})",
line
)
if grDirective:
res = False
if not isinstance(obj['value'], list):
obj['value'] = [obj['value']]
for value in obj['value']:
res = self._check_value_exist(line, value)
if res:
break
if res:
self._reports["postfix"][obj['flag']] = dict()
self._reports["postfix"][obj['flag']]["result"] = "success"
self._reports["postfix"][obj['flag']]["description"] = obj['description']
self._reports["postfix"][obj['flag']]["flagFound"] = line
else:
self._reports["postfix"][obj['flag']] = dict()
self._reports["postfix"][obj['flag']]["result"] = "failed"
self._reports["postfix"][obj["flag"]]["recommand_value"] = obj["value"]
self._reports["postfix"][obj['flag']]["description"] = obj['description']
self._reports["postfix"][obj['flag']]["flag"] = obj['flag']
def _check_value_exist(self, line, value) -> bool:
if '[' in value:
value = value.replace('[', '\[')
if ']' in value:
value = value.replace(']', '\]')
grValue = re.search(value, line)
if grValue:
return True
return False
def _constructReports(self):
"""
Construct dictionary for result of the tests
Each entry contains:
Key:
- filename: filename of the test
- line: line of the test
- parse: Display the line where the vulnerabilites has been found
- description: description of the vulnerability
- level: high, medium or low
"""
self._reports['postfix'] = dict()