aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Server
diff options
context:
space:
mode:
authorMachiavelli <machiavelli.trinity@gmail.com>2013-08-29 16:43:37 +0100
committerMachiavelli <machiavelli.trinity@gmail.com>2013-08-29 16:46:28 +0100
commit59b4c3492482b7536651625f0b1ed0ef87f52e79 (patch)
tree2202ea149e9e970cccfc2ad1a309756e693a0885 /src/server/game/Server
parent3b71172e8a0fdda1da9e64f880cb184a7b617e93 (diff)
Core/NetworkIO: Generic packet spam solution
Currently regulates the usage of CMSG_CHAR_ENUM only, but can be easily extended to detect inappropriate network behaviour by using AntiDOS.AllowOpcode in WorldSession's handlers.
Diffstat (limited to 'src/server/game/Server')
-rw-r--r--src/server/game/Server/WorldSession.cpp14
-rw-r--r--src/server/game/Server/WorldSession.h77
2 files changed, 88 insertions, 3 deletions
diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp
index 5519f1d4d0e..ce1db7fcac7 100644
--- a/src/server/game/Server/WorldSession.cpp
+++ b/src/server/game/Server/WorldSession.cpp
@@ -118,7 +118,8 @@ WorldSession::WorldSession(uint32 id, WorldSocket* sock, AccountTypes sec, uint8
recruiterId(recruiter),
isRecruiter(isARecruiter),
timeLastWhoCommand(0),
- _RBACData(NULL)
+ _RBACData(NULL),
+ AntiDOS(this)
{
if (sock)
{
@@ -274,13 +275,19 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
!_recvQueue.empty() && _recvQueue.peek(true) != firstDelayedPacket &&
_recvQueue.next(packet, updater))
{
- if (packet->GetOpcode() >= NUM_MSG_TYPES)
+ if (!AntiDOS.EvaluateOpcode(*packet))
+ {
+ delete packet;
+ KickPlayer();
+ }
+
+ if (packet && packet->GetOpcode() >= NUM_MSG_TYPES)
{
TC_LOG_ERROR(LOG_FILTER_OPCODES, "Received non-existed opcode %s from %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str()
, GetPlayerInfo().c_str());
sScriptMgr->OnUnknownPacketReceive(m_Socket, WorldPacket(*packet));
}
- else
+ else if (packet)
{
OpcodeHandler &opHandle = opcodeTable[packet->GetOpcode()];
try
@@ -547,6 +554,7 @@ void WorldSession::LogoutPlayer(bool save)
m_playerLogout = false;
m_playerSave = false;
m_playerRecentlyLogout = true;
+ AntiDOS.AllowOpcode(CMSG_CHAR_ENUM, true);
LogoutRequest(0);
}
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index bf79b34822d..721bdb06c8a 100644
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -30,6 +30,7 @@
#include "World.h"
#include "WorldPacket.h"
#include "Cryptography/BigNumber.h"
+#include "AccountMgr.h"
class Creature;
class GameObject;
@@ -911,6 +912,82 @@ class WorldSession
QueryCallback<PreparedQueryResult, CharacterCreateInfo*, true> _charCreateCallback;
QueryResultHolderFuture _charLoginCallback;
+ friend class World;
+ protected:
+ class DosProtection
+ {
+ friend class World;
+ public:
+ DosProtection(WorldSession* s) : Session(s), _policy((Policy)sWorld->getIntConfig(CONFIG_PACKET_SPOOF_POLICY)) {}
+
+ bool EvaluateOpcode(WorldPacket& p) const
+ {
+ if (IsOpcodeAllowed(p.GetOpcode()))
+ return true;
+
+ // Opcode not allowed, let the punishment begin
+ sLog->outInfo(LOG_FILTER_NETWORKIO, "AntiDOS: Account %u, IP: %s, sent unacceptable packet (opc: %u, size: %u)",
+ Session->GetAccountId(), Session->GetRemoteAddress().c_str(), p.GetOpcode(), p.size());
+
+ switch (_policy)
+ {
+ case POLICY_LOG:
+ return true;
+ case POLICY_KICK:
+ sLog->outInfo(LOG_FILTER_NETWORKIO, "AntiDOS: Player kicked!");
+ return false;
+ case POLICY_BAN:
+ {
+ BanMode bm = (BanMode)sWorld->getIntConfig(CONFIG_PACKET_SPOOF_BANMODE);
+ int64 duration = (int64)sWorld->getIntConfig(CONFIG_PACKET_SPOOF_BANDURATION); // in seconds
+ std::string nameOrIp = "";
+ switch (bm)
+ {
+ case BAN_ACCOUNT: (void)sAccountMgr->GetName(Session->GetAccountId(), nameOrIp); break;
+ case BAN_IP: nameOrIp = Session->GetRemoteAddress(); break;
+ }
+ sWorld->BanAccount(bm, nameOrIp, duration, "DOS (Packet Flooding/Spoofing", "Server: AutoDOS");
+ sLog->outInfo(LOG_FILTER_NETWORKIO, "AntiDOS: Player automatically banned for "I64FMT" seconds.", duration);
+
+ return false;
+ }
+ default: // invalid policy
+ return true;
+ }
+ }
+
+ void AllowOpcode(uint16 opcode, bool allow)
+ {
+ _isOpcodeAllowed[opcode] = allow;
+ }
+
+ protected:
+ enum Policy
+ {
+ POLICY_LOG,
+ POLICY_KICK,
+ POLICY_BAN,
+ };
+
+ bool IsOpcodeAllowed(uint16 opcode) const
+ {
+ OpcodeStatusMap::const_iterator itr = _isOpcodeAllowed.find(opcode);
+ if (itr == _isOpcodeAllowed.end())
+ return true; // No presence in the map indicates this is the first time the opcode was sent this session, so allow
+
+ return itr->second;
+ }
+
+ WorldSession* Session;
+
+ private:
+ typedef UNORDERED_MAP<uint16, bool> OpcodeStatusMap;
+ OpcodeStatusMap _isOpcodeAllowed; // could be bool array, but wouldn't be practical for game versions with non-linear opcodes
+ Policy _policy;
+
+
+ } AntiDOS;
+
private:
// private trade methods
void moveItems(Item* myItems[], Item* hisItems[]);