funnyjesterscape
Would you like to react to this message? Create an account in a few clicks or log in to continue.


Forums made by Drew
 
HomeHome  PortalPortal  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 Basic anti SYI

Go down 
AuthorMessage
Qwerty Skill




Posts : 3
Join date : 2008-11-01

Basic anti SYI Empty
PostSubject: Basic anti SYI   Basic anti SYI Icon_minitimeSat Nov 22, 2008 1:30 pm

Hi guys this is my first tutorial on this forum Very Happy. I made a tutorial about this on runelocus and I just copy and pasted it on here

There's two options on how to make an anti SYI.

1) Get a firewall that blocks out ip addresses, when someone try's to SYI your server, simply add their IP address to your firewall and they'll never be able to conect to you're server again Very Happy.

2) This only works for the Devolution source which is mostly for advanced coders. (Before doing this make sure you make a backup) and this ONLY WORKS FOR DEVOLUTION SOURCE

ConnectionFilter.java
----------------------------

What does this do?
This ConnectionFilter will filter out fast and normal client connection speeds usually if you connect 3 or more times within 10ms it's not a real client. Si if that does happen it will temporarily ban that hostname until it is done flooding the server. With the extra features i added, like the isWasFlooder will print in the server if a person logs on in a real client and they have tryed to flood the server before, so you will know they tryed
Note: This tutorial is not compatible with Grahams Remove Thread-Per-Client.

Step 1
Make a new java file named ConnectionFilter.java and put this in it.

import java.util.ArrayList;

/**
* Filters out fast and normal client connection speeds.
* SYI/DoS Flooding Protection.
* @author Qwerty
*
*/
public class ConnectionFilter
{

private static ArrayList<String> HOST_LIST = new ArrayList<String>();
private static ArrayList<String> CONNECTIONS = new ArrayList<String>();

private int cycle;
private boolean isFlooder;
private boolean wasFlooder;
private boolean wasConnected;

public ConnectionFilter()
{
System.out.println("[ConnectionFilter] - Initialized");
}

/**
* Setter for isFlooder boolean
* @param isFlooder
*/
private void setFlooder(boolean isFlooder)
{
this.isFlooder = isFlooder;
}

/**
* Setter for wasFlooder boolean
* @param wasFlooder
*/
private void setWasFlooder(boolean wasFlooder)
{
this.wasFlooder = wasFlooder;
}

/**
* Setter for wasConnected boolean
* @param wasConnected
*/
private void setWasConnected(boolean wasConnected)
{
this.wasConnected = wasConnected;
}

/**
* @return isFlooder
*/
private boolean isFlooder()
{
return isFlooder;
}

/**
* @return isWasFlooder
*/
private boolean isWasFlooder()
{
return wasFlooder;
}

/**
* @return wasConnected
*/
@SuppressWarnings("unused")
private boolean isWasConnected()
{
return wasConnected;
}

/**
* Setter for HOST_LIST array
* @param hOST_LIST ArrayList
*/
public static void setHOST_LIST(ArrayList<String> hOST_LIST)
{
HOST_LIST = hOST_LIST;
}

/**
* @return ArrayList HOST_LIST
* @param getHOST_LIST ArrayList
*/
public static ArrayList<String> getHOST_LIST()
{
return HOST_LIST;
}

/**
* Setter for CONNECTIONS array
* @param cONNECTIONS ArrayList
*/
public static void setCONNECTIONS(ArrayList<String> cONNECTIONS)
{
CONNECTIONS = cONNECTIONS;
}

/**
* @return ArrayList CONNECTIONS
* @param getConnections ArrayList
*/
public static ArrayList<String> getCONNECTIONS()
{
return CONNECTIONS;
}

/**
* Adds a hostname to the HOST_LIST array list
* @param host String
*/
public void add(String host)
{
System.out.println((new StringBuilder("[ConnectionFilter] Temporarily banning ")).append(host).append(" (Massive Connecting Flooding)").toString());
getHOST_LIST().add(host);
}

/**
* Checks for any blocked hostnames
* @param host String
*/
public boolean blocked(String host)
{
for (String h : HOST_LIST)
{
if (h.equals(host))
return true;
}

int n = 0;
for (String h : CONNECTIONS)
{
if (host.equals(h))
{
n++;
}
}

if (n > 2)
{
add(host);
setFlooder(true);
return true;
}

if(isFlooder())
return true;

if(isWasFlooder())
{
/* Handle anything you want to do to a person that tryed flooding the server in the past. */
}
return false;
}

/**
* 500ms Process, used for clearing out the array's after a given time in the cycle
*/
public void process()
{
if(cycle % 10 == 0)
{
getCONNECTIONS().clear();
setWasConnected(true);
}
if(cycle % 500 == 0)
{
getHOST_LIST().clear();
setFlooder(false);
setWasFlooder(true);
}
if(cycle > 10000)
{
cycle = 0;
}
cycle++;
}

}This bit is a for loop that will go through the HOST_LIST array.


Quote:
if (h.equals(host))
return true;

That will make the boolean return true if the current host is in the HOST_LIST array.

Quote:
for (String h : HOST_LIST)
{
if (h.equals(host))
return true;
}

This bit
int n = 0; declares the integer n at a value of zero
for (String h : CONNECTIONS) is a for loop that goes through the CONNECTIONS array.


Quote:
if (host.equals(h))
n++;

That will will make the integer go up by 1


Quote:
int n = 0;
for (String h : CONNECTIONS)
{
if (host.equals(h))
{
n++;
}
}

This bit is checking if the integer is over 2 which would be 3 or higher
And if it is it will.
add(Host) add it to the temp banned ips list
setFlooder(true); making the server know that the person is a flooder
return true; will return the boolean blocked() to true

Quote:
if (n > 2)
{
add(host);
setFlooder(true);
return true;
}

Step 2
Open Server.java.
2.1)
Declare


public static ConnectionFilter ConnectionFilter = null;This makes the ConnectionFilter a static class.

2.2)
Under,


public static void main(String args[]) {Add,

Code:
ConnectionFilter = new ConnectionFilter();This will start the ConnectionFilter when the server starts.

2.3)
Find,

Code:
while(!shutdownServer) {Under it add,

Code:
ConnectionFilter.process();This will make the process() method in ConnectionFilter run at 500ms

2.4)
Find,

Code:
playerHandler.newPlayerClient(s, connectingHost);Above it add,

Code:
if(!ConnectionFilter.blocked(connectingHost)) {And under it add,

Code:
} else
{
System.out.println("[ConnectionFilter] Rejected "+connectingHost+" [Massive flooding]");
s.close();
System.gc();
}System.out.println() will print in the server console
s.close(); will close the current socket the player used.
System.gc(); is gc > garbage collect and will collect unused garbage from your RAM that the server used.
That basicly is checking to see if the connecting host is NOT blocked (the ! is saying "if is not") . And if it is it will add the new player.
Now save and close Server.java

Step 3
Open playerHandler.java and find

Code:
newPlayerClientScroll down a little bit until you find,

Code:
(new Thread(newClient)).start();Under that add,

Code:
ConnectionFilter.getCONNECTIONS().add(connectedFrom);This will remove the host from the connections array if the player gets disconnected.
Now save and close playerHandler.java

Credits:Qwerty
__________________


Later i'll tell you guys how to edit the azn cheat client to make your self owner and stuff ^.^
Back to top Go down
 
Basic anti SYI
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
funnyjesterscape :: Tutorials :: post tutorials here-
Jump to: