Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.InetSocketAddress;
- import java.net.Socket;
- public class TurkBot
- {
- //Main, that's the entry point of the program.
- public static void main(String[] args)
- {
- int tc;
- try
- {
- if(args.length < 1)
- throw new NumberFormatException();
- tc = Integer.parseInt(args[0]);
- }
- catch(NumberFormatException e)
- {
- System.out.println("java TurkBot Threads");
- return;
- }
- //Start 6 Threads:
- for(int i = 0; i < tc; i++)
- (new Task()).start();
- }
- //A thread, started by the main class
- public static class Task extends Thread
- {
- public void run()
- {
- //Just start the spam function.
- spamTask();
- }
- }
- private static final String host = "turkcraft.net";
- //The spam function... :D
- public static void spamTask()
- {
- try
- {
- Socket s;
- String session = null;
- String captchaID = null;
- String header;
- InputStream in;
- OutputStream out;
- byte[] buffer;
- String reply;
- int cl = 0;
- int got;
- String[] split;
- int t;
- String postdata;
- String captcha;
- String token;
- StringBuilder sb;
- //The main loop. As we want to spam it should never end.
- while(true)
- {
- captcha = null;
- //This loop fetches the registration page till it gets the anser to the captcha.
- while(captcha == null)
- {
- //New socket
- s = new Socket();
- //As we want to register a new user: Remove the session hash.
- session = null;
- //Connect to the web server
- s.connect(new InetSocketAddress(host, 80));
- //Get an input and an output stream to talk to the server.
- in = s.getInputStream();
- out = s.getOutputStream();
- //Generate a valid HTTP header:
- /*
- * GET /index.php?register/ HTTP/1.1
- * Host: turkcraft.net
- * Connection: close
- * User-Agent: V10Bot
- */
- header = "GET /index.php?register/ HTTP/1.1\r\nHost: "+host+"\r\nConnection: close\r\nUser-Agent: V10Bot\r\n\r\n";
- //Send it to the host
- out.write(header.getBytes());
- out.flush();
- //Read the HTTP header the server replies. The header ends with a double newline.
- //We read it byte for byte so we can stop after the header.
- reply = new String();
- //Read 8 kb. The header shouldn't be bigger. This may cut off some parts of the body, but that's no big problem as there's no information we need.
- buffer = new byte[8192];
- in.read(buffer);
- reply = new String(buffer);
- //We have the header, let's parse it line by line.
- split = reply.split("\r\n\r\n");
- for(String line: split[0].split("\r\n"))
- {
- //If the line describes the length of the HTTP body (the html page) save the length.
- //We need it later to read the buffer.
- if(line.startsWith("Content-Length: "))
- cl = Integer.parseInt(line.substring(16));
- //Else if the line is used to send us the cookie with the session hash, save that session hash
- //So we can authenticate us later.
- else if(line.startsWith("Set-Cookie: xf_session="))
- session = line.substring(23, line.indexOf(";"));
- }
- //Now read the body. As we have the length let's make a buffer with it and read from the socket till we have all.
- //The buffer may be bigger than it needs to be, I was to lazy to convert to the 8kb header read. :P
- got = cl - split[1].length();
- buffer = new byte[cl];
- while(got > 0)
- {
- t = cl - got;
- got -= in.read(buffer, t, cl - t);
- }
- //Allright, we don't need the connection anymore, let's close it.
- in.close();
- out.close();
- s.close();
- //Let's make a readable string from the byte buffer containing the body
- reply = new String(buffer);
- //Now let's parse the captchaID + the security question (the captcha itself) with a bit split/substring magic
- split = reply.split("\t\t<div class=\"ddText\"><label for=\"");
- if(split.length < 2)
- continue;
- t = split[1].indexOf("\"");
- captchaID = split[1].substring(0, t);
- //Let's get the answer for the question or continue with the loop (see above).
- reply = split[1].substring(t+2, split[1].indexOf("<"));
- if(reply.equals("Minecraft'ın yapımcısı kimdir?") || reply.equals("Minecraft'da \"Patlayan Yaratık\"a ne isim verilir?"))
- captcha = "Notch";
- else if(reply.equals("Hangisi bir isimdir? \"Asdasd\", \"Mehmet\""))
- captcha = "Mehmet";
- else if(reply.equals("Türkiyenin başkenti hangi ilimizdir?"))
- captcha = "Ankara";
- else if(reply.equals("\"Hello\"nun Türkçe karşılığı nedir?"))
- captcha = "Merhaba";
- }
- //Now register the user with the session in a cookie + the captcha and the other needed stuff like username, email, password, ... in the POST data.
- //First: Connect on a new socket.
- s = new Socket();
- s.connect(new InetSocketAddress(host, 80));
- in = s.getInputStream();
- out = s.getOutputStream();
- //We need a username, let's use a random number generator for it.
- postdata = Long.toHexString(Double.doubleToLongBits(Math.random()));
- //If the username is to long et's short it
- if(postdata.length() > 15)
- postdata = postdata.substring(0, 14);
- //Now let's make the POST data:
- /*
- * username = <username>
- * email = <username>@<username>.com
- * password = <username>
- * password_confirm = <username>
- * dob_month = 1
- * dob_day = 1
- * dob_year = 1990
- * gender = male
- * timezone = Europe/Amsterdam
- * captcha_question_answer = <captcha>
- * captcha_questionHash = <capthcaID>
- */
- postdata = "username="+postdata+"&email="+postdata+"%40"+postdata+".com&password="+postdata+"&password_confirm="+postdata+"&dob_month=1&dob_day=1&dob_year=1990&gender=male&timezone=Europe%2FAmsterdam&captcha_question_answer="+captcha+"&captcha_question_hash="+captchaID+"&agree=1\r\n";
- //Now let's make a valid HTTP header:
- /*
- * POST /index.php?register/register HTTP/1.1
- * Host: turkcraft.net
- * Connection: close
- * User-Agent: V10bot
- * Content-Length <postdata length>
- * Content-Type: application/x-www-form-urlencoded
- */
- sb = new StringBuilder("POST /index.php?register/register HTTP/1.1\r\nHost: ").append(host).append("\r\nConnection: close\r\nUser-Agent: V10Bot\r\nContent-Length: ").append(postdata.length()).append("\r\nContent-Type: application/x-www-form-urlencoded\r\n");
- //If we have a session hash (we should!) let's add it as a cookie
- if(session != null)
- sb.append("Cookie: xf_session=").append(session).append("\r\n");
- //And a ending newline to tell the server that the POST data begins. After that the postdata.
- sb.append("\r\n").append(postdata);
- //Let's send that data to the server:
- /*
- * POST /index.php?register/register HTTP/1.1
- * Host: turkcraft.net
- * Connection: close
- * User-Agent: V10bot
- * Content-Length <postdata length>
- * Content-Type: application/x-www-form-urlencoded
- * Cookie: xf_session=<session>
- *
- * username=<username>&email=<username>@<username>.com&password=<username>&password_confirm=<username>&dob_month=1&dob_day=1&dob_year=1990&gender=male&timezone=Europe/Amsterdam&captcha_question_answer=<captcha>&captcha_questionHash=<capthcaID>
- */
- out.write(sb.toString().getBytes());
- out.flush();
- //Read the header
- buffer = new byte[8192];
- in.read(buffer);
- reply = new String(buffer);
- for(String line: reply.split("\r\n\r\n")[0].split("\r\n"))
- if(line.startsWith("Set-Cookie: xf_session="))
- session = line.substring(23, line.indexOf(";"));
- //No need to read the body, xenforo seems to register us while we read the header.
- in.close();
- out.close();
- s.close();
- //Now, as we are registred, go to the create thread page...
- s = new Socket();
- s.connect(new InetSocketAddress(host, 80));
- in = s.getInputStream();
- out = s.getOutputStream();
- sb = new StringBuilder("GET /index.php?forums/survival-mod-sunucular%C4%B1.20/create-thread HTTP/1.1\r\nHost: ").append(host).append("\r\nConnection: close\r\nUser-Agent: V10Bot\r\n");
- if(session != null)
- sb.append("Cookie: xf_session=").append(session).append("\r\n");
- sb.append("\r\n").append(postdata);
- out.write(sb.toString().getBytes());
- out.flush();
- buffer = new byte[8192];
- in.read(buffer);
- reply = new String(buffer);
- //We have the header, let's parse it line by line.
- split = reply.split("\r\n\r\n");
- for(String line: split[0].split("\r\n"))
- {
- //If the line describes the length of the HTTP body (the html page) save the length.
- //We need it later to read the buffer.
- if(line.startsWith("Content-Length: "))
- cl = Integer.parseInt(line.substring(16));
- //Else if the line is used to send us the cookie with the session hash, save that session hash
- //So we can authenticate us later.
- else if(line.startsWith("Set-Cookie: xf_session="))
- session = line.substring(23, line.indexOf(";"));
- }
- //Now read the body. As we have the length let's make a buffer with it and read from the socket till we have all.
- //The buffer may be bigger than it needs to be, I was to lazy to convert to the 8kb header read. :P
- got = cl - split[1].length();
- buffer = new byte[cl];
- while(got > 0)
- {
- t = cl - got;
- got -= in.read(buffer, t, cl - t);
- }
- //We need the attachment hash and the xfToken from that page or we will cause a security exception from xenforo later
- split = new String(buffer).split("<input type=\"hidden\" name=\"attachment_hash\" value=\"");
- if(split.length < 2)
- continue;
- String hash = split[1];
- split = hash.split("<input type=\"hidden\" name=\"_xfToken\" value=\"");
- if(split.length < 2)
- continue;
- token = split[1];
- hash = hash.substring(0, hash.indexOf("\""));
- token = token.substring(0, token.indexOf("\""));
- //And we close...
- in.close();
- out.close();
- s.close();
- s = new Socket();
- s.connect(new InetSocketAddress(host, 80));
- in = s.getInputStream();
- out = s.getOutputStream();
- //We need postdata again, Iwon't get into detail this time, but it contains the thread title, the message, the attachment hash, the xfToken and other things to make a valid thread.
- postdata = "title=I%20told%20you%20to%20NOT%20DELETE%20MY%20POSTS&message=Lynax%20is%20the%20liar%2C%20not%20me.%20He%20is%20unable%20to%20give%20the%20simplest%20information%20like%20paypal%20addresses%20and%20transaction%20numbers%20which%20would%20prove%20his%20payment!%0A%0AWe%20do%20not%20forgive.%0AWe%20do%20not%20forget.%0AExpect%20us.&_xfRelativeResolver=http%3A%2F%2Fturkcraft.net%2Findex.php%3Fforums%2Fsurvival-mod-sunucular%25C4%25B1.20%2Fcreate-thread&attachment_hash="+hash+"&watch_thread=1&watch_thread_email=1&watch_thread_state=1&poll%5Bquestion%5D=&poll%5Bresponses%5D%5B%5D=&poll%5Bresponses%5D%5B%5D=&_xfToken="+token+"&_xfRequestUri=%2Findex.php%3Fforums%2Fsurvival-mod-sunucular%25C4%25B1.20%2Fcreate-thread&_xfNoRedirect=1&_xfResponseType=json\r\n";
- sb = new StringBuilder("POST /index.php?forums/survival-mod-sunucular%C4%B1.20/add-thread HTTP/1.1\r\nHost: ").append(host).append("\r\nConnection: close\r\nUser-Agent: V10Bot\r\nContent-Length: ").append(postdata.length()).append("\r\nContent-Type: application/x-www-form-urlencoded\r\nReferer: /index.php?forums/survival-mod-sunucular%C4%B1.20/create-thread\r\n");
- if(session != null)
- sb.append("Cookie: xf_session="+session+"\r\n");
- sb.append("\r\n").append(postdata);
- out.write(sb.toString().getBytes());
- //No need to read the data here. Xenforo saved the post before it replies any data. Also we don't flush/close for better performance. ^^
- //Allright, let's start from the beginning of the loop.
- }
- }
- catch(IOException e)
- {
- e.printStackTrace();
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement