Siga-nos em...
Follow us on Twitter Follow us on Facebook Watch us on YouTube
Registro

Alpha Servers
Resultados 1 a 10 de 14

Visão do Encadeamento

  1. #1

    Avatar de Getulio
    Data de Ingresso
    Mar 2010
    Localização
    char
    Idade
    31
    Posts
    95
    Agradecido
    289
    Agradeceu
    92
    Peso da Avaliação
    0

    Padrão Proteção contra Disconnect Hack & Ataques (Flood) no GS

    Não tenho muito a dizer sobre, afinal, o próprio titulo já diz tudo.

    Proteção contra Disconnect Hack:
    Disconnect.h:
    Código:
    #pragma once
    
    namespace Network
    {
    	struct PMSG_ACTION
    	{
    		PBMSG_HEAD h;
    		unsigned char Direction;
    		unsigned char Action;
    		unsigned char TargetH;
    		unsigned char TargetL;
    	};
    
    	struct DisconnectStruct
    	{
    		bool Send;
    		unsigned long Timer;
    		unsigned long Count;
    	};
    
    	class Disconnect
    	{
    	public:
    		static void Action(PMSG_ACTION* lpMsg, DWORD dwIndex);
    
    	public:
    		static DisconnectStruct Struct[1000];
    	};
    }
    Disconnect.cpp:
    Código:
    #include "Disconnect.h"
    
    namespace Network
    {
    	DisconnectStruct Disconnect::Struct[1000];
    
    	void Disconnect::Action(PMSG_ACTION* lpMsg, DWORD dwIndex)
    	{
    		WORD szIndex = (WORD)(dwIndex - 4800);
    
    		if(!Struct[szIndex].Send)
    		{
    			return;
    		}
    
    		if(Struct[szIndex].Timer <= 0)
    		{
    			Struct[szIndex].Timer = GetTickCount();
    		}
    	
    		if(Struct[szIndex].Count >= 15)
    		{
    			DWORD dwTimer = (GetTickCount() - Struct[szIndex].Timer) / 1000;
    		
    			if(dwTimer <= 1)
    			{
    				Struct[szIndex].Send = false;
    				ServerCloseClient(dwIndex, 0);
    			}
    			else
    			{
    				Struct[szIndex].Count = 0;
    				Struct[szIndex].Timer = GetTickCount();
    			}
    		}
    
    		Struct[szIndex].Count++;
    
    		ServerActionPlayer(lpMsg, dwIndex);		
    	}
    }
    Hook:
    Código:
    Hook((DWORD)&Network::Disconnect::Action, 0x401A1E);
    Define:
    Código:
    #define ServerActionPlayer		((void(*)(Network::PMSG_ACTION*, DWORD)) 0x425CD0)

    Proteção contra Ataques (Flood) no GS - (impedindo lotação de servers):
    Flood.h:
    Código:
    #pragma once
    
    namespace Network
    {
    	struct FloodCheck
    	{
    		bool Send;
    		bool Delete;
    		unsigned long Timer;
    		unsigned long Count;
    		std::string Address;
    	};
    
    	struct FloodStruct
    	{
    		FloodCheck Check;
    		std::string Address;
    	};
    
    	class Flood
    	{
    	public:
    		static bool Inits();
    		static bool Check(std::string szAddress);
    		static short stringExplode(std::string szAddress, std::string szExplode);
    		static short Connection(SOCKET szSocket, char* szAddress);
    
    	public:
    		static FloodStruct Struct[500];
    
    	public:
    		static unsigned long Count;
    	};
    }
    Flood.cpp:
    Código:
    #include "Library.h"
    
    namespace Network
    {
    	FloodStruct Flood::Struct[500];
    	unsigned long Flood::Count;
    
    	bool Flood::Init()
    	{
    		for(int i = 0; i < 500; i++)
    		{
    			Struct[i].Address = "";
    		}
    
    		Count = 0;
    
    		std::fstream f(".\\Network\\Block\\IpAddress.txt", std::ios::in);
    		
    		if(f.is_open() && f.good())
    		{
    			BYTE szNum = 0;
    			char szBuffer[1024];
    			std::string szLine;
    
    			while(!f.eof())
    			{
    				if(Count == 500)
    				{
    					MessageBox(NULL, "O limite de endereço IP de usuários foi excedido.", "Erro", MB_OK | MB_ICONERROR);
    					break;
    				}
    
    				memset(&szBuffer[0], 0x00, 1024);
    				f.getline(szBuffer, 1024);
    				szLine.assign(&szBuffer[0]);
    
    				if(szLine.length() > 9)
    				{
    					if(szLine.substr(0, 2) != "//" && szLine.substr(0, 1) != "#" && szLine.substr(0, 1) != ";")
    					{
    						szNum = (BYTE)Count;
    
    						for(int i = 0; i < (int)szLine.length(); i++)
    						{
    							if(szLine[i] != ' ' && szLine[i] != '\t' && szLine[i] != '"')
    							{
    								if(isdigit(szLine.c_str()[i]) || szLine[i] == '.')
    								{
    									Struct[szNum].Address += szLine[i];
    								}
    								else
    								{
    									f.close();
    									MessageBox(NULL, "O arquivo IpAddress.txt está configurado de forma inadequada.", "Erro", MB_OK | MB_ICONERROR);
    									return false;
    								}
    							}
    						}
    					
    						Count++;
    					}
    				}
    			}
    
    			f.close();
    
    			return true;
    		}
    
    		return false;
    	}
    
    	short Flood::stringExplode(std::string szAddress, std::string szExplode)
    	{
    		BYTE szId = 0, szDec[4] = {0};
    		std::string szConvert = "";
    	
    		for(int i = 0; i <= (int)szAddress.length(); i++)
    		{
    			if(!szAddress.compare(i, 1, szExplode) || i == szAddress.length())
    			{
    				szDec[szId] = (BYTE)atoi((char*)szConvert.c_str());
    				szConvert = "";
    				szId++;
    			}
    			else
    			{
    				szConvert += szAddress[i];
    			}
    		}
    
    		float szResult = (float)(((szDec[0] + szDec[1]) - szDec[2]) + (szDec[3] * 2)) / 2;
    
    		if((szResult > 400))
    		{
    			szResult /= 2;
    		}
    
    		return (short)szResult;
    	}
    
    	bool Flood::Check(std::string szAddress)
    	{
    		WORD szIndex = Function::stringExplode(szAddress, (std::string)".");
    
    		if(Count > 0)
    		{
    			for(int i = 0; i < (int)Count; i++)
    			{
    				if(Struct[i].Address.empty())
    				{
    					break;
    				}
    
    				if((boost::iequals(Struct[i].Address, szAddress)))
    				{
    					if(!Struct[szIndex].Check.Delete)
    					{
    						for(int i = 4800; i < 5800; i++)
    						{
    							if(Object[i].Connected <= 1)
    							{
    								if(boost::iequals(Object[i].IpAddress, szAddress.c_str()))
    								{
    									ServerDelete(i);
    								}
    							}
    						}
    
    						Struct[szIndex].Check.Delete++;
    					}
    
    					return false;
    				}
    			}
    		}
    
    		if(Struct[szIndex].Check.Timer <= 0)
    		{
    			Struct[szIndex].Check.Send	  = true;
    			Struct[szIndex].Check.Delete  = false;
    			Struct[szIndex].Check.Address = szAddress;
    			Struct[szIndex].Check.Timer	  = GetTickCount();
    			Struct[szIndex].Check.Count   = 0;
    		}
    
    		if(!Struct[szIndex].Check.Send)
    		{
    			if(boost::iequals(Struct[szIndex].Check.Address, szAddress))
    			{
    				return false;
    			}
    		}
    
    		if(Struct[szIndex].Check.Count >= 2)
    		{
    			DWORD dwTimer = (GetTickCount() - Struct[szIndex].Check.Timer) / 1000;
    			
    			if(dwTimer <= 1)
    			{
    				Struct[szIndex].Check.Send	  = false;
    				Struct[szIndex].Check.Delete  = false;
    				Struct[szIndex].Check.Address = szAddress;
    
    				bool szWriteProceed = false;
    				
    				if(Count < 500)
    				{
    					if(Count == 499)
    					{
    						if(Struct[499].Address.empty())
    						{
    							Struct[499].Check.Address = szAddress;
    							szWriteProceed = true;
    						}
    					}
    					else
    					{
    						BYTE szNum = (BYTE)Count;
    						Struct[szNum].Address = szAddress;
    						szWriteProceed = true;
    						Count++;
    					}
    				}
    
    				if(szWriteProceed)
    				{
    					std::fstream f(".\\Network\\Block\\IpAddress.txt", std::ios::app | std::ios::out);
    					
    					if(f.is_open() && f.good())
    					{
    						std::string Msg(255, ' ');
    						
    						sprintf_s(&Msg[0], 255, "\"%s\"\n", &szAddress[0]);
    
    						f.write(Msg.c_str(), Msg.length());
    						f.close();
    					}
    				}
    			}
    			else
    			{
    				if(!boost::iequals(Struct[szIndex].Check.Address, szAddress))
    				{
    					Struct[szIndex].Check.Send	  = true;
    					Struct[szIndex].Check.Delete  = false;
    					Struct[szIndex].Check.Address = szAddress;
    				}
    
    				Struct[szIndex].Check.Timer = GetTickCount();
    				Struct[szIndex].Check.Count = 0;
    			}
    		}
    		
    		Struct[szIndex].Check.Count++;
    
    		return true;
    	}
    
    	short Flood::Connection(SOCKET szSocket, char* szAddress)
    	{
    		if(!Check((std::string)szAddress))
    		{
    			return (-1);
    		}
    
    		return ServerConnect(szSocket, szAddress);
    	}
    }
    Hook:
    Código:
    Hook((DWORD)&Network::Flood::Connection, 0x401834);
    Define:
    Código:
    #define ServerConnect			((short(*)(SOCKET, char*)) 0x45F0F0)

    Lembrando, os offsets utilizados em ambos, são da versão 97d.


    Créditos:
    Network.
    Última edição por Getulio; 03-04-2012 às 01:16 AM.

 

 

Informações de Tópico

Usuários Navegando neste Tópico

Há 1 usuários navegando neste tópico. (0 registrados e 1 visitantes)

Tópicos Similares

  1. |Source| Proteção contra debuggers e Ant Inject
    Por Sain no fórum Delphi
    Respostas: 3
    Último Post: 11-04-2014, 09:42 PM
  2. DUVIDA COMO PROTEJER CONTRA ATAQUES NO Case Sensitive
    Por TOMASBORUS no fórum Dúvidas
    Respostas: 7
    Último Post: 05-05-2012, 02:19 PM
  3. |Source| Proteção contra Skill Bug
    Por Getulio no fórum Sources
    Respostas: 0
    Último Post: 02-04-2012, 01:39 AM
  4. |Source| Proteção contra Trade Hack
    Por Getulio no fórum Sources
    Respostas: 0
    Último Post: 01-04-2012, 04:17 AM
  5. |Tutorial| Defendendo contra Ataques DDoS / Flood GS/ Sprut.
    Por mustx1 no fórum Servers
    Respostas: 22
    Último Post: 22-03-2011, 03:20 PM

Marcadores

Permissões de Postagem

  • Você não pode iniciar novos tópicos
  • Você não pode enviar respostas
  • Você não pode enviar anexos
  • Você não pode editar suas mensagens
  •