Update project

This commit is contained in:
gbucchino 2023-06-05 16:39:18 +02:00
parent 96342a2b2c
commit 6cb4cacaf9
2 changed files with 61 additions and 29 deletions

1
.gitignore vendored

@ -1,2 +1,3 @@
__pycache__/ __pycache__/
__pycache__/** __pycache__/**
**.swp

@ -5,7 +5,7 @@ from parsing.base import ParsingBase
class Parsing(ParsingBase): class Parsing(ParsingBase):
def __init__(self, objects, audit): def __init__(self, objects, audit):
self._parsing = dict() self._parsing = dict()
self._results = dict() self._reports = dict()
self._objects = objects self._objects = objects
self._audit = audit self._audit = audit
@ -24,35 +24,61 @@ class Parsing(ParsingBase):
self._constructResults(filename='/etc/sysctl.conf') self._constructResults(filename='/etc/sysctl.conf')
resultsFlag = 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']] = list()
print(resultsFlag)
for line in lines: for line in lines:
line = line.decode("utf-8") line = line.decode("utf-8")
for obj in self._objects['sysctl']: for obj in self._objects['sysctl']:
result = self._parsingFile(line, obj) result = self._parsingFile(line, obj, resultsFlag)
if len(result) == 0: if result:
pass print(resultsFlag[obj['flag']][
# If the flag is found len(resultsFlag[obj['flag']]) - 1:
else: len(resultsFlag[obj['flag']])
# And if the current value is not setted corectly for the vulnerability ])
print(result) # If not exist, we recommand to put the flag
#if len(result) == 0:
self._results[obj['flag']].append({ # # print("Not find")
'lineNumber': numLines, # pass
'value': obj['value'], ## If the flag is found
'audit': 'failed' # Or success #else:
}) # # And if the current value is not setted corectly for the vulnerability
# print(result)
if result['value'] != result['current_value']: #
print(f"You must change the value to {obj['value']} for fixing the vulnerabilities") # self._reports[obj['flag']].append({
# 'lineNumber': numLines,
# 'value': obj['value'],
# 'audit': 'failed' # Or success
# })
#
# #if result['value'] != result['current_value']:
# # print(f"You must change the value to {obj['value']} for fixing the vulnerabilities")
numLines += 1 numLines += 1
print(self._results) print(self._reports)
def _parsingFile(self, line, obj) -> dict: # 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
print("")
for entry in resultsFlag:
print(entry)
print(resultsFlag[entry])
# We can generate the report
def _parsingFile(self, line, obj, resultsFlag) -> bool:
""" """
This function parse the line and try to find the item in it This function parse the line and try to find the item in it
""" """
result = dict() result = bool()
groupLine = re.search(obj['flag'], line) groupLine = re.search(obj['flag'], line)
if groupLine: if groupLine:
@ -61,15 +87,20 @@ class Parsing(ParsingBase):
sLine = line.split('=') sLine = line.split('=')
flag = sLine[0] flag = sLine[0]
value = int(sLine[1].strip('')) value = int(sLine[1].strip(''))
result = True
#print(sLine) #print(sLine)
result['found'] = flag resultsFlag[flag].append({
result['current_value'] = value 'current_value': value,
result['value'] = obj['value'] 'value': obj['value']
})
#result['found'] = flag
#result['current_value'] = value
#result['value'] = obj['value']
if value != obj['value']: #if value != obj['value']:
print("Need to change the value") # print("Need to change the value")
print(sLine) # print(sLine)
return result return result
@ -84,11 +115,11 @@ class Parsing(ParsingBase):
- description: description of the vulnerabilities - description: description of the vulnerabilities
- level: high, medium or low - level: high, medium or low
""" """
self._results['filename'] = filename self._reports['filename'] = filename
for sysctl in self._objects['sysctl']: for sysctl in self._objects['sysctl']:
self._results[sysctl['flag']] = list() self._reports[sysctl['flag']] = list()
print(self._results) print(self._reports)
print("") print("")
def getResults(self) -> dict: def getResults(self) -> dict: