Auditing apache indexes
This commit is contained in:
+25
-24
@@ -180,7 +180,7 @@ class Apache:
|
||||
self._reports["indexes"]["audit"] = True
|
||||
|
||||
with open(path, 'rb') as fdata:
|
||||
self._reports["indexes"]["indexes"] = \
|
||||
self._reports["indexes"] = \
|
||||
self._parsingApacheConfig(fdata)
|
||||
else:
|
||||
self._reports["indexes"]["audit"] = False
|
||||
@@ -195,10 +195,11 @@ class Apache:
|
||||
# Each entry in the variable directories contains a list
|
||||
# of <Directory> with all data in it
|
||||
# We create another entry when a found </Directory>
|
||||
directories = list()
|
||||
directories = dict()
|
||||
directoryFound = False
|
||||
index = 0
|
||||
optsFound = list()
|
||||
currentPath = None
|
||||
|
||||
for line in lines:
|
||||
line = line.decode('utf-8')
|
||||
@@ -208,53 +209,53 @@ class Apache:
|
||||
grDirectory = re.search("<Directory ", line, re.IGNORECASE)
|
||||
if grDirectory:
|
||||
directoryFound = True
|
||||
directories.append(list())
|
||||
directories[index].append(line)
|
||||
currentPath = self._getDirectoryPath(line)
|
||||
directories[currentPath] = list()
|
||||
directories[currentPath].append(line)
|
||||
else:
|
||||
#directory.append(line)
|
||||
directories[index].append(line)
|
||||
directories[currentPath].append(line)
|
||||
grDirectory = re.search("</Directory>", line, re.IGNORECASE)
|
||||
if grDirectory:
|
||||
directoryFound = False
|
||||
index += 1
|
||||
currentPath = None
|
||||
|
||||
# We will find if we find an indexes option
|
||||
for d in directories:
|
||||
for entry in d:
|
||||
# We get the directory path
|
||||
path = self._getDirectoryPath(entry)
|
||||
report["directories"][path] = dict()
|
||||
for directory in directories:
|
||||
report["directories"][directory] = dict()
|
||||
report["directories"][directory]["options"] = list()
|
||||
|
||||
# Try to find the Option flag
|
||||
for line in directories[directory]:
|
||||
grFlag = re.search(
|
||||
f"{self._indexes['flag']}",
|
||||
entry,
|
||||
line,
|
||||
re.IGNORECASE
|
||||
)
|
||||
if grFlag:
|
||||
for opt in self._indexes['options']:
|
||||
grOption = re.search(
|
||||
f"-{opt}",
|
||||
entry,
|
||||
line,
|
||||
re.IGNORECASE
|
||||
)
|
||||
if grOption:
|
||||
optsFound.append(opt)
|
||||
|
||||
report["audit"] = True
|
||||
report["options"] = dict()
|
||||
if len(optsFound) == len(self._indexes['options']):
|
||||
report["result"] = "success"
|
||||
else:
|
||||
report["result"] = "failed"
|
||||
for opt in self._indexes["options"]:
|
||||
if opt not in optsFound:
|
||||
report["options"][opt] = f"{opt} is not removed. You should disable it"
|
||||
# We can check if you found the options
|
||||
if len(optsFound) == len(self._indexes['options']):
|
||||
report["directories"][directory]["result"] = "success"
|
||||
else:
|
||||
report["directories"][directory]["result"] = "failed"
|
||||
for opt in self._indexes["options"]:
|
||||
if opt not in optsFound:
|
||||
report["directories"][directory]["options"].append(
|
||||
f"{opt} is not removed. You should disable it"
|
||||
)
|
||||
|
||||
report["audit"] = True
|
||||
report["description"] = self._indexes["description"]
|
||||
report["level"] = self._indexes["level"]
|
||||
report["recommand_value"] = self._indexes["recommand_value"]
|
||||
print(report)
|
||||
return report
|
||||
|
||||
def _getDirectoryPath(self, line) -> str:
|
||||
|
||||
+1
-4
@@ -47,16 +47,13 @@ def generateHtmlReport(path, data):
|
||||
"apache-virtualhost"
|
||||
)
|
||||
if data['system']['apache']['signature']['audit']:
|
||||
print(dataJinja2['apache']['signature'])
|
||||
_generateAccordion(
|
||||
dataJinja2["apache"]["signature"]["signature"],
|
||||
"apache-signature"
|
||||
)
|
||||
print("")
|
||||
if data['system']['apache']['indexes']['audit']:
|
||||
print(dataJinja2['apache']['indexes'])
|
||||
_generateAccordion(
|
||||
dataJinja2["apache"]["indexes"]["indexes"],
|
||||
dataJinja2["apache"]["indexes"]["directories"],
|
||||
"apache-indexes"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user