Parsing postfix

This commit is contained in:
2023-09-10 18:08:48 +02:00
parent 3cd25dce85
commit 582b85bb07
14 changed files with 281 additions and 77 deletions
+67
View File
@@ -0,0 +1,67 @@
#!/usr/bin/env python3
import re
from os import listdir
from os.path import isdir
from audit.system.plugins.apache.apache import apache
class Apache:
def __init__(self, arguments):
self._objects = apache()
self._reports = dict()
self._apache_directory = arguments["apache_directory"]
# Create the report
self._constructReports()
# Report
self._reports["directory"] = self._apache_directory
def runAudit(self):
print("Running test for Apache")
self._runParsing()
def getReports(self) -> dict:
return self._reports
def _runParsing(self):
# Check if the file exist
path = f"{self._apache_directory}/sites-available"
if isdir(self._apache_directory):
for site in listdir(path):
with open(f"{path}/{site}", 'rb') as f:
self._parseFile(f)
else:
self._reports["apache"]["test"] = "No directory found"
def _parseFile(self, fdata):
data = fdata.read()
lines = data.splitlines()
for line in lines:
line = line.decode('utf-8')
# check if SSL is enable for the VirtualHost
grSSLEngine = re.search("SSLEngine on", line)
if grSSLEngine:
print(line)
def _check_value_exist(self, line, value) -> bool:
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['apache'] = dict()
+89
View File
@@ -0,0 +1,89 @@
#!/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()
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
from audit.system.plugins.sysctl.parsing import Parsing
from audit.system.plugins.sysctl.sysctl import sysctl
class Sysctl:
def __init__(self, args):
self._objects = dict()
self._reports = dict()
self._audit = list()
self._audit.append({
'audit': 'file',
'value': args["sysctl_file"],
})
self._audit.append({
'audit': 'process',
'value': 'sysctl -a',
})
self._sysctl()
self._parsing = Parsing(self._objects, self._audit)
def _sysctl(self):
self._objects = sysctl()
def runAudit(self):
print("Running test for sysctl")
self._parsing.runParsing()
self._reports = self._parsing.getResults()
def getReports(self) -> dict:
return self._reports