Thread: DDoS Protection! *The Real Way*

Results 1 to 3 of 3
  1. #1 DDoS Protection! *The Real Way* 
    Can I Be Vet Pls?

    Trytohaxme's Avatar
    Join Date
    May 2008
    Age
    31
    Posts
    2,401
    Thanks given
    1
    Thanks received
    21
    Rep Power
    1478
    First of all credits go to Hidendra!
    I DID FIND THIS JUST THOUGHT IT WOULD HELP ALOT OF OTHERS



    Note: This does not invoke you to use any god damn firewall, or for you to do a lot of work. This is probably one of the ONLY ways you can fully stop SYI and any other DDoS'r until they learn how to send Packet 14.

    If this gets locked, it gets locked. I don't know how long it'll take you to do it, and it's kind of hard to avoid c|p. At least you get one good thing out of it: No more SYI pissing us off.


    Seriously guys, the shitty tutorials about firewalls and incorrectly blocking this and your lame-brain questions have got to stop.
    Not sure if this was ever made before, but this is my version. I changed everything around to make it look a lot more readable, and removed unnecessary junk (useless comments, etc, etc).

    This will: Correctly protect your server against DDoS attacks and deal with them right. We will NOT use any Firewalls, and instead use what you people should have been using.

    Before you start, you should know: Well, you're going to have to work. You will have to add all of the handlers you use to the class provided here. Only ones added are the obvious ones: clientHandler and playerHandler.

    Base: Any wL base. You probably use it, right?

    This has been tested: Yes.. But not extensively. KEEP BACKUPS.

    Alright, well there isnt a lot of stuff to do, so let's start.

    Open the client class.
    Now, search for:
    Code:
    if(inStream.readUnsignedByte() != 14) {
    This will be found in your run method.

    Comment or delete the block of code. It looks similar to:
    Code:
    if(inStream.readUnsignedByte() != 14) {
    				shutdownError("Expected login Id 14 from client.");
    				disconnected = true;
    				return;
    			}
    This block will check if packet 14 exists, but of course when we're checking for the packet in the socket process it makes it mysteriously disappear. Big Grin


    Now we have the fun part, we get to redo your server class! Make a backup of your server class, just incase. Smiley
    Replace your WHOLE class with the following: (Yes, I did say REPLACE.)
    Code:
    /*
    * server.java
     * 
     * Version 1.0a
     *
     * Date: Tuesday June 19th, 2008.
     * 
     * Author: Hidendra < [email protected] >
     *
     *  Correctly blocking SYI, and useless **** taken out.
     */
    
    import java.sql.*;
    import java.io.*;
    import java.net.Socket;
    import java.util.StringTokenizer;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    
    public class server implements Runnable {
    	
    	public server() { }
    	
    	public static void main(java.lang.String args[]) {
    		clientHandler = new server();
    		(new Thread(clientHandler)).start();
    		playerHandler = new PlayerHandler();
    		int waitFails = 0;
    		long lastTicks = System.currentTimeMillis();
    		long totalTimeSpentProcessing = 0;
    		int cycle = 0;
    		while(!shutdownServer) {
    			if(updateServer)
    				calcTime();
    			playerHandler.process();
    			System.gc();
    			long timeSpent = System.currentTimeMillis() - lastTicks;
    			totalTimeSpentProcessing += timeSpent;
    			if(timeSpent >= cycleTime) {
    				timeSpent = cycleTime;
    				if(++waitFails > 100) {
    					misc.println("[KERNEL]: machine is too slow to run this server!");
    				}
    			}
    			try {
    				Thread.sleep(cycleTime-timeSpent);
    			} catch(java.lang.Exception _ex) { }
    			lastTicks = System.currentTimeMillis();
    			cycle++;
    			if(cycle % 100 == 0) {
    				float time = ((float)totalTimeSpentProcessing)/cycle;
    			}
    			if (cycle % 3600 == 0) {
    				System.gc();
    			}
    			if (ShutDown == true) {
    				if (ShutDownCounter >= 100) {
    					shutdownServer = true;
    				}
    				ShutDownCounter++;
    			}
    		}
    		playerHandler.destruct();
    		clientHandler.killServer();
    		clientHandler = null;
    	}
    	
    	public void run() {
    		try {
    			shutdownClientHandler = false;
    			clientListener = new java.net.ServerSocket(serverListenerPort, 1, null);
    			misc.println("Running server on port: "+serverListenerPort);
    			misc.println("     Server class revamped by Hidendra.");
    			while(true) {
    				Socket s = clientListener.accept();
    				s.setTcpNoDelay(true);
    				String connectingHost = s.getInetAddress().getHostName();
    				int type = 0;
    				type = s.getInputStream().read();
    				if(clientListener != null) {
    					int Found = -1;
    					for (int i = 0; i < MaxConnections; i++) {
    						if (Connections[i] == connectingHost) {
    							Found = ConnectionCount[i];
    							break;
    						}
    					}
    					if (Found < 3) {
    						if(type == 14) {
    							misc.println("ClientHandler: Accepted from "+connectingHost+":"+s.getPort());
    							playerHandler.newPlayerClient(s, connectingHost);
    						} else {
    							// if you want to do anything for INVALID clients, add it here.
    							//  don't just ipban them box-side (ie: iptables).. 
    							//  because possible connections include, but not limited to:
    							//    - DDoS'ers / SYI
    							//    - Server Status checkers (Mopar's, ETC!)
    							PrintWriter out = new PrintWriter(s.getOutputStream());
    							out.println("HTTP/1.0 200 OK");
    							out.println("Content-Type: text/html");
    							out.println("Server: Bot");
    							out.println("");
    							out.println("You are connecting to this private server VIA a web browser. <br/> <br/> &nbsp; Please connect using a <b>VALID</b> client, like MoparScape. <br/>Thank you!");
    							out.flush();
    							s.close();
    						}
    					}
    				}
    			}
    		} catch(java.io.IOException ioe) {
    			if(!shutdownClientHandler) {
    				misc.println("[FATAL]: Port: "+serverListenerPort+" already in use?");
    			} else {
    				misc.println("ClientHandler was shut down.");
    			}
    		}
    	}
    	
    	public static void calcTime() {
    		long curTime = System.currentTimeMillis();
    		updateSeconds = 180 - ((int)(curTime - startTime) / 1000);
    		if(updateSeconds == 0) {
    			shutdownServer = true;
    		}
    	}
    	
    	public void killServer() {
    		try {
    			shutdownClientHandler = true;
    			if(clientListener != null) clientListener.close();
    			clientListener = null;
    		} catch(java.lang.Exception __ex) {
    			__ex.printStackTrace();
    		}
    	}
    	
    	public static int EnergyRegian = 60;
    	public static int MaxConnections = 999000;
    	public static String[] Connections = new String[MaxConnections];
    	public static int[] ConnectionCount = new int[MaxConnections];
    	public static boolean ShutDown = false;
    	public static int ShutDownCounter = 0;
    	public static final int cycleTime = 500;
    	public static boolean updateServer = false;
    	public static int updateSeconds = 180;
    	public static long startTime;
    	public static Connection connection = null;
    	public static server clientHandler = null;
    	public static java.net.ServerSocket clientListener = null;
    	public static boolean shutdownServer = false;
    	public static boolean shutdownClientHandler;
    	public static int serverListenerPort = 43594;
    	public static PlayerHandler playerHandler = null;
    	
    	
    }
    Now, it should work.. You shouldn't be invadedz by nulls and weird connecting from..'s
    I added a sorta-cool twist to the server class, when your server is running, in a web browser type http://localhostort in your address bar, where port is the port of the server, IE 43594.. I implemented a quick webserver to send that information, you can easily change or remove it by looking at the code. Smiley

    Not really much of a webserver, just a 5 second thing xD.


    Also, you will have to add your handlers yourself, including the public static <class> <othername> yourself, and the new <class>();
    No, I am not doing it for you. If you want DDoS protection, then you're going to have to work for it.

    If you have any questions, please post them here and I will of course try to answer them as best I can..
    Cheers!


    AND I DO REALIZE YOU CAN JUST USE FIREWALL VOIDS I JUST FIND THIS EASIER!
    Attached image
     

  2. #2  
    doodoohead
    Guest
    Either leeched from mopar or you're the same dude who put it on there
    EDIT SAW CREDITS
     

  3. #3  
    brb ridin da storm

    blakeman8192's Avatar
    Join Date
    Dec 2012
    Age
    31
    Posts
    2,012
    Thanks given
    818
    Thanks received
    1,361
    Rep Power
    329
    Yeah and what if they spoof a login procedure like SYI?
    /fail
    rest in peace Qemist, Izzy, Colton, TeChNo PuNk, Impulser, & bootnecklad
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •