Skip to content

Commit

Permalink
Added ability of output to same directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexer125 committed Apr 29, 2020
1 parent d94d8d2 commit fe32c76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
Binary file modified out/production/SELinux Denials tool/com/dexer125/Main.class
Binary file not shown.
40 changes: 25 additions & 15 deletions src/com/dexer125/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@ public static void main(String[] args) {
String tcontext;
String tclass;
String output;
String filename;
String answer;
int fileNameIndex;
int count = 0;

//Ask for paths
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the path to log file: ");
path = scanner.nextLine();
System.out.println("Enter the output path: ");
outPath = scanner.nextLine();
System.out.println("Would you like to save output into same path? y/n");
answer = scanner.nextLine();
if (answer.equals("y")){
fileNameIndex = path.lastIndexOf("/");
filename = path.substring(fileNameIndex+1, path.length());
outPath = path.replace(filename, "");
}
else if (answer.equals("n")){
System.out.println("Enter the output path: ");
outPath = scanner.nextLine();
}
else {
System.out.println("Wrong answer.");
return;
}

// Make sure that "/" is always at the end of the path
if (!outPath.endsWith("/")){
Expand All @@ -46,8 +62,6 @@ public static void main(String[] args) {
tclass = line.substring(line.indexOf("tclass=")+7, line.indexOf("permissive"));
output = "allow " + scontext + " " + tcontext + ":" + tclass + command + ";";

System.out.println(output);

writer.write(output);
count++;
writer.newLine();
Expand All @@ -63,8 +77,6 @@ else if (line.contains("avc: denied") && line.contains("tcontext=u:r:") && !line
tclass = line.substring(line.indexOf("tclass=")+7, line.indexOf("permissive"));
output = "allow " + scontext + " " + tcontext + ":" + tclass + command + ";";

System.out.println(output);

writer.write(output);
count++;
writer.newLine();
Expand All @@ -79,8 +91,6 @@ else if (line.contains("avc: denied")&& line.contains("tcontext=u:r:") && line.c
tclass = line.substring(line.indexOf("tclass=")+7, line.indexOf("permissive"));
output = "allow " + scontext + " " + tcontext + ":" + tclass + command + ";";

System.out.println(output);

writer.write(output);
count++;
writer.newLine();
Expand All @@ -94,8 +104,6 @@ else if (line.contains("avc: denied")&& line.contains("tcontext=u:object_r:") &&
tclass = line.substring(line.indexOf("tclass=")+7, line.indexOf("permissive"));
output = "allow " + scontext + " " + tcontext + ":" + tclass + command + ";";

System.out.println(output);

writer.write(output);
count++;
writer.newLine();
Expand All @@ -114,7 +122,6 @@ else if (line.contains("avc: denied")&& line.contains("tcontext=u:r:") && line.c
output = output.replace(output.substring(output.indexOf(":s0:"), output.indexOf(";")+1), "");
output = output + ":" + tclass + command + ";";
}
System.out.println(output);

writer.write(output);
count++;
Expand All @@ -133,7 +140,6 @@ else if (line.contains("avc: denied")&& line.contains("tcontext=u:object_r:") &&
output = output.replace(output.substring(output.indexOf(":s0:"), output.indexOf(";")+1), "");
output = output + ":" + tclass + command + ";";
}
System.out.println(output);

writer.write(output);
count++;
Expand All @@ -155,10 +161,12 @@ else if (line.contains("avc: denied")&& line.contains("tcontext=u:object_r:") &&
if (count == 0){
System.out.println("No denials in log file, check if your kernel supports audit logging.");
File tempFile = new File(outPath + "outputTemp.txt");
if (tempFile.delete()){System.out.println("No files created.");}
if (tempFile.delete()){
System.out.println("No files created.");
}
}
else {

System.out.println("\nResolving denials...");
System.out.println("\nTemporary file created");

try {
Expand Down Expand Up @@ -187,7 +195,9 @@ else if (line.contains("avc: denied")&& line.contains("tcontext=u:object_r:") &&
System.out.println("Temporary file removed.");
}
System.out.println("Duplicates removed.");
if (outPath.contains("//")){outPath = outPath.replace("//", "/");}
if (outPath.contains("//")){
outPath = outPath.replace("//", "/");
}
System.out.println("\nYou can find your fixed denials under " + outPath + "output.txt");
System.out.println("\nTool by @Dexer125");
}
Expand Down

0 comments on commit fe32c76

Please sign in to comment.