Update parsing and move files

This commit is contained in:
gbucchino
2023-06-06 16:55:22 +02:00
parent 9a4c845f6d
commit 7e2c6b3ee8
8 changed files with 66 additions and 17 deletions
+20 -11
View File
@@ -24,46 +24,55 @@ class Parsing(ParsingBase):
self._constructResults(filename='/etc/sysctl.conf')
resultsFlag = dict()
vulnerabilityFound = dict()
# I create an array which contains all flag we need to find
# After that, for each data, I put the number of occurence I found.
# If the array is empty, no entry found for a flag, otherwise, we check the value
for obj in self._objects['sysctl']:
resultsFlag[obj['flag']] = dict()
resultsFlag[obj['flag']]['recommand_value'] = obj['value']
resultsFlag[obj['flag']]['occurence'] = 0
vulnerabilityFound[obj['flag']] = dict()
vulnerabilityFound[obj['flag']]['recommand_value'] = obj['value']
vulnerabilityFound[obj['flag']]['occurence'] = 0
for item in obj:
vulnerabilityFound[obj['flag']][item] = obj[item]
print("")
for line in lines:
line = line.decode("utf-8")
for obj in self._objects['sysctl']:
result = self._parsingFile(line, obj, resultsFlag)
result = self._parsingFile(line, obj, vulnerabilityFound)
if result:
resultsFlag[obj['flag']]['lineNumber'] = numLines
resultsFlag[obj['flag']]['occurence'] += 1
vulnerabilityFound[obj['flag']]['lineNumber'] = numLines
vulnerabilityFound[obj['flag']]['occurence'] += 1
numLines += 1
# Now, we can check if the value is specified or not
# And check if the flag is specified and need to put on the sysctl config
for entry in resultsFlag:
obj = resultsFlag[entry]
for entry in vulnerabilityFound:
obj = vulnerabilityFound[entry]
if obj['occurence'] > 0:
print(entry)
print(obj)
if obj['current_value'] != obj['recommand_value']:
self._reports[entry]['result'] = "failed"
self._reports[entry]['message'] = \
f"You specify this value {obj['current_value']}" \
", you should use this value {obj['recommand_value']}"
else:
self._reports[entry]['result'] = "success"
else:
# No find the flag, we recommand to enable it
self._reports[entry]['message'] = ""
# We can generate the report
print(self._reports)
print("")
print(vulnerabilityFound)
def _parsingFile(self, line, obj, resultsFlag) -> bool:
def _parsingFile(self, line, obj, vulnerabilityFound) -> bool:
"""
This function parse the line and try to find the item in it
"""
@@ -77,7 +86,7 @@ class Parsing(ParsingBase):
flag = sLine[0].strip()
value = int(sLine[1].strip())
resultsFlag[flag]['current_value'] = value
vulnerabilityFound[flag]['current_value'] = value
result = True