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 ( )
29 : Warden()
30{
31}
Warden()
Definition: Warden.cpp:32

◆ ~WardenMac()

WardenMac::~WardenMac ( )
overridedefault

Member Function Documentation

◆ GetModuleForClient()

ClientWardenModule * WardenMac::GetModuleForClient ( )
overridevirtual

Implements Warden.

70{
71 auto mod = new ClientWardenModule;
72
73 // data assign
75 mod->CompressedData = Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data.data();
76
77 // md5 hash
78 mod->Id = Acore::Crypto::MD5::GetDigestOf(mod->CompressedData, mod->CompressedSize);
79 return mod;
80}
std::array< uint8, 9318 > Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data
Definition: WardenModuleMac.h:23
static Digest GetDigestOf(uint8 const *data, size_t len)
Definition: CryptoHash.h:53
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.

205{
206 LOG_DEBUG("warden", "Handle data");
207
208 _dataSent = false;
210
211 //uint16 Length;
212 //buff >> Length;
213 //uint32 Checksum;
214 //buff >> Checksum;
215
216 //if (!IsValidCheckSum(Checksum, buff.contents() + buff.rpos(), Length))
217 //{
218 // buff.rpos(buff.wpos());
219 // if (sWorld->getBoolConfig(CONFIG_BOOL_WARDEN_KICK))
220 // Client->KickPlayer();
221 // return;
222 //}
223
224 //bool found = false;
225
226 std::string str = "Test string!";
227
229 sha1.UpdateData(str);
230 uint32 magic = 0xFEEDFACE; // unsure
231 sha1.UpdateData((uint8*)&magic, 4);
232 sha1.Finalize();
233
235 buff.read(sha1Hash.data(), sha1Hash.size());
236
237 if (sha1Hash != sha1.GetDigest())
238 {
239 LOG_DEBUG("warden", "Handle data failed: SHA1 hash is wrong!");
240 //found = true;
241 }
242
243 auto ourMD5Hash = Acore::Crypto::MD5::GetDigestOf(str);
244 Acore::Crypto::MD5::Digest theirsMD5Hash{};
245 buff.read(theirsMD5Hash);
246
247 if (ourMD5Hash != theirsMD5Hash)
248 {
249 LOG_DEBUG("warden", "Handle data failed: MD5 hash is wrong!");
250 //found = true;
251 }
252
253 _session->KickPlayer("WardenMac::HandleData");
254}
std::uint8_t uint8
Definition: Define.h:110
std::uint32_t uint32
Definition: Define.h:108
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
Definition: CryptoHash.h:48
void UpdateData(uint8 const *data, size_t len)
Definition: CryptoHash.h:115
void Finalize()
Definition: CryptoHash.h:128
std::array< uint8, DIGEST_LENGTH > Digest
Definition: CryptoHash.h:51
Digest const & GetDigest() const
Definition: CryptoHash.h:136
void KickPlayer(bool setKicked=true)
Definition: WorldSession.h:399
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.

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

36{
37 _session = pClient;
38 // Generate Warden Key
40 WK.Generate(_inputKey, 16);
41 WK.Generate(_outputKey, 16);
42 /*
43 Seed: 4D808D2C77D905C41A6380EC08586AFE (0x05 packet)
44 Hash: <?> (0x04 packet)
45 Module MD5: 0DBBF209A27B1E279A9FEC5C168A15F7
46 New Client Key: <?>
47 New Cerver Key: <?>
48 */
49 uint8 mod_seed[16] = { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE };
50
51 memcpy(_seed, mod_seed, 16);
52
55
56 LOG_DEBUG("warden", "Server side warden for client {} initializing...", pClient->GetAccountId());
57 LOG_DEBUG("warden", "C->S Key: {}", Acore::Impl::ByteArrayToHexStr(_inputKey, 16));
58 LOG_DEBUG("warden", "S->C Key: {}", Acore::Impl::ByteArrayToHexStr(_outputKey, 16 ));
59 LOG_DEBUG("warden", " Seed: {}", Acore::Impl::ByteArrayToHexStr(_seed, 16));
60 LOG_DEBUG("warden", "Loading Module...");
61
63
64 LOG_DEBUG("warden", "Module Key: {}", ByteArrayToHexStr(_module->Key));
65 LOG_DEBUG("warden", "Module ID: {}", ByteArrayToHexStr(_module->Id));
67}
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
Definition: Util.h:376
AC_COMMON_API std::string ByteArrayToHexStr(uint8 const *bytes, size_t length, bool reverse=false)
Definition: Util.cpp:541
Definition: SessionKeyGenerator.h:26
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:69

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.

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

References LOG_DEBUG.

◆ RequestChecks()

void WardenMac::RequestChecks ( )
overridevirtual

Implements Warden.

181{
182 LOG_DEBUG("warden", "Request data");
183
184 ByteBuffer buff;
186
187 std::string str = "Test string!";
188
189 buff << uint8(str.size());
190 buff.append(str.c_str(), str.size());
191
192 buff.hexlike();
193
194 // Encrypt with warden RC4 key.
195 EncryptData(buff.contents(), buff.size());
196
197 WorldPacket pkt(SMSG_WARDEN_DATA, buff.size());
198 pkt.append(buff);
199 _session->SendPacket(&pkt);
200
201 _dataSent = true;
202}
@ 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:207
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:136
Definition: ByteBuffer.h:70
void hexlike() const
Definition: ByteBuffer.cpp:189
void append(T value)
Definition: ByteBuffer.h:129
size_t size() const
Definition: ByteBuffer.h:444

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.

88{
89 LOG_DEBUG("warden", "Request hash");
90
91 // Create packet structure
92 WardenHashRequest Request{};
94 memcpy(Request.Seed, _seed, 16);
95
96 // Encrypt with warden RC4 key.
97 EncryptData((uint8*)&Request, sizeof(WardenHashRequest));
98
100 pkt.append((uint8*)&Request, sizeof(WardenHashRequest));
101 _session->SendPacket(&pkt);
102}
@ 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.