From 17065a2dbb2315de2a34bcb6acfd042041a1b13e Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Wed, 19 Sep 2018 23:36:26 +0200 Subject: [PATCH 01/20] hotfix encryption for incoming packetstream --- src/main/protocol/memory/Rc4Obtainer.java | 1 + src/main/protocol/packethandler/Handler.java | 23 ++++---- .../packethandler/IncomingHandler.java | 56 ++++++++++++++++++- .../packethandler/OutgoingHandler.java | 45 ++++++++------- .../loggerdisplays/PacketLoggerFactory.java | 7 ++- 5 files changed, 97 insertions(+), 35 deletions(-) diff --git a/src/main/protocol/memory/Rc4Obtainer.java b/src/main/protocol/memory/Rc4Obtainer.java index cd173fb..62d5f7e 100644 --- a/src/main/protocol/memory/Rc4Obtainer.java +++ b/src/main/protocol/memory/Rc4Obtainer.java @@ -72,6 +72,7 @@ public class Rc4Obtainer { if (payloadBuffer.peak().length == 0) { outgoingHandler.setRc4(rc4Tryout); + incomingHandler.setRc4(rc4Tryout); break outerloop; } diff --git a/src/main/protocol/packethandler/Handler.java b/src/main/protocol/packethandler/Handler.java index ab0d206..fd12dff 100644 --- a/src/main/protocol/packethandler/Handler.java +++ b/src/main/protocol/packethandler/Handler.java @@ -2,6 +2,7 @@ package main.protocol.packethandler; import main.protocol.HMessage; import main.protocol.TrafficListener; +import main.protocol.crypto.RC4; import java.io.IOException; import java.io.OutputStream; @@ -10,6 +11,8 @@ import java.util.List; public abstract class Handler { + protected static final boolean DEBUG = false; + volatile PayloadBuffer payloadBuffer = new PayloadBuffer(); volatile OutputStream out; volatile Object[] listeners = null; //get notified on packet send @@ -17,6 +20,9 @@ public abstract class Handler { volatile boolean isDataStream = false; volatile int currentIndex = 0; + protected RC4 clientcipher = null; + protected RC4 servercipher = null; + public Handler(OutputStream outputStream, Object[] listeners) { this.listeners = listeners; @@ -28,18 +34,11 @@ public abstract class Handler { isDataStream = true; } - public void act(byte[] buffer) throws IOException { - if (isDataStream) { - payloadBuffer.push(buffer); - notifyBufferListeners(buffer.length); + public abstract void act(byte[] buffer) throws IOException; - if (!isTempBlocked) { - flush(); - } - } - else { - out.write(buffer); - } + public void setRc4(RC4 rc4) { + this.clientcipher = rc4.deepCopy(); + this.servercipher = rc4.deepCopy(); } public void block() { @@ -73,7 +72,7 @@ public abstract class Handler { public abstract void flush() throws IOException; - + protected abstract void printForDebugging(byte[] bytes); private List bufferListeners = new ArrayList<>(); public void addBufferListener(BufferListener listener) { diff --git a/src/main/protocol/packethandler/IncomingHandler.java b/src/main/protocol/packethandler/IncomingHandler.java index a085e6a..168a70c 100644 --- a/src/main/protocol/packethandler/IncomingHandler.java +++ b/src/main/protocol/packethandler/IncomingHandler.java @@ -13,13 +13,48 @@ public class IncomingHandler extends Handler { super(outputStream, listeners); } + private final Object lock = new Object(); + private Boolean isEncryptedStream = null; + + + @Override + public void act(byte[] buffer) throws IOException { + if (isDataStream) { + if (DEBUG) { + printForDebugging(buffer); + } + + + if (isEncryptedStream == null || !isEncryptedStream) { + payloadBuffer.push(buffer); + } + else { + payloadBuffer.push(servercipher.rc4(buffer)); + } + + + notifyBufferListeners(buffer.length); + + if (!isTempBlocked) { + flush(); + } + } + else { + out.write(buffer); + } + } + @Override public void sendToStream(byte[] buffer) { synchronized (lock) { try { - out.write(buffer); + out.write( + (isEncryptedStream == null || !isEncryptedStream) + ? buffer + : clientcipher.rc4(buffer) + ); } catch (IOException e) { e.printStackTrace(); } @@ -33,14 +68,29 @@ public class IncomingHandler extends Handler { for (HPacket hpacket : hpackets){ HMessage hMessage = new HMessage(hpacket, HMessage.Side.TOCLIENT, currentIndex); - if (isDataStream) notifyListeners(hMessage); + if (isDataStream) { + notifyListeners(hMessage); + } if (!hMessage.isBlocked()) { - out.write(hMessage.getPacket().toBytes()); + out.write( + (isEncryptedStream == null || !isEncryptedStream) + ? hMessage.getPacket().toBytes() + : clientcipher.rc4(hMessage.getPacket().toBytes()) + ); + } + + if (isDataStream && isEncryptedStream == null && hpacket.length() == 261) { + isEncryptedStream = hpacket.readBoolean(264); } currentIndex++; } } } + + @Override + protected void printForDebugging(byte[] bytes) { + System.out.println("-- DEBUG INCOMING -- " + new HPacket(bytes).toString() + " -- DEBUG --"); + } } diff --git a/src/main/protocol/packethandler/OutgoingHandler.java b/src/main/protocol/packethandler/OutgoingHandler.java index ece5193..545dbe9 100644 --- a/src/main/protocol/packethandler/OutgoingHandler.java +++ b/src/main/protocol/packethandler/OutgoingHandler.java @@ -14,10 +14,7 @@ public class OutgoingHandler extends Handler { private final Object lock = new Object(); - private final static int encryptOffset = 3; //all packets with index < 3 aren't encrypted - private RC4 clientcipher = null; - private RC4 servercipher = null; private List tempEncryptedBuffer = new ArrayList<>(); public OutgoingHandler(OutputStream outputStream, Object[] listeners) { @@ -35,7 +32,6 @@ public class OutgoingHandler extends Handler { public void act(byte[] buffer) throws IOException { dataStreamCheck(buffer); if (isDataStream) { - if (currentIndex < encryptOffset) { payloadBuffer.push(buffer); } @@ -45,7 +41,11 @@ public class OutgoingHandler extends Handler { } } else { - payloadBuffer.push(clientcipher.rc4(buffer)); + byte[] tm = clientcipher.rc4(buffer); + if (DEBUG) { + printForDebugging(tm); + } + payloadBuffer.push(tm); } notifyBufferListeners(buffer.length); @@ -60,21 +60,9 @@ public class OutgoingHandler extends Handler { } @Override - public void sendToStream(byte[] buffer) { - synchronized (lock) { - try { - out.write(servercipher.rc4(buffer)); - } catch (IOException e) { - e.printStackTrace(); - } - } - - } - public void setRc4(RC4 rc4) { - this.clientcipher = rc4; - this.servercipher = rc4.deepCopy(); - + super.setRc4(rc4); + byte[] encrbuffer = new byte[tempEncryptedBuffer.size()]; for (int i = 0; i < tempEncryptedBuffer.size(); i++) { encrbuffer[i] = tempEncryptedBuffer.get(i); @@ -87,6 +75,19 @@ public class OutgoingHandler extends Handler { } tempEncryptedBuffer = null; } + + @Override + public void sendToStream(byte[] buffer) { + synchronized (lock) { + try { + out.write(servercipher.rc4(buffer)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + public List getEncryptedBuffer() { return tempEncryptedBuffer; } @@ -109,4 +110,10 @@ public class OutgoingHandler extends Handler { } } + + + @Override + protected void printForDebugging(byte[] bytes) { + System.out.println("-- DEBUG OUTGOING -- " + new HPacket(bytes).toString() + " -- DEBUG --"); + } } diff --git a/src/main/ui/logger/loggerdisplays/PacketLoggerFactory.java b/src/main/ui/logger/loggerdisplays/PacketLoggerFactory.java index bb74f55..267957a 100644 --- a/src/main/ui/logger/loggerdisplays/PacketLoggerFactory.java +++ b/src/main/ui/logger/loggerdisplays/PacketLoggerFactory.java @@ -1,14 +1,19 @@ package main.ui.logger.loggerdisplays; +import main.misc.OSValidator; + /** * Created by Jonas on 04/04/18. */ public class PacketLoggerFactory { public static PacketLogger get() { - if (System.getenv("XDG_CURRENT_DESKTOP") != null && System.getenv("XDG_CURRENT_DESKTOP").toLowerCase().contains("gnome")) { + if (OSValidator.isUnix()) { return new GnomeTerminalLogger(); } +// if (System.getenv("XDG_CURRENT_DESKTOP") != null && System.getenv("XDG_CURRENT_DESKTOP").toLowerCase().contains("gnome")) { +// return new GnomeTerminalLogger(); +// } return new SimpleTerminalLogger(); } From 697be8af769f2d9a0680bc383178ff4f90c4a853 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Wed, 19 Sep 2018 23:45:51 +0200 Subject: [PATCH 02/20] version number --- src/main/ui/info/Info.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/ui/info/Info.java b/src/main/ui/info/Info.java index 6a4dfaa..e44adbc 100644 --- a/src/main/ui/info/Info.java +++ b/src/main/ui/info/Info.java @@ -12,7 +12,7 @@ public class Info extends SubForm { public void initialize() { String[] lines = { - "G-Earth", + "G-Earth 0.1.1", "Linux Habbo Packet Manipulator", "", "Made by:", From 86c546adc66d61b5050667deda873681c41eef85 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sat, 22 Sep 2018 02:30:11 +0200 Subject: [PATCH 03/20] support for installing extensions, working extensions filesystem --- src/META-INF/MANIFEST.MF | 3 + src/main/extensions/Extension.java | 20 ++-- .../extensions/examples/AdminOnConnect.java | 2 +- src/main/ui/extensions/Extensions.fxml | 2 +- src/main/ui/extensions/Extensions.java | 28 ++++- .../ui/extensions/executer/ExecutionInfo.java | 32 +++++ .../extensions/executer/ExtensionRunner.java | 18 +++ .../executer/ExtensionRunnerFactory.java | 14 +++ .../executer/NormalExtensionRunner.java | 110 ++++++++++++++++++ 9 files changed, 219 insertions(+), 10 deletions(-) create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/main/ui/extensions/executer/ExecutionInfo.java create mode 100644 src/main/ui/extensions/executer/ExtensionRunner.java create mode 100644 src/main/ui/extensions/executer/ExtensionRunnerFactory.java create mode 100644 src/main/ui/extensions/executer/NormalExtensionRunner.java diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1e663f8 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: main.extensions.examples.AdminOnConnect + diff --git a/src/main/extensions/Extension.java b/src/main/extensions/Extension.java index ee236e4..9c57b87 100644 --- a/src/main/extensions/Extension.java +++ b/src/main/extensions/Extension.java @@ -4,10 +4,7 @@ import main.protocol.HMessage; import main.protocol.HPacket; import main.ui.extensions.Extensions; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; @@ -63,7 +60,15 @@ public abstract class Extension { while (!gEarthExtensionServer.isClosed()) { - int length = dIn.readInt(); + int length; + try { + length = dIn.readInt(); + } + catch(EOFException exception) { + //g-earth closed the extension + break; + } + byte[] headerandbody = new byte[length + 4]; int amountRead = 0; @@ -142,10 +147,11 @@ public abstract class Extension { } } - + System.out.println("Extension closed"); } catch (IOException | ArrayIndexOutOfBoundsException e) { - e.printStackTrace(); + System.err.println("Connection failed; is G-Earth open?"); +// e.printStackTrace(); } finally { if (gEarthExtensionServer != null && !gEarthExtensionServer.isClosed()) { diff --git a/src/main/extensions/examples/AdminOnConnect.java b/src/main/extensions/examples/AdminOnConnect.java index 2508549..11f1dde 100644 --- a/src/main/extensions/examples/AdminOnConnect.java +++ b/src/main/extensions/examples/AdminOnConnect.java @@ -20,7 +20,7 @@ public class AdminOnConnect extends Extension { private boolean done = true; protected void init() { - intercept(HMessage.Side.TOCLIENT, -1, message -> { + intercept(HMessage.Side.TOCLIENT, message -> { if (!done) { HPacket packet = message.getPacket(); if (packet.length() == 11) { diff --git a/src/main/ui/extensions/Extensions.fxml b/src/main/ui/extensions/Extensions.fxml index 153d095..b07e03e 100644 --- a/src/main/ui/extensions/Extensions.fxml +++ b/src/main/ui/extensions/Extensions.fxml @@ -83,7 +83,7 @@ -