TrinityCore
WardenMac.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WardenMac.h"
19#include "ByteBuffer.h"
20#include "Common.h"
21#include "CryptoHash.h"
22#include "GameTime.h"
23#include "Log.h"
24#include "Opcodes.h"
25#include "SessionKeyGenerator.h"
26#include "Util.h"
27#include "WardenModuleMac.h"
28#include "WorldPacket.h"
29#include "WorldSession.h"
30
31#include <array>
32
34
36
37void WardenMac::Init(WorldSession* pClient, SessionKey const& K)
38{
39 _session = pClient;
40 // Generate Warden Key
42 WK.Generate(_inputKey.data(), 16);
43 WK.Generate(_outputKey.data(), 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
52 _seed = { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE };
53
56 TC_LOG_DEBUG("warden", "Server side warden for client {} initializing...", pClient->GetAccountId());
57 TC_LOG_DEBUG("warden", "C->S Key: {}", ByteArrayToHexStr(_inputKey));
58 TC_LOG_DEBUG("warden", "S->C Key: {}", ByteArrayToHexStr(_outputKey));
59 TC_LOG_DEBUG("warden", " Seed: {}", ByteArrayToHexStr(_seed));
60 TC_LOG_DEBUG("warden", "Loading Module...");
61
63
64 TC_LOG_DEBUG("warden", "Module Key: {}", ByteArrayToHexStr(_module->Key));
65 TC_LOG_DEBUG("warden", "Module ID: {}", ByteArrayToHexStr(_module->Id));
67}
68
70{
71 // data assign
74}
75
77{
78 TC_LOG_DEBUG("warden", "Initialize module");
79}
80
82{
83 TC_LOG_DEBUG("warden", "Request hash");
84
85 // Create packet structure
88 Request.Seed = _seed;
89
90 // Encrypt with warden RC4 key.
92
94 pkt.append((uint8*)&Request, sizeof(WardenHashRequest));
95 _session->SendPacket(&pkt);
96}
97
98struct keyData {
99 union
100 {
101 struct
102 {
105
106 struct
107 {
108 int ints[4];
110 };
111};
112
114{
115
116 // test
117 int keyIn[4];
118
119 keyData mod_seed = { { { { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE } } } };
120
121 for (int i = 0; i < 4; ++i)
122 {
123 keyIn[i] = mod_seed.ints.ints[i];
124 }
125
126 int keyOut[4];
127 int keyIn1, keyIn2;
128 keyOut[0] = keyIn[0];
129 keyIn[0] ^= 0xDEADBEEFu;
130 keyIn1 = keyIn[1];
131 keyIn[1] -= 0x35014542u;
132 keyIn2 = keyIn[2];
133 keyIn[2] += 0x5313F22u;
134 keyIn[3] *= 0x1337F00Du;
135 keyOut[1] = keyIn1 - 0x6A028A84;
136 keyOut[2] = keyIn2 + 0xA627E44;
137 keyOut[3] = 0x1337F00D * keyIn[3];
138 // end test
139
140 //const uint8 validHash[20] = { 0x56, 0x8C, 0x05, 0x4C, 0x78, 0x1A, 0x97, 0x2A, 0x60, 0x37, 0xA2, 0x29, 0x0C, 0x22, 0xB5, 0x25, 0x71, 0xA0, 0x6F, 0x4E };
141
142 // Verify key
144 buff.read(result);
145 if (result != Trinity::Crypto::SHA1::GetDigestOf(reinterpret_cast<uint8*>(keyIn), 16))
146 {
147 char const* penalty = ApplyPenalty(nullptr);
148 TC_LOG_WARN("warden", "{} failed hash reply. Action: {}", _session->GetPlayerInfo(), penalty);
149 return;
150 }
151
152 TC_LOG_DEBUG("warden", "Request hash reply: succeed");
153
154 // client 7F96EEFDA5B63D20A4DF8E00CBF48304
155 //const uint8 client_key[16] = { 0x7F, 0x96, 0xEE, 0xFD, 0xA5, 0xB6, 0x3D, 0x20, 0xA4, 0xDF, 0x8E, 0x00, 0xCB, 0xF4, 0x83, 0x04 };
156
157 // server C2B7ADEDFCCCA9C2BFB3F85602BA809B
158 //const uint8 server_key[16] = { 0xC2, 0xB7, 0xAD, 0xED, 0xFC, 0xCC, 0xA9, 0xC2, 0xBF, 0xB3, 0xF8, 0x56, 0x02, 0xBA, 0x80, 0x9B };
159
160 // change keys here
161 memcpy(_inputKey.data(), keyIn, 16);
162 memcpy(_outputKey.data(), keyOut, 16);
163
166
167 _initialized = true;
168}
169
171{
172 TC_LOG_DEBUG("warden", "Request data");
173
174 ByteBuffer buff;
176
177 std::string str = "Test string!";
178
179 buff << uint8(str.size());
180 buff.append(str.c_str(), str.size());
181
182 buff.hexlike();
183
184 // Encrypt with warden RC4 key.
185 EncryptData(buff.contents(), buff.size());
186
188 pkt.append(buff);
189 _session->SendPacket(&pkt);
190
191 _dataSent = true;
192}
193
195{
196 TC_LOG_DEBUG("warden", "Handle data");
197
198 _dataSent = false;
200
201 //uint16 Length;
202 //buff >> Length;
203 //uint32 Checksum;
204 //buff >> Checksum;
205
206 //if (!IsValidCheckSum(Checksum, buff.contents() + buff.rpos(), Length))
207 //{
208 // buff.rpos(buff.wpos());
209 // if (sWorld->getBoolConfig(CONFIG_BOOL_WARDEN_KICK))
210 // Client->KickPlayer();
211 // return;
212 //}
213
214 //bool found = false;
215
216 std::string str = "Test string!";
217
219 sha1.UpdateData(str);
220 uint32 magic = 0xFEEDFACE; // unsure
221 sha1.UpdateData((uint8*)&magic, 4);
222 sha1.Finalize();
223
224 std::array<uint8, Trinity::Crypto::SHA1::DIGEST_LENGTH> sha1Hash;
225 buff.read(sha1Hash.data(), sha1Hash.size());
226
227 if (sha1Hash != sha1.GetDigest())
228 {
229 TC_LOG_DEBUG("warden", "Handle data failed: SHA1 hash is wrong!");
230 //found = true;
231 }
232
233 std::array<uint8, 16> ourMD5Hash = Trinity::Crypto::MD5::GetDigestOf(str);
234 std::array<uint8, 16> theirsMD5Hash;
235 buff.read(theirsMD5Hash);
236
237 if (ourMD5Hash != theirsMD5Hash)
238 {
239 TC_LOG_DEBUG("warden", "Handle data failed: MD5 hash is wrong!");
240 //found = true;
241 }
242
243 _session->KickPlayer("WardenMac::HandleCheckResult");
244}
std::array< uint8, SESSION_KEY_LENGTH > SessionKey
Definition: AuthDefines.h:25
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:162
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
std::string ByteArrayToHexStr(Container const &c, bool reverse=false)
Definition: Util.h:368
std::array< uint8, 9318 > Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data
@ WARDEN_SMSG_HASH_REQUEST
Definition: Warden.h:43
@ WARDEN_SMSG_CHEAT_CHECKS_REQUEST
Definition: Warden.h:40
void hexlike() const
Definition: ByteBuffer.cpp:177
void append(T value)
Definition: ByteBuffer.h:143
size_t size() const
Definition: ByteBuffer.h:536
uint8 * contents()
Definition: ByteBuffer.h:522
void Generate(uint8 *buf, uint32 sz)
void Init(uint8 const *seed, size_t len)
Definition: ARC4.cpp:43
std::array< uint8, DIGEST_LENGTH > Digest
Definition: CryptoHash.h:47
void UpdateData(uint8 const *data, size_t len)
Definition: CryptoHash.h:111
Digest const & GetDigest() const
Definition: CryptoHash.h:130
static Digest GetDigestOf(uint8 const *data, size_t len)
Definition: CryptoHash.h:49
void RequestChecks() override
Definition: WardenMac.cpp:170
void HandleCheckResult(ByteBuffer &buff) override
Definition: WardenMac.cpp:194
void InitializeModule() override
Definition: WardenMac.cpp:76
void HandleHashResult(ByteBuffer &buff) override
Definition: WardenMac.cpp:113
void InitializeModuleForClient(ClientWardenModule &module) override
Definition: WardenMac.cpp:69
void Init(WorldSession *session, SessionKey const &k) override
Definition: WardenMac.cpp:37
void RequestHash() override
Definition: WardenMac.cpp:81
Definition: Warden.h:85
char const * ApplyPenalty(WardenCheck const *check)
Definition: Warden.cpp:175
Optional< ClientWardenModule > _module
Definition: Warden.h:127
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:137
uint32 _clientResponseTimer
Definition: Warden.h:125
void MakeModuleForClient()
Definition: Warden.cpp:43
void RequestModule()
Definition: Warden.cpp:79
Trinity::Crypto::ARC4 _outputCrypto
Definition: Warden.h:123
std::array< uint8, 16 > _inputKey
Definition: Warden.h:119
Trinity::Crypto::ARC4 _inputCrypto
Definition: Warden.h:122
bool _dataSent
Definition: Warden.h:126
bool _initialized
Definition: Warden.h:128
std::array< uint8, 16 > _seed
Definition: Warden.h:121
WorldSession * _session
Definition: Warden.h:118
std::array< uint8, 16 > _outputKey
Definition: Warden.h:120
Player session in the World.
Definition: WorldSession.h:963
std::string GetPlayerInfo() const
void KickPlayer(std::string const &reason)
Kick a player out of the World.
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
uint32 GetAccountId() const
@ SMSG_WARDEN3_DATA
Definition: Opcodes.h:2063
boost::beast::http::request< RequestBody > Request
Definition: HttpCommon.h:30
uint8 const * CompressedData
Definition: Warden.h:78
size_t CompressedSize
Definition: Warden.h:79
std::array< uint32, 5 > ints
Definition: Warden.cpp:161
std::array< uint8, 20 > bytes
Definition: Warden.cpp:160