-
-
Save Lyceris-chan/b80252fa43dc58dd7d78b0789bc60f3d to your computer and use it in GitHub Desktop.
Selinux Denial Fixer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Denials Input : denials.txt | Fix Output : fixdenials.txt | |
import re | |
denres = "" | |
denlist = [] | |
with open("denials.txt") as deninput: | |
denlines = deninput.readlines() | |
regex = {} | |
regex[0] = re.compile(r"scontext=u:r:(.*?):", re.IGNORECASE) | |
regex[1] = re.compile(r"tcontext=.*:(.*?):", re.IGNORECASE) | |
regex[2] = re.compile(r"tclass=(.*?) ", re.IGNORECASE) | |
regex[3] = re.compile(r"{ .*? }", re.IGNORECASE) | |
for text in denlines: | |
if "scontext" not in text : | |
continue | |
denialfix = "allow " | |
denialfix += f"{re.findall(regex[0], text)[0]} " | |
denialfix += f"{re.findall(regex[1], text)[0]}:" | |
denialfix += f"{re.findall(regex[2], text)[0]} " | |
denialfix += f"{re.findall(regex[3], text)[0]};" | |
if denialfix in denlist: | |
continue | |
denres += f"{denialfix}\n" | |
denlist.append(denialfix) | |
fixfile = open("fixdenials.txt", "w") | |
fixfile.write(denres) | |
fixfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment