Created
May 4, 2024 20:13
-
-
Save pwgit-create/d4c67e4aeca16ab360d985e45e937657 to your computer and use it in GitHub Desktop.
Detecting backdoors on Linux x64 systems
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
import java.io.*; | |
import java.util.*; | |
public class BackdoorFinder { | |
public static void main(String[] args) { | |
File file = new File("/etc"); // Good Starting point. Change here if you want another root folder to start from. | |
if (file.exists() && !file.isDirectory()) { | |
System.out.println("File is not a directory"); | |
return; | |
} | |
findBackdoorFiles(file); | |
} | |
private static void findBackdoorFiles(File directory) { | |
File[] files = directory.listFiles(); | |
if (files != null) { | |
for (File file : files) { | |
if (file.isDirectory()) { | |
findBackdoorFiles(file); | |
} else { | |
String fileName = file.getName().toLowerCase(); | |
if (fileName.endsWith(".sh") || fileName.endsWith(".bash")) { | |
try { | |
BufferedReader reader = new BufferedReader(new FileReader(file)); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
if (line.contains("eval") || line.contains("exec")) { | |
System.out.println("Potential backdoor found: " + file.getAbsolutePath()); | |
} | |
} | |
reader.close(); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment