mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 00:40:51 +01:00
Merge pull request #127 from dorving/client-handshake-checks
Wrapped RC4 table checks in try catch block (#106)
This commit is contained in:
commit
5ac1593dae
@ -3,25 +3,20 @@ package gearth.protocol.memory;
|
||||
import gearth.GEarth;
|
||||
import gearth.protocol.HConnection;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.protocol.crypto.RC4;
|
||||
import gearth.protocol.memory.habboclient.HabboClient;
|
||||
import gearth.protocol.memory.habboclient.HabboClientFactory;
|
||||
import gearth.protocol.packethandler.PayloadBuffer;
|
||||
import gearth.protocol.packethandler.flash.BufferChangeListener;
|
||||
import gearth.protocol.packethandler.flash.FlashPacketHandler;
|
||||
import gearth.protocol.packethandler.PayloadBuffer;
|
||||
import gearth.ui.titlebar.TitleBarController;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Hyperlink;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.web.WebView;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -31,17 +26,15 @@ public class Rc4Obtainer {
|
||||
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
private HabboClient client;
|
||||
private final HabboClient client;
|
||||
private List<FlashPacketHandler> flashPacketHandlers;
|
||||
|
||||
public Rc4Obtainer(HConnection hConnection) {
|
||||
client = HabboClientFactory.get(hConnection);
|
||||
}
|
||||
|
||||
|
||||
public void setFlashPacketHandlers(FlashPacketHandler... flashPacketHandlers) {
|
||||
this.flashPacketHandlers = Arrays.asList(flashPacketHandlers);
|
||||
|
||||
for (FlashPacketHandler handler : flashPacketHandlers) {
|
||||
BufferChangeListener bufferChangeListener = new BufferChangeListener() {
|
||||
@Override
|
||||
@ -54,12 +47,8 @@ public class Rc4Obtainer {
|
||||
};
|
||||
handler.getBufferChangeObservable().addListener(bufferChangeListener);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void onSendFirstEncryptedMessage(FlashPacketHandler flashPacketHandler) {
|
||||
if (!HConnection.DECRYPTPACKETS) return;
|
||||
|
||||
@ -82,7 +71,6 @@ public class Rc4Obtainer {
|
||||
if (!worked) {
|
||||
System.err.println("COULD NOT FIND RC4 TABLE");
|
||||
|
||||
|
||||
Platform.runLater(() -> {
|
||||
Alert alert = new Alert(Alert.AlertType.WARNING, "Something went wrong!", ButtonType.OK);
|
||||
|
||||
@ -97,65 +85,74 @@ public class Rc4Obtainer {
|
||||
|
||||
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
|
||||
alert.getDialogPane().setContent(fp);
|
||||
alert.setOnCloseRequest(event -> {
|
||||
GEarth.main.getHostServices().showDocument(link.getText());
|
||||
});
|
||||
alert.setOnCloseRequest(event -> GEarth.main.getHostServices().showDocument(link.getText()));
|
||||
try {
|
||||
TitleBarController.create(alert).showAlert();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
if (DEBUG) {
|
||||
final long endTime = System.currentTimeMillis();
|
||||
if (DEBUG)
|
||||
System.out.println("Cracked RC4 in " + (endTime - startTime) + "ms");
|
||||
}
|
||||
|
||||
flashPacketHandlers.forEach(FlashPacketHandler::unblock);
|
||||
}).start();
|
||||
}
|
||||
|
||||
private boolean onSendFirstEncryptedMessage(FlashPacketHandler flashPacketHandler, List<byte[]> potentialRC4tables) {
|
||||
for (byte[] possible : potentialRC4tables) {
|
||||
|
||||
byte[] encBuffer = new byte[flashPacketHandler.getEncryptedBuffer().size()];
|
||||
for (int i = 0; i < encBuffer.length; i++) {
|
||||
encBuffer[i] = flashPacketHandler.getEncryptedBuffer().get(i);
|
||||
for (byte[] possible : potentialRC4tables)
|
||||
if (isCorrectRC4Table(flashPacketHandler, possible))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isCorrectRC4Table(FlashPacketHandler flashPacketHandler, byte[] possible) {
|
||||
|
||||
try {
|
||||
|
||||
final byte[] encBuffer = new byte[flashPacketHandler.getEncryptedBuffer().size()];
|
||||
|
||||
for (int i = 0; i < encBuffer.length; i++)
|
||||
encBuffer[i] = flashPacketHandler.getEncryptedBuffer().get(i);
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
for (int j = 0; j < 256; j++) {
|
||||
byte[] keycpy = Arrays.copyOf(possible, possible.length);
|
||||
RC4 rc4Tryout = new RC4(keycpy, i, j);
|
||||
|
||||
if (flashPacketHandler.getMessageSide() == HMessage.Direction.TOSERVER) rc4Tryout.undoRc4(encBuffer);
|
||||
final byte[] keycpy = Arrays.copyOf(possible, possible.length);
|
||||
final RC4 rc4Tryout = new RC4(keycpy, i, j);
|
||||
|
||||
if (flashPacketHandler.getMessageSide() == HMessage.Direction.TOSERVER)
|
||||
rc4Tryout.undoRc4(encBuffer);
|
||||
|
||||
if (rc4Tryout.couldBeFresh()) {
|
||||
byte[] encDataCopy = Arrays.copyOf(encBuffer, encBuffer.length);
|
||||
RC4 rc4TryCopy = rc4Tryout.deepCopy();
|
||||
|
||||
final byte[] encDataCopy = Arrays.copyOf(encBuffer, encBuffer.length);
|
||||
final RC4 rc4TryCopy = rc4Tryout.deepCopy();
|
||||
|
||||
try {
|
||||
PayloadBuffer payloadBuffer = new PayloadBuffer();
|
||||
byte[] decoded = rc4TryCopy.rc4(encDataCopy);
|
||||
HPacket[] checker = payloadBuffer.pushAndReceive(decoded);
|
||||
final PayloadBuffer payloadBuffer = new PayloadBuffer();
|
||||
final byte[] decoded = rc4TryCopy.rc4(encDataCopy);
|
||||
|
||||
payloadBuffer.pushAndReceive(decoded);
|
||||
|
||||
if (payloadBuffer.peak().length == 0) {
|
||||
flashPacketHandler.setRc4(rc4Tryout);
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user