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 bool IsCheckInProgress ()=0
 
virtual bool IsInitialized ()
 
virtual void ForceChecks ()=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, uint8 const *data, const uint16 length)
 
static uint32 BuildChecksum (uint8 const *data, uint32 length)
 

Detailed Description

Constructor & Destructor Documentation

◆ WardenMac()

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

◆ ~WardenMac()

WardenMac::~WardenMac ( )
overridedefault

Member Function Documentation

◆ GetModuleForClient()

ClientWardenModule * WardenMac::GetModuleForClient ( )
overridevirtual

Implements Warden.

72{
73 auto mod = new ClientWardenModule;
74
75 // data assign
77 mod->CompressedData = Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data.data();
78
79 // md5 hash
80 mod->Id = Acore::Crypto::MD5::GetDigestOf(mod->CompressedData, mod->CompressedSize);
81 return mod;
82}
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:93
uint32 CompressedSize
Definition Warden.h:96

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.

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

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.

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

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.

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

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.

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

References LOG_DEBUG.

◆ RequestChecks()

void WardenMac::RequestChecks ( )
overridevirtual

Implements Warden.

183{
184 LOG_DEBUG("warden", "Request data");
185
186 ByteBuffer buff;
188
189 std::string str = "Test string!";
190
191 buff << uint8(str.size());
192 buff.append(str.c_str(), str.size());
193
194 buff.hexlike();
195
196 // Encrypt with warden RC4 key.
197 EncryptData(buff.contents(), buff.size());
198
199 WorldPacket pkt(SMSG_WARDEN_DATA, buff.size());
200 pkt.append(buff);
201 _session->SendPacket(&pkt);
202
203 _dataSent = true;
204}
@ WARDEN_SMSG_CHEAT_CHECKS_REQUEST
Definition Warden.h:40
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
void EncryptData(uint8 *buffer, uint32 length)
Definition Warden.cpp:135
Definition WorldPacket.h:26
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition WorldSession.cpp:226
@ SMSG_WARDEN_DATA
Definition Opcodes.h:772

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.

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

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


The documentation for this class was generated from the following files: