advanced; option to override connection info with raw values

This commit is contained in:
sirjonasxx 2019-01-30 01:16:06 +01:00
parent 148fd93cf8
commit fc7b86dc95
4 changed files with 76 additions and 37 deletions

View File

@ -5,6 +5,7 @@ import gearth.misc.OSValidator;
import gearth.protocol.hostreplacer.HostReplacer; import gearth.protocol.hostreplacer.HostReplacer;
import gearth.protocol.hostreplacer.HostReplacerFactory; import gearth.protocol.hostreplacer.HostReplacerFactory;
import gearth.protocol.memory.Rc4Obtainer; import gearth.protocol.memory.Rc4Obtainer;
import gearth.protocol.misc.ConnectionInfoOverrider;
import gearth.protocol.packethandler.Handler; import gearth.protocol.packethandler.Handler;
import gearth.protocol.packethandler.IncomingHandler; import gearth.protocol.packethandler.IncomingHandler;
import gearth.protocol.packethandler.OutgoingHandler; import gearth.protocol.packethandler.OutgoingHandler;
@ -101,8 +102,9 @@ public class HConnection {
} }
public static boolean DECRYPTPACKETS = true; private static volatile ConnectionInfoOverrider connectionInfoOverrider;
public static boolean DEBUG = false; public static volatile boolean DECRYPTPACKETS = true;
public static volatile boolean DEBUG = false;
private static final HostReplacer hostsReplacer = HostReplacerFactory.get(); private static final HostReplacer hostsReplacer = HostReplacerFactory.get();
private volatile boolean hostRedirected = false; private volatile boolean hostRedirected = false;
@ -110,7 +112,7 @@ public class HConnection {
private volatile List<StateChangeListener> stateChangeListeners = new ArrayList<>(); private volatile List<StateChangeListener> stateChangeListeners = new ArrayList<>();
private volatile State state = State.NOT_CONNECTED; private volatile State state = State.NOT_CONNECTED;
private class Proxy { public static class Proxy {
private volatile String input_domain; //string representation of the domain to intercept private volatile String input_domain; //string representation of the domain to intercept
private volatile String actual_domain; //dns resolved domain (ignoring hosts file) private volatile String actual_domain; //dns resolved domain (ignoring hosts file)
private volatile int actual_port; //port of the server private volatile int actual_port; //port of the server
@ -178,7 +180,6 @@ public class HConnection {
private volatile Proxy actual_proxy = null; private volatile Proxy actual_proxy = null;
private volatile String hotelVersion = ""; private volatile String hotelVersion = "";
public State getState() { public State getState() {
return state; return state;
} }
@ -214,41 +215,44 @@ public class HConnection {
removeFromHosts(); removeFromHosts();
} }
List<String> willremove = new ArrayList<>(); if (connectionInfoOverrider.mustOverrideConnection()) {
potentialProxies.add(connectionInfoOverrider.getOverrideProxy());
}
else {
List<String> willremove = new ArrayList<>();
int c = 0;
for (String host : allPotentialHosts) {
String[] split = host.split(":");
String input_dom = split[0];
int port = Integer.parseInt(split[1]);
String actual_dom;
int c = 0; InetAddress address = null;
try {
address = InetAddress.getByName(input_dom);
actual_dom = address.getHostAddress();
}
catch (UnknownHostException e) {
willremove.add(host);
continue;
}
for (String host : allPotentialHosts) { int intercept_port = port;
String[] split = host.split(":"); String intercept_host = "127.0." + (c / 254) + "." + (1 + c % 254);
String input_dom = split[0]; potentialProxies.add(new Proxy(input_dom, actual_dom, port, intercept_port, intercept_host));
int port = Integer.parseInt(split[1]); c++;
String actual_dom;
InetAddress address = null;
try {
address = InetAddress.getByName(input_dom);
actual_dom = address.getHostAddress();
}
catch (UnknownHostException e) {
willremove.add(host);
continue;
} }
int intercept_port = port; List<Object> additionalCachedHotels = Cacher.getList(HOTELS_CACHE_KEY);
String intercept_host = "127.0." + (c / 254) + "." + (1 + c % 254); if (additionalCachedHotels != null) {
potentialProxies.add(new Proxy(input_dom, actual_dom, port, intercept_port, intercept_host)); for (String host : willremove) {
c++; additionalCachedHotels.remove(host);
}
Cacher.put(HOTELS_CACHE_KEY, additionalCachedHotels);
}
} }
List<Object> additionalCachedHotels = Cacher.getList(HOTELS_CACHE_KEY);
if (additionalCachedHotels != null) {
for (String host : willremove) {
additionalCachedHotels.remove(host);
}
Cacher.put(HOTELS_CACHE_KEY, additionalCachedHotels);
}
setState(State.PREPARED); setState(State.PREPARED);
} }
@ -567,4 +571,8 @@ public class HConnection {
public String getHotelVersion() { public String getHotelVersion() {
return hotelVersion; return hotelVersion;
} }
public static void setConnectionInfoOverrider(ConnectionInfoOverrider connectionInfoOverrider) {
HConnection.connectionInfoOverrider = connectionInfoOverrider;
}
} }

View File

@ -0,0 +1,12 @@
package gearth.protocol.misc;
import gearth.protocol.HConnection;
/**
* Created by Jeunez on 30/01/2019.
*/
public interface ConnectionInfoOverrider {
boolean mustOverrideConnection();
HConnection.Proxy getOverrideProxy();
}

View File

@ -2,6 +2,7 @@ package gearth.ui.extra;
import gearth.misc.Cacher; import gearth.misc.Cacher;
import gearth.protocol.HConnection; import gearth.protocol.HConnection;
import gearth.protocol.misc.ConnectionInfoOverrider;
import gearth.ui.SubForm; import gearth.ui.SubForm;
import gearth.ui.info.Info; import gearth.ui.info.Info;
import javafx.beans.InvalidationListener; import javafx.beans.InvalidationListener;
@ -12,7 +13,7 @@ import javafx.scene.layout.GridPane;
/** /**
* Created by Jonas on 06/04/18. * Created by Jonas on 06/04/18.
*/ */
public class Extra extends SubForm { public class Extra extends SubForm implements ConnectionInfoOverrider {
public static final String NOTEPAD_CACHE_KEY = "notepad_text"; public static final String NOTEPAD_CACHE_KEY = "notepad_text";
@ -36,6 +37,8 @@ public class Extra extends SubForm {
public CheckBox cbx_debug; public CheckBox cbx_debug;
public void initialize() { public void initialize() {
HConnection.setConnectionInfoOverrider(this);
url_troubleshooting.setTooltip(new Tooltip("https://github.com/sirjonasxx/G-Earth/wiki/Troubleshooting")); url_troubleshooting.setTooltip(new Tooltip("https://github.com/sirjonasxx/G-Earth/wiki/Troubleshooting"));
Info.activateHyperlink(url_troubleshooting); Info.activateHyperlink(url_troubleshooting);
@ -82,4 +85,20 @@ public class Extra extends SubForm {
cbx_disableDecryption.setDisable(getHConnection().getState() != HConnection.State.NOT_CONNECTED); cbx_disableDecryption.setDisable(getHConnection().getState() != HConnection.State.NOT_CONNECTED);
} }
@Override
public boolean mustOverrideConnection() {
return cbx_ovcinfo.isSelected();
}
@Override
public HConnection.Proxy getOverrideProxy() {
return new HConnection.Proxy(
txt_realIp.getText(),
txt_realIp.getText(),
Integer.parseInt(txt_realPort.getText()),
Integer.parseInt(txt_mitmPort.getText()),
txt_mitmIP.getText()
);
}
} }

View File

@ -71,7 +71,7 @@
<Label text="MITM IP:" GridPane.rowIndex="1" /> <Label text="MITM IP:" GridPane.rowIndex="1" />
<Label text="Real port:" GridPane.rowIndex="2" /> <Label text="Real port:" GridPane.rowIndex="2" />
<Label text="MITM port:" GridPane.rowIndex="3" /> <Label text="MITM port:" GridPane.rowIndex="3" />
<TextField fx:id="txt_realPort" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="2"> <TextField fx:id="txt_realPort" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="2">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>
@ -79,7 +79,7 @@
<Insets bottom="3.0" right="7.0" top="3.0" /> <Insets bottom="3.0" right="7.0" top="3.0" />
</GridPane.margin> </GridPane.margin>
</TextField> </TextField>
<TextField fx:id="txt_mitmIP" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="1"> <TextField fx:id="txt_mitmIP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="1">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>
@ -87,7 +87,7 @@
<Insets bottom="3.0" right="7.0" top="3.0" /> <Insets bottom="3.0" right="7.0" top="3.0" />
</GridPane.margin> </GridPane.margin>
</TextField> </TextField>
<TextField fx:id="txt_realIp" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1"> <TextField fx:id="txt_realIp" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>
@ -95,7 +95,7 @@
<Insets bottom="3.0" right="7.0" top="3.0" /> <Insets bottom="3.0" right="7.0" top="3.0" />
</GridPane.margin> </GridPane.margin>
</TextField> </TextField>
<TextField fx:id="txt_mitmPort" editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="3"> <TextField fx:id="txt_mitmPort" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="3">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>