SHARE
TWEET

Untitled

a guest Sep 24th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.America10Ultra.BotAttack;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.DataInputStream;
  5. import java.io.DataOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.InputStreamReader;
  9. import java.io.PrintStream;
  10. import java.net.HttpURLConnection;
  11. import java.net.InetSocketAddress;
  12. import java.net.Socket;
  13. import java.net.URL;
  14. import java.net.URLEncoder;
  15. import javax.net.ssl.HttpsURLConnection;
  16.  
  17. public class Bot
  18.   implements Runnable
  19. {
  20.   private String username;
  21.   private String password;
  22.   private String server;
  23.   private int port;
  24.   private String[] session;
  25.   private String auth;
  26.   private String spam;
  27.   private Socket socket;
  28.   private DataOutputStream dos;
  29.   private DataInputStream dis;
  30.  
  31.   public Bot(String s, String s1, String s2, String s3, int i)
  32.   {
  33.     this.username = s;
  34.     this.password = s1;
  35.     this.spam = s2;
  36.     this.server = s3;
  37.     this.port = i;
  38.   }
  39.  
  40.   public void run()
  41.   {
  42.     try
  43.     {
  44.       System.out.println("Running...");
  45.       setupBot();
  46.     }
  47.     catch (Exception exception)
  48.     {
  49.       exception.printStackTrace();
  50.     }
  51.   }
  52.  
  53.   public void setupBot()
  54.   {
  55.     System.out.println("Setting up the bot...");
  56.     try
  57.     {
  58.       createSocket();
  59.       if (this.socket.isConnected())
  60.       {
  61.         String s = "user=" + URLEncoder.encode(this.username, "UTF-8") + "&password=" + URLEncoder.encode(this.password, "UTF-8") + "&version=" + 13;
  62.         authenticateLogin(s);
  63.         Thread.sleep(20L);
  64.         sendHandshake();
  65.         Thread.sleep(90L);
  66.         sendLogin();
  67.         Thread.sleep(60L);
  68.         sendChat("Hello");
  69.         Thread.sleep(20L);
  70.         sendDisconnect();
  71.         Thread.sleep(40L);
  72.         this.socket.close();
  73.         this.dis.close();
  74.         this.dos.close();
  75.       }
  76.     }
  77.     catch (Exception exception)
  78.     {
  79.       exception.printStackTrace();
  80.     }
  81.   }
  82.  
  83.   public void createSocket()
  84.   {
  85.     try
  86.     {
  87.       System.out.println("Creating socket...");
  88.       this.socket = new Socket();
  89.       connect();
  90.       this.dos = new DataOutputStream(this.socket.getOutputStream());
  91.       this.dis = new DataInputStream(this.socket.getInputStream());
  92.     }
  93.     catch (IOException ioexception)
  94.     {
  95.       ioexception.printStackTrace();
  96.     }
  97.   }
  98.  
  99.   public void connect()
  100.   {
  101.     try
  102.     {
  103.       System.out.println("Connecting to: " + this.server + ":" + this.port);
  104.       this.socket.connect(new InetSocketAddress(this.server, this.port));
  105.     }
  106.     catch (IOException ioexception)
  107.     {
  108.       ioexception.printStackTrace();
  109.     }
  110.     catch (Exception exception) {}
  111.   }
  112.  
  113.   public void sendHandshake()
  114.   {
  115.     try
  116.     {
  117.       this.dos.writeByte(2);
  118.       String s = new StringBuilder().append(this.username).append(";").toString() + new StringBuilder().append(this.server).append(":").toString() + this.port;
  119.       writeString(s);
  120.       int i = this.dis.read();
  121.       System.out.println("Num: " + i);
  122.       this.auth = read(this.dis);
  123.     }
  124.     catch (Exception exception)
  125.     {
  126.       exception.printStackTrace();
  127.     }
  128.     System.out.println("Sending Handshake...");
  129.   }
  130.  
  131.   public void sendLogin()
  132.   {
  133.     try
  134.     {
  135.       joinServer();
  136.       this.dos.writeByte(1);
  137.       this.dos.writeInt(29);
  138.       writeString(this.username);
  139.       writeString("");
  140.       this.dos.writeInt(0);
  141.       this.dos.writeInt(0);
  142.       this.dos.writeByte(0);
  143.       this.dos.writeByte(0);
  144.       this.dos.writeByte(0);
  145.       Thread.sleep(20L);
  146.       createSession();
  147.     }
  148.     catch (IOException ioexception)
  149.     {
  150.       ioexception.printStackTrace();
  151.     }
  152.     catch (Exception exception)
  153.     {
  154.       exception.printStackTrace();
  155.     }
  156.     System.out.println("Logging in...");
  157.   }
  158.  
  159.   protected void keepAlive(DataOutputStream dataoutputstream)
  160.   {
  161.     try
  162.     {
  163.       dataoutputstream.writeByte(0);
  164.       dataoutputstream.writeInt(0);
  165.       System.out.println("Bot is still alive!");
  166.     }
  167.     catch (IOException ioexception)
  168.     {
  169.       ioexception.printStackTrace();
  170.     }
  171.   }
  172.  
  173.   public void sendChat(String s)
  174.   {
  175.     try
  176.     {
  177.       this.dos.writeByte(3);
  178.       writeString(s);
  179.     }
  180.     catch (IOException ioexception)
  181.     {
  182.       ioexception.printStackTrace();
  183.     }
  184.     System.out.println("Spamming...");
  185.   }
  186.  
  187.   public void sendDisconnect()
  188.   {
  189.     try
  190.     {
  191.       this.dos.writeByte(255);
  192.       writeString("Quitting");
  193.       this.dos.close();
  194.       this.dis.close();
  195.       this.socket.close();
  196.       System.out.println("Disconnecting...");
  197.     }
  198.     catch (IOException ioexception)
  199.     {
  200.       ioexception.printStackTrace();
  201.     }
  202.   }
  203.  
  204.   public void writeString(String s)
  205.   {
  206.     try
  207.     {
  208.       this.dos.writeShort(s.length());
  209.       this.dos.writeChars(s);
  210.     }
  211.     catch (IOException ioexception)
  212.     {
  213.       ioexception.printStackTrace();
  214.     }
  215.   }
  216.  
  217.   protected String read(DataInputStream datainputstream)
  218.     throws IOException
  219.   {
  220.     StringBuilder stringbuilder = new StringBuilder();
  221.     short word0 = datainputstream.readShort();
  222.     System.out.println("Read integer: " + word0);
  223.     for (int i = 0; i < word0; i++) {
  224.       stringbuilder.append(datainputstream.readChar());
  225.     }
  226.     return stringbuilder.toString();
  227.   }
  228.  
  229.   private void createSession()
  230.   {
  231.     try
  232.     {
  233.       URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + URLEncoder.encode(this.username, "UTF-8") + "&sessionId=" + URLEncoder.encode(this.session[3], "UTF-8") + "&serverId=" + URLEncoder.encode(this.auth, "UTF-8"));
  234.       BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(url.openStream()));
  235.       String s = bufferedreader.readLine();
  236.       bufferedreader.close();
  237.       if (s.equalsIgnoreCase("ok")) {
  238.         System.out.println("http://session.minecraft.net/: Logged in as: " + this.username);
  239.       } else {
  240.         System.out.println("http://session.minecraft.net/: Bad Login");
  241.       }
  242.     }
  243.     catch (Exception exception)
  244.     {
  245.       exception.printStackTrace();
  246.     }
  247.     System.out.println("Session created.");
  248.   }
  249.  
  250.   private void authenticateLogin(String s)
  251.   {
  252.     HttpsURLConnection httpsurlconnection = null;
  253.     try
  254.     {
  255.       URL url = new URL("https://login.minecraft.net/");
  256.       httpsurlconnection = (HttpsURLConnection)url.openConnection();
  257.       httpsurlconnection.setRequestMethod("GET");
  258.       httpsurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  259.       httpsurlconnection.setRequestProperty("Content-Type", Integer.toString(s.getBytes().length));
  260.       httpsurlconnection.setRequestProperty("Content-Language", "en-US");
  261.       httpsurlconnection.setUseCaches(false);
  262.       httpsurlconnection.setDoInput(true);
  263.       httpsurlconnection.setDoOutput(true);
  264.       httpsurlconnection.connect();
  265.       DataOutputStream dataoutputstream = new DataOutputStream(httpsurlconnection.getOutputStream());
  266.       dataoutputstream.writeBytes(s);
  267.       dataoutputstream.flush();
  268.       dataoutputstream.close();
  269.       InputStream inputstream = httpsurlconnection.getInputStream();
  270.       BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
  271.       StringBuffer stringbuffer = new StringBuffer();
  272.       String s1;
  273.       while ((s1 = bufferedreader.readLine()) != null)
  274.       {
  275.         stringbuffer.append(s1);
  276.         stringbuffer.append('\r');
  277.       }
  278.       bufferedreader.close();
  279.       String s2 = stringbuffer.toString();
  280.       this.session = s2.split(":");
  281.       System.out.println("https://login.mineccraft.net/: " + s2);
  282.       System.out.println("Session ID: " + this.session[3]);
  283.     }
  284.     catch (Exception exception)
  285.     {
  286.       exception.printStackTrace();
  287.     }
  288.     finally
  289.     {
  290.       if (httpsurlconnection != null) {
  291.         httpsurlconnection.disconnect();
  292.       }
  293.     }
  294.     System.out.println("Bot Authenticated.");
  295.   }
  296.  
  297.   public void joinServer()
  298.     throws Exception
  299.   {
  300.     HttpURLConnection httpurlconnection = null;
  301.     URL url = new URL("http://session.minecraft.net/game/joinserver.jsp?user=" + this.username + "&sessionId=" + this.session[3] + "&serverId=" + this.auth);
  302.     httpurlconnection = (HttpURLConnection)url.openConnection();
  303.     httpurlconnection.setUseCaches(false);
  304.     httpurlconnection.setConnectTimeout(16000);
  305.     httpurlconnection.setReadTimeout(16000);
  306.     BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream()));
  307.     StringBuffer stringbuffer = new StringBuffer();
  308.     String s;
  309.     while ((s = bufferedreader.readLine()) != null)
  310.     {
  311.       stringbuffer.append(s);
  312.       stringbuffer.append('\r');
  313.     }
  314.     String s1 = stringbuffer.toString();
  315.     String s2 = s1.replaceAll("null", "").trim();
  316.     if (!s2.equals("OK"))
  317.     {
  318.       System.out.println(s2);
  319.       throw new Exception();
  320.     }
  321.   }
  322. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top