AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WardenMac Class Reference

#include "WardenMac.h"

Inheritance diagram for WardenMac:
Warden

Public Member Functions

 WardenMac ()
 
 ~WardenMac () override
 
void Init (WorldSession *session, SessionKey const &k) override
 
ClientWardenModuleGetModuleForClient () override
 
void InitializeModule () override
 
void RequestHash () override
 
void HandleHashResult (ByteBuffer &buff) override
 
void RequestChecks () override
 
void HandleData (ByteBuffer &buff) override
 
- Public Member Functions inherited from Warden
 Warden ()
 
virtual ~Warden ()
 
virtual void Init (WorldSession *session, SessionKey const &k)=0
 
virtual ClientWardenModuleGetModuleForClient ()=0
 
virtual void InitializeModule ()=0
 
virtual void RequestHash ()=0
 
virtual void HandleHashResult (ByteBuffer &buff)=0
 
virtual bool IsCheckInProgress ()=0
 
virtual bool IsInitialized ()
 
virtual void ForceChecks ()=0
 
virtual void RequestChecks ()=0
 
virtual void HandleData (ByteBuffer &buff)=0
 
bool ProcessLuaCheckResponse (std::string const &msg)
 
void SendModuleToClient ()
 
void RequestModule ()
 
void Update (uint32 const diff)
 
void DecryptData (uint8 *buffer, uint32 length)
 
void EncryptData (uint8 *buffer, uint32 length)
 
void ApplyPenalty (uint16 checkId, std::string const &reason)
 
WardenPayloadMgrGetPayloadMgr ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Warden
static bool IsValidCheckSum (uint32 checksum, const uint8 *data, const uint16 length)
 
static uint32 BuildChecksum (const uint8 *data, uint32 length)
 

Detailed Description

Constructor & Destructor Documentation

◆ WardenMac()

WardenMac::WardenMac ( )
30 : Warden()
31{
32}
Warden()
Definition: Warden.cpp:32

◆ ~WardenMac()

WardenMac::~WardenMac ( )
overridedefault

Member Function Documentation

◆ GetModuleForClient()

ClientWardenModule * WardenMac::GetModuleForClient ( )
overridevirtual

Implements Warden.

71{
72 auto mod = new ClientWardenModule;
73
74 // data assign
76 mod->CompressedData = Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data.data();
77
78 // md5 hash
79 mod->Id = Acore::Crypto::MD5::GetDigestOf(mod->CompressedData, mod->CompressedSize);
80 return mod;
81}
std::array< uint8, 9318 > Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data
Definition: WardenModuleMac.h:23
static Digest GetDigestOf(uint8 const *data, std::size_t len)
Definition: CryptoHash.h:48
Definition: Warden.h:94
uint32 CompressedSize
Definition: Warden.h:97

References ClientWardenModule::CompressedSize, Acore::Impl::GenericHash< HashCreator, DigestLength >::GetDigestOf(), and Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data.

Referenced by Init().

◆ HandleData()

void WardenMac::HandleData ( ByteBuffer buff)
overridevirtual

Implements Warden.

206{
207 LOG_DEBUG("warden", "Handle data");
208
209 _dataSent = false;
211
212 //uint16 Length;
213 //buff >> Length;
214 //uint32 Checksum;
215 //buff >> Checksum;
216
217 //if (!IsValidCheckSum(Checksum, buff.contents() + buff.rpos(), Length))
218 //{
219 // buff.rpos(buff.wpos());
220 // if (sWorld->getBoolConfig(CONFIG_BOOL_WARDEN_KICK))
221 // Client->KickPlayer();
222 // return;
223 //}
224
225 //bool found = false;
226
227 std::string str = "Test string!";
228
230 sha1.UpdateData(str);
231 uint32 magic = 0xFEEDFACE; // unsure
232 sha1.UpdateData((uint8*)&magic, 4);
233 sha1.Finalize();
234
236 buff.read(sha1Hash.data(), sha1Hash.size());
237
238 if (sha1Hash != sha1.GetDigest())
239 {
240 LOG_DEBUG("warden", "Handle data failed: SHA1 hash is wrong!");
241 //found = true;
242 }
243
244 auto ourMD5Hash = Acore::Crypto::MD5::GetDigestOf(str);
245 Acore::Crypto::MD5::Digest theirsMD5Hash{};
246 buff.read(theirsMD5Hash);
247
248 if (ourMD5Hash != theirsMD5Hash)
249 {
250 LOG_DEBUG("warden", "Handle data failed: MD5 hash is wrong!");
251 //found = true;
252 }
253
254 _session->KickPlayer("WardenMac::HandleData");
255}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:168
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
Definition: CryptoHash.h:43
void Finalize()
Definition: CryptoHash.h:123
void UpdateData(uint8 const *data, std::size_t len)
Definition: CryptoHash.h:110
std::array< uint8, DIGEST_LENGTH > Digest
Definition: CryptoHash.h:46
Digest const & GetDigest() const
Definition: CryptoHash.h:131
void KickPlayer(bool setKicked=true)
Definition: WorldSession.h:400
uint32 _clientResponseTimer
Definition: Warden.h:147
bool _dataSent
Definition: Warden.h:148
WorldSession * _session
Definition: Warden.h:139
T read()
Definition: ByteBuffer.h:351

References Warden::_clientResponseTimer, Warden::_dataSent, Warden::_session, Acore::Impl::GenericHash< HashCreator, DigestLength >::Finalize(), Acore::Impl::GenericHash< HashCreator, DigestLength >::GetDigest(), Acore::Impl::GenericHash< HashCreator, DigestLength >::GetDigestOf(), WorldSession::KickPlayer(), LOG_DEBUG, ByteBuffer::read(), and Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

◆ HandleHashResult()

void WardenMac::HandleHashResult ( ByteBuffer buff)
overridevirtual

Implements Warden.

122{
123 // test
124 int keyIn[4];
125
126 keyData mod_seed = { { { { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE } } } };
127
128 for (int i = 0; i < 4; ++i)
129 {
130 keyIn[i] = mod_seed.ints.ints[i];
131 }
132
133 int keyOut[4];
134 int keyIn1, keyIn2;
135 keyOut[0] = keyIn[0];
136 keyIn[0] ^= 0xDEADBEEFu;
137 keyIn1 = keyIn[1];
138 keyIn[1] -= 0x35014542u;
139 keyIn2 = keyIn[2];
140 keyIn[2] += 0x5313F22u;
141 keyIn[3] *= 0x1337F00Du;
142 keyOut[1] = keyIn1 - 0x6A028A84;
143 keyOut[2] = keyIn2 + 0xA627E44;
144 keyOut[3] = 0x1337F00D * keyIn[3];
145 // end test
146
147 buff.rpos(buff.wpos());
148
150 sha1.UpdateData((uint8*)keyIn, 16);
151 sha1.Finalize();
152
153 //const uint8 validHash[20] = { 0x56, 0x8C, 0x05, 0x4C, 0x78, 0x1A, 0x97, 0x2A, 0x60, 0x37, 0xA2, 0x29, 0x0C, 0x22, 0xB5, 0x25, 0x71, 0xA0, 0x6F, 0x4E };
154
155 // Verify key
156 if (memcmp(buff.contents() + 1, sha1.GetDigest().data(), 20) != 0)
157 {
158 LOG_DEBUG("warden", "Request hash reply: failed");
159 ApplyPenalty(0, "Request hash reply: failed");
160 return;
161 }
162
163 LOG_DEBUG("warden", "Request hash reply: succeed");
164
165 // client 7F96EEFDA5B63D20A4DF8E00CBF48304
166 //const uint8 client_key[16] = { 0x7F, 0x96, 0xEE, 0xFD, 0xA5, 0xB6, 0x3D, 0x20, 0xA4, 0xDF, 0x8E, 0x00, 0xCB, 0xF4, 0x83, 0x04 };
167
168 // server C2B7ADEDFCCCA9C2BFB3F85602BA809B
169 //const uint8 server_key[16] = { 0xC2, 0xB7, 0xAD, 0xED, 0xFC, 0xCC, 0xA9, 0xC2, 0xBF, 0xB3, 0xF8, 0x56, 0x02, 0xBA, 0x80, 0x9B };
170
171 // change keys here
172 memcpy(_inputKey, keyIn, 16);
173 memcpy(_outputKey, keyOut, 16);
174
177
178 _initialized = true;
179}
void Init(uint8 const *seed, std::size_t len)
Definition: ARC4.cpp:36
Definition: Warden.cpp:163
std::array< uint32, 5 > ints
Definition: Warden.cpp:165
Acore::Crypto::ARC4 _inputCrypto
Definition: Warden.h:144
void ApplyPenalty(uint16 checkId, std::string const &reason)
Definition: Warden.cpp:197
Acore::Crypto::ARC4 _outputCrypto
Definition: Warden.h:145
uint8 _inputKey[16]
Definition: Warden.h:141
uint8 _outputKey[16]
Definition: Warden.h:142
bool _initialized
Definition: Warden.h:150
std::size_t wpos() const
Definition: ByteBuffer.h:330
std::size_t rpos() const
Definition: ByteBuffer.h:317
uint8 * contents()
Definition: ByteBuffer.h:424

References Warden::_initialized, Warden::_inputCrypto, Warden::_inputKey, Warden::_outputCrypto, Warden::_outputKey, Warden::ApplyPenalty(), ByteBuffer::contents(), Acore::Impl::GenericHash< HashCreator, DigestLength >::Finalize(), Acore::Impl::GenericHash< HashCreator, DigestLength >::GetDigest(), Acore::Crypto::ARC4::Init(), keyData::ints, LOG_DEBUG, ByteBuffer::rpos(), Acore::Impl::GenericHash< HashCreator, DigestLength >::UpdateData(), and ByteBuffer::wpos().

◆ Init()

void WardenMac::Init ( WorldSession session,
SessionKey const &  k 
)
overridevirtual

Implements Warden.

37{
38 _session = pClient;
39 // Generate Warden Key
41 WK.Generate(_inputKey, 16);
42 WK.Generate(_outputKey, 16);
43 /*
44 Seed: 4D808D2C77D905C41A6380EC08586AFE (0x05 packet)
45 Hash: <?> (0x04 packet)
46 Module MD5: 0DBBF209A27B1E279A9FEC5C168A15F7
47 New Client Key: <?>
48 New Cerver Key: <?>
49 */
50 uint8 mod_seed[16] = { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE };
51
52 memcpy(_seed, mod_seed, 16);
53
56
57 LOG_DEBUG("warden", "Server side warden for client {} initializing...", pClient->GetAccountId());
58 LOG_DEBUG("warden", "C->S Key: {}", Acore::Impl::ByteArrayToHexStr(_inputKey, 16));
59 LOG_DEBUG("warden", "S->C Key: {}", Acore::Impl::ByteArrayToHexStr(_outputKey, 16 ));
60 LOG_DEBUG("warden", " Seed: {}", Acore::Impl::ByteArrayToHexStr(_seed, 16));
61 LOG_DEBUG("warden", "Loading Module...");
62
64
65 LOG_DEBUG("warden", "Module Key: {}", ByteArrayToHexStr(_module->Key));
66 LOG_DEBUG("warden", "Module ID: {}", ByteArrayToHexStr(_module->Id));
68}
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
Definition: Util.h:381
AC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, std::size_t length, bool reverse=false)
Definition: Util.cpp:545
Definition: SessionKeyGenerator.h:23
std::array< uint8, 16 > Key
Definition: Warden.h:96
std::array< uint8, 16 > Id
Definition: Warden.h:95
uint8 _seed[16]
Definition: Warden.h:143
void RequestModule()
Definition: Warden.cpp:74
ClientWardenModule * _module
Definition: Warden.h:149
ClientWardenModule * GetModuleForClient() override
Definition: WardenMac.cpp:70

References Warden::_inputCrypto, Warden::_inputKey, Warden::_module, Warden::_outputCrypto, Warden::_outputKey, Warden::_seed, Warden::_session, ByteArrayToHexStr(), Acore::Impl::ByteArrayToHexStr(), SessionKeyGenerator< Hash >::Generate(), WorldSession::GetAccountId(), GetModuleForClient(), ClientWardenModule::Id, Acore::Crypto::ARC4::Init(), ClientWardenModule::Key, LOG_DEBUG, and Warden::RequestModule().

◆ InitializeModule()

void WardenMac::InitializeModule ( )
overridevirtual

Implements Warden.

84{
85 LOG_DEBUG("warden", "Initialize module");
86}

References LOG_DEBUG.

◆ RequestChecks()

void WardenMac::RequestChecks ( )
overridevirtual

Implements Warden.

182{
183 LOG_DEBUG("warden", "Request data");
184
185 ByteBuffer buff;
187
188 std::string str = "Test string!";
189
190 buff << uint8(str.size());
191 buff.append(str.c_str(), str.size());
192
193 buff.hexlike();
194
195 // Encrypt with warden RC4 key.
196 EncryptData(buff.contents(), buff.size());
197
198 WorldPacket pkt(SMSG_WARDEN_DATA, buff.size());
199 pkt.append(buff);
200 _session->SendPacket(&pkt);
201
202 _dataSent = true;
203}
@ WARDEN_SMSG_CHEAT_CHECKS_REQUEST
Definition: Warden.h:41
@ SMSG_WARDEN_DATA
Definition: Opcodes.h:772
Definition: WorldPacket.h:27
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:136
Definition: ByteBuffer.h:70
std::size_t size() const
Definition: ByteBuffer.h:444
void hexlike() const
Definition: ByteBuffer.cpp:188
void append(T value)
Definition: ByteBuffer.h:129

References Warden::_dataSent, Warden::_session, ByteBuffer::append(), ByteBuffer::contents(), Warden::EncryptData(), ByteBuffer::hexlike(), LOG_DEBUG, WorldSession::SendPacket(), ByteBuffer::size(), SMSG_WARDEN_DATA, and WARDEN_SMSG_CHEAT_CHECKS_REQUEST.

◆ RequestHash()

void WardenMac::RequestHash ( )
overridevirtual

Implements Warden.

89{
90 LOG_DEBUG("warden", "Request hash");
91
92 // Create packet structure
93 WardenHashRequest Request{};
95 memcpy(Request.Seed, _seed, 16);
96
97 // Encrypt with warden RC4 key.
98 EncryptData((uint8*)&Request, sizeof(WardenHashRequest));
99
101 pkt.append((uint8*)&Request, sizeof(WardenHashRequest));
102 _session->SendPacket(&pkt);
103}
@ WARDEN_SMSG_HASH_REQUEST
Definition: Warden.h:44
Definition: Warden.h:82
uint8 Command
Definition: Warden.h:83

References Warden::_seed, Warden::_session, ByteBuffer::append(), WardenHashRequest::Command, Warden::EncryptData(), LOG_DEBUG, WorldSession::SendPacket(), SMSG_WARDEN_DATA, and WARDEN_SMSG_HASH_REQUEST.