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
76
77 // data assign
78 mod->CompressedSize = length;
79 mod->CompressedData = new uint8[length];
80 memcpy(mod->CompressedData, Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data.data(), length);
81
82 // md5 hash
83 mod->Id = Acore::Crypto::MD5::GetDigestOf(mod->CompressedData, mod->CompressedSize);
84 return mod;
85}
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
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.

210{
211 LOG_DEBUG("warden", "Handle data");
212
213 _dataSent = false;
215
216 //uint16 Length;
217 //buff >> Length;
218 //uint32 Checksum;
219 //buff >> Checksum;
220
221 //if (!IsValidCheckSum(Checksum, buff.contents() + buff.rpos(), Length))
222 //{
223 // buff.rpos(buff.wpos());
224 // if (sWorld->getBoolConfig(CONFIG_BOOL_WARDEN_KICK))
225 // Client->KickPlayer();
226 // return;
227 //}
228
229 //bool found = false;
230
231 std::string str = "Test string!";
232
234 sha1.UpdateData(str);
235 uint32 magic = 0xFEEDFACE; // unsure
236 sha1.UpdateData((uint8*)&magic, 4);
237 sha1.Finalize();
238
240 buff.read(sha1Hash.data(), sha1Hash.size());
241
242 if (sha1Hash != sha1.GetDigest())
243 {
244 LOG_DEBUG("warden", "Handle data failed: SHA1 hash is wrong!");
245 //found = true;
246 }
247
248 auto ourMD5Hash = Acore::Crypto::MD5::GetDigestOf(str);
249 Acore::Crypto::MD5::Digest theirsMD5Hash{};
250 buff.read(theirsMD5Hash);
251
252 if (ourMD5Hash != theirsMD5Hash)
253 {
254 LOG_DEBUG("warden", "Handle data failed: MD5 hash is wrong!");
255 //found = true;
256 }
257
258 _session->KickPlayer("WardenMac::HandleData");
259}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
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:482

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.

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

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:372
Definition SessionKeyGenerator.h:23
ClientWardenModule * GetModuleForClient() override
Definition WardenMac.cpp:71
uint8 _seed[16]
Definition Warden.h:142
void RequestModule()
Definition Warden.cpp:76
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.

88{
89 LOG_DEBUG("warden", "Initialize module");
90}

References LOG_DEBUG.

◆ RequestChecks()

void WardenMac::RequestChecks ( )
overridevirtual

Implements Warden.

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

93{
94 LOG_DEBUG("warden", "Request hash");
95
96 // Create packet structure
97 WardenHashRequest Request{};
99 memcpy(Request.Seed, _seed, 16);
100
101 // Encrypt with warden RC4 key.
102 EncryptData((uint8*)&Request, sizeof(WardenHashRequest));
103
105 pkt.append((uint8*)&Request, sizeof(WardenHashRequest));
106 _session->SendPacket(&pkt);
107}
@ 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: