Skip to content

Instantly share code, notes, and snippets.

@ferrybig
Created November 16, 2014 13:45
Show Gist options
  • Save ferrybig/bab8c6f737be5f63189c to your computer and use it in GitHub Desktop.
Save ferrybig/bab8c6f737be5f63189c to your computer and use it in GitHub Desktop.
package minecrafthacker;
import java.io.FilterInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketImpl;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.util.concurrent.atomic.AtomicInteger;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import net.minecraft.bootstrap.Bootstrap;
/**
* This class exposes any information the Minecraft Bootstrapper says to https://authserver.mojang.net/
without breaking the certificate.
* This should be only used for debugging purposes.
* I know that this class is unstructured and messy, but *its only for debugging purposes*
* @author Fernando
*/
public class MinecraftHacker {
public static void main(String[] args) throws IOException {
HttpsURLConnection.setDefaultSSLSocketFactory(new SSLSocketFactoryImpl());
Bootstrap.main(new String[]{});
}
private static class SSLSocketFactoryImpl extends SSLSocketFactory {
SSLSocketFactory ssl = HttpsURLConnection.getDefaultSSLSocketFactory();
@Override
public String[] getDefaultCipherSuites() {
return ssl.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return ssl.getSupportedCipherSuites();
}
@Override
public Socket createSocket(Socket socket, String string, int i, boolean bln) throws IOException {
return ssl.createSocket(socket, string, i, bln);
}
@Override
public Socket createSocket(Socket socket, InputStream in, boolean bln) throws IOException {
return ssl.createSocket(socket, in, bln);
}
@Override
public Socket createSocket() throws IOException {
Socket s = new SSLSocketImpl();
return s;
}
@Override
public Socket createSocket(String string, int i) throws IOException, UnknownHostException {
return ssl.createSocket(string, i);
}
@Override
public Socket createSocket(String string, int i, InetAddress ia, int i1) throws IOException, UnknownHostException {
return ssl.createSocket(string, i, ia, i1);
}
@Override
public Socket createSocket(InetAddress ia, int i) throws IOException {
return ssl.createSocket(ia, i);
}
@Override
public Socket createSocket(InetAddress ia, int i, InetAddress ia1, int i1) throws IOException {
return ssl.createSocket(ia, i, ia1, i1);
}
static class CustomSocketImpl extends SocketImpl {
private final Socket parent;
private boolean readFromSocket = false;
private static final AtomicInteger reference = new AtomicInteger();
private final int id = reference.getAndIncrement();
private CustomSocketImpl(Socket parent) {
this.parent = parent;
}
@Override
protected void create(boolean stream) throws IOException {
//System.err.println("[" + id + "] " + "create; stream=" + stream);
}
@Override
protected void connect(String host, int port) throws IOException {
this.connect(InetAddress.getByName(host), port);
}
@Override
protected void connect(InetAddress address, int port) throws IOException {
this.connect(new InetSocketAddress(address, port), 0);
}
@Override
protected void connect(SocketAddress address, int timeout) throws IOException {
parent.connect(address, timeout);
//System.err.println("Connect: " + ((InetSocketAddress) address).getAddress().getHostName());
if (((InetSocketAddress) address).getAddress().getHostName().equals("authserver.mojang.com")) {
this.readFromSocket = true;
System.err.println("Reading from connection!");
}
}
@Override
protected void bind(InetAddress host, int port) throws IOException {
parent.bind(new InetSocketAddress(address, port));
}
@Override
protected void listen(int backlog) throws IOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
protected void accept(SocketImpl s) throws IOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
protected InputStream getInputStream() throws IOException {
if (this.readFromSocket) {
return new FilterInputStream(parent.getInputStream()) {
@Override
public int read(byte[] b, int off, int len) throws IOException {
int l = super.read(b, off, len);
String total = new String(b, off, l);
for (String s : total.split("\n")) {
System.err.println("[" + id + "] [read] " + s);
}
return l;
}
};
}
return parent.getInputStream();
}
@Override
protected OutputStream getOutputStream() throws IOException {
if (this.readFromSocket) {
return new FilterOutputStream(parent.getOutputStream()) {
@Override
public void write(byte[] b, int off, int len) throws IOException {
super.write(b, off, len);
String total = new String(b, off, len);
for (String s : total.split("\n")) {
System.err.println("[" + id + "] [write] " + s);
}
}
};
}
return parent.getOutputStream();
}
@Override
protected int available() throws IOException {
return parent.getInputStream().available();
}
@Override
protected void close() throws IOException {
parent.close();
}
@Override
protected void sendUrgentData(int data) throws IOException {
parent.sendUrgentData(data);
}
@Override
public void setOption(int optID, Object value) throws SocketException {
//System.err.println("Set option: " + optID + " to " + value);
}
@Override
public Object getOption(int optID) throws SocketException {
throw new UnsupportedOperationException("Not supported yet.");
}
}
private class SSLSocketImpl extends SSLSocket {
public SSLSocketImpl() throws IOException {
parent = (SSLSocket) ssl.createSocket();
impl = new CustomSocketImpl(parent);
base = new Socket(impl) {
};
}
private final SSLSocket parent;
private final SocketImpl impl;
private final Socket base;
@Override
public void connect(SocketAddress endpoint) throws IOException {
base.connect(endpoint);
}
@Override
public void connect(SocketAddress endpoint, int timeout) throws IOException {
base.connect(endpoint, timeout);
}
@Override
public void bind(SocketAddress bindpoint) throws IOException {
base.bind(bindpoint);
}
@Override
public InetAddress getInetAddress() {
return base.getInetAddress();
}
@Override
public InetAddress getLocalAddress() {
return base.getLocalAddress();
}
@Override
public int getPort() {
return base.getPort();
}
@Override
public int getLocalPort() {
return base.getLocalPort();
}
@Override
public SocketAddress getRemoteSocketAddress() {
return base.getRemoteSocketAddress();
}
@Override
public SocketAddress getLocalSocketAddress() {
return base.getLocalSocketAddress();
}
@Override
public SocketChannel getChannel() {
return base.getChannel();
}
@Override
public InputStream getInputStream() throws IOException {
return base.getInputStream();
}
@Override
public OutputStream getOutputStream() throws IOException {
return base.getOutputStream();
}
@Override
public void setTcpNoDelay(boolean on) throws SocketException {
base.setTcpNoDelay(on);
}
@Override
public boolean getTcpNoDelay() throws SocketException {
return base.getTcpNoDelay();
}
@Override
public void setSoLinger(boolean on, int linger) throws SocketException {
base.setSoLinger(on, linger);
}
@Override
public int getSoLinger() throws SocketException {
return base.getSoLinger();
}
@Override
public void sendUrgentData(int data) throws IOException {
base.sendUrgentData(data);
}
@Override
public void setOOBInline(boolean on) throws SocketException {
base.setOOBInline(on);
}
@Override
public boolean getOOBInline() throws SocketException {
return base.getOOBInline();
}
@Override
public synchronized void setSoTimeout(int timeout) throws SocketException {
base.setSoTimeout(timeout);
}
@Override
public synchronized int getSoTimeout() throws SocketException {
return base.getSoTimeout();
}
@Override
public synchronized void setSendBufferSize(int size) throws SocketException {
base.setSendBufferSize(size);
}
@Override
public synchronized int getSendBufferSize() throws SocketException {
return base.getSendBufferSize();
}
@Override
public synchronized void setReceiveBufferSize(int size) throws SocketException {
base.setReceiveBufferSize(size);
}
@Override
public synchronized int getReceiveBufferSize() throws SocketException {
return base.getReceiveBufferSize();
}
@Override
public void setKeepAlive(boolean on) throws SocketException {
base.setKeepAlive(on);
}
@Override
public boolean getKeepAlive() throws SocketException {
return base.getKeepAlive();
}
@Override
public void setTrafficClass(int tc) throws SocketException {
base.setTrafficClass(tc);
}
@Override
public int getTrafficClass() throws SocketException {
return base.getTrafficClass();
}
@Override
public void setReuseAddress(boolean on) throws SocketException {
base.setReuseAddress(on);
}
@Override
public boolean getReuseAddress() throws SocketException {
return base.getReuseAddress();
}
@Override
public synchronized void close() throws IOException {
base.close();
}
@Override
public void shutdownInput() throws IOException {
base.shutdownInput();
}
@Override
public void shutdownOutput() throws IOException {
base.shutdownOutput();
}
@Override
public String toString() {
return base.toString();
}
@Override
public boolean isConnected() {
return base.isConnected();
}
@Override
public boolean isBound() {
return base.isBound();
}
@Override
public boolean isClosed() {
return base.isClosed();
}
@Override
public boolean isInputShutdown() {
return base.isInputShutdown();
}
@Override
public boolean isOutputShutdown() {
return base.isOutputShutdown();
}
@Override
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
base.setPerformancePreferences(connectionTime, latency, bandwidth);
}
@Override
public String[] getSupportedCipherSuites() {
return parent.getSupportedCipherSuites();
}
@Override
public String[] getEnabledCipherSuites() {
return parent.getEnabledCipherSuites();
}
@Override
public void setEnabledCipherSuites(String[] strings) {
parent.setEnabledCipherSuites(strings);
}
@Override
public String[] getSupportedProtocols() {
return parent.getSupportedProtocols();
}
@Override
public String[] getEnabledProtocols() {
return parent.getEnabledProtocols();
}
@Override
public void setEnabledProtocols(String[] strings) {
parent.setEnabledProtocols(strings);
}
@Override
public SSLSession getSession() {
return parent.getSession();
}
@Override
public SSLSession getHandshakeSession() {
return parent.getHandshakeSession();
}
@Override
public void addHandshakeCompletedListener(HandshakeCompletedListener hl) {
parent.addHandshakeCompletedListener(hl);
}
@Override
public void removeHandshakeCompletedListener(HandshakeCompletedListener hl) {
parent.removeHandshakeCompletedListener(hl);
}
@Override
public void startHandshake() throws IOException {
parent.startHandshake();
}
@Override
public void setUseClientMode(boolean bln) {
parent.setUseClientMode(bln);
}
@Override
public boolean getUseClientMode() {
return parent.getUseClientMode();
}
@Override
public void setNeedClientAuth(boolean bln) {
parent.setNeedClientAuth(bln);
}
@Override
public boolean getNeedClientAuth() {
return parent.getNeedClientAuth();
}
@Override
public void setWantClientAuth(boolean bln) {
parent.setWantClientAuth(bln);
}
@Override
public boolean getWantClientAuth() {
return parent.getWantClientAuth();
}
@Override
public void setEnableSessionCreation(boolean bln) {
parent.setEnableSessionCreation(bln);
}
@Override
public boolean getEnableSessionCreation() {
return parent.getEnableSessionCreation();
}
@Override
public SSLParameters getSSLParameters() {
return parent.getSSLParameters();
}
@Override
public void setSSLParameters(SSLParameters sslp) {
parent.setSSLParameters(sslp);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment