TrinityCore
Loading...
Searching...
No Matches
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 "Player.h"
26#include "SessionKeyGenerator.h"
27#include "Util.h"
28#include "WardenModuleMac.h"
29#include "WorldPacket.h"
30#include "WorldSession.h"
31
32#include <array>
33
35
37
38void WardenMac::Init(WorldSession* pClient, SessionKey const& K)
39{
40 _session = pClient;
41 // Generate Warden Key
43 WK.Generate(_inputKey.data(), 16);
44 WK.Generate(_outputKey.data(), 16);
45 /*
46 Seed: 4D808D2C77D905C41A6380EC08586AFE (0x05 packet)
47 Hash: <?> (0x04 packet)
48 Module MD5: 0DBBF209A27B1E279A9FEC5C168A15F7
49 New Client Key: <?>
50 New Cerver Key: <?>
51 */
52
53 _seed = { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE };
54
57 TC_LOG_DEBUG("warden", "Server side warden for client {} initializing...", pClient->GetAccountId());
58 TC_LOG_DEBUG("warden", "C->S Key: {}", ByteArrayToHexStr(_inputKey));
59 TC_LOG_DEBUG("warden", "S->C Key: {}", ByteArrayToHexStr(_outputKey));
60 TC_LOG_DEBUG("warden", " Seed: {}", ByteArrayToHexStr(_seed));
61 TC_LOG_DEBUG("warden", "Loading Module...");
62
64
65 TC_LOG_DEBUG("warden", "Module Key: {}", ByteArrayToHexStr(_module->Key));
66 TC_LOG_DEBUG("warden", "Module ID: {}", ByteArrayToHexStr(_module->Id));
68}
69
71{
72 // data assign
73 module.CompressedData = Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data.data();
74 module.CompressedSize = Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data.size();
75}
76
78{
79 TC_LOG_DEBUG("warden", "Initialize module");
80}
81
83{
84 TC_LOG_DEBUG("warden", "Request hash");
85
86 // Create packet structure
87 WardenHashRequest Request;
89 Request.Seed = _seed;
90
91 // Encrypt with warden RC4 key.
92 EncryptData((uint8*)&Request, sizeof(WardenHashRequest));
93
95 pkt.append((uint8*)&Request, sizeof(WardenHashRequest));
96 _session->SendPacket(&pkt);
97}
98
99struct keyData {
100 union
101 {
102 struct
103 {
106
107 struct
108 {
109 int ints[4];
111 };
112};
113
115{
116
117 // test
118 int keyIn[4];
119
120 keyData mod_seed = { { { { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE } } } };
121
122 for (int i = 0; i < 4; ++i)
123 {
124 keyIn[i] = mod_seed.ints.ints[i];
125 }
126
127 int keyOut[4];
128 int keyIn1, keyIn2;
129 keyOut[0] = keyIn[0];
130 keyIn[0] ^= 0xDEADBEEFu;
131 keyIn1 = keyIn[1];
132 keyIn[1] -= 0x35014542u;
133 keyIn2 = keyIn[2];
134 keyIn[2] += 0x5313F22u;
135 keyIn[3] *= 0x1337F00Du;
136 keyOut[1] = keyIn1 - 0x6A028A84;
137 keyOut[2] = keyIn2 + 0xA627E44;
138 keyOut[3] = 0x1337F00D * keyIn[3];
139 // end test
140
141 //const uint8 validHash[20] = { 0x56, 0x8C, 0x05, 0x4C, 0x78, 0x1A, 0x97, 0x2A, 0x60, 0x37, 0xA2, 0x29, 0x0C, 0x22, 0xB5, 0x25, 0x71, 0xA0, 0x6F, 0x4E };
142
143 // Verify key
145 buff.read(result);
146 if (result != Trinity::Crypto::SHA1::GetDigestOf(reinterpret_cast<uint8*>(keyIn), 16))
147 {
148 char const* penalty = ApplyPenalty(nullptr);
149 TC_LOG_WARN("warden", "{} failed hash reply. Action: {}", _session->GetPlayerInfo(), penalty);
150 return;
151 }
152
153 TC_LOG_DEBUG("warden", "Request hash reply: succeed");
154
155 // client 7F96EEFDA5B63D20A4DF8E00CBF48304
156 //const uint8 client_key[16] = { 0x7F, 0x96, 0xEE, 0xFD, 0xA5, 0xB6, 0x3D, 0x20, 0xA4, 0xDF, 0x8E, 0x00, 0xCB, 0xF4, 0x83, 0x04 };
157
158 // server C2B7ADEDFCCCA9C2BFB3F85602BA809B
159 //const uint8 server_key[16] = { 0xC2, 0xB7, 0xAD, 0xED, 0xFC, 0xCC, 0xA9, 0xC2, 0xBF, 0xB3, 0xF8, 0x56, 0x02, 0xBA, 0x80, 0x9B };
160
161 // change keys here
162 memcpy(_inputKey.data(), keyIn, 16);
163 memcpy(_outputKey.data(), keyOut, 16);
164
167
168 _initialized = true;
169}
170
172{
173 TC_LOG_DEBUG("warden", "Request data");
174
175 ByteBuffer buff;
177
178 std::string str = "Test string!";
179
180 buff << uint8(str.size());
181 buff.append(str.c_str(), str.size());
182
183 buff.hexlike();
184
185 // Encrypt with warden RC4 key.
186 EncryptData(buff.contents(), buff.size());
187
188 WorldPacket pkt(SMSG_WARDEN_DATA, buff.size());
189 pkt.append(buff);
190 _session->SendPacket(&pkt);
191
192 _dataSent = true;
193}
194
196{
197 TC_LOG_DEBUG("warden", "Handle data");
198
199 _dataSent = false;
201
202 //uint16 Length;
203 //buff >> Length;
204 //uint32 Checksum;
205 //buff >> Checksum;
206
207 //if (!IsValidCheckSum(Checksum, buff.contents() + buff.rpos(), Length))
208 //{
209 // buff.rpos(buff.wpos());
210 // if (sWorld->getBoolConfig(CONFIG_BOOL_WARDEN_KICK))
211 // Client->KickPlayer();
212 // return;
213 //}
214
215 //bool found = false;
216
217 std::string str = "Test string!";
218
220 sha1.UpdateData(str);
221 uint32 magic = 0xFEEDFACE; // unsure
222 sha1.UpdateData((uint8*)&magic, 4);
223 sha1.Finalize();
224
225 std::array<uint8, Trinity::Crypto::SHA1::DIGEST_LENGTH> sha1Hash;
226 buff.read(sha1Hash.data(), sha1Hash.size());
227
228 if (sha1Hash != sha1.GetDigest())
229 {
230 TC_LOG_DEBUG("warden", "Handle data failed: SHA1 hash is wrong!");
231 //found = true;
232 }
233
234 std::array<uint8, 16> ourMD5Hash = Trinity::Crypto::MD5::GetDigestOf(str);
235 std::array<uint8, 16> theirsMD5Hash;
236 buff.read(theirsMD5Hash);
237
238 if (ourMD5Hash != theirsMD5Hash)
239 {
240 TC_LOG_DEBUG("warden", "Handle data failed: MD5 hash is wrong!");
241 //found = true;
242 }
243
244 _session->KickPlayer("WardenMac::HandleCheckResult");
245}
std::array< uint8, SESSION_KEY_LENGTH > SessionKey
Definition AuthDefines.h:25
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
#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:335
@ WARDEN_SMSG_HASH_REQUEST
Definition Warden.h:44
@ WARDEN_SMSG_CHEAT_CHECKS_REQUEST
Definition Warden.h:41
void hexlike() const
void append(T value)
Definition ByteBuffer.h:129
size_t size() const
Definition ByteBuffer.h:409
uint8 * contents()
Definition ByteBuffer.h:395
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
void HandleCheckResult(ByteBuffer &buff) override
void InitializeModule() override
Definition WardenMac.cpp:77
void HandleHashResult(ByteBuffer &buff) override
void InitializeModuleForClient(ClientWardenModule &module) override
Definition WardenMac.cpp:70
void Init(WorldSession *session, SessionKey const &k) override
Definition WardenMac.cpp:38
void RequestHash() override
Definition WardenMac.cpp:82
char const * ApplyPenalty(WardenCheck const *check)
Definition Warden.cpp:174
Optional< ClientWardenModule > _module
Definition Warden.h:128
void EncryptData(uint8 *buffer, uint32 length)
Definition Warden.cpp:136
uint32 _clientResponseTimer
Definition Warden.h:126
void MakeModuleForClient()
Definition Warden.cpp:42
void RequestModule()
Definition Warden.cpp:78
Trinity::Crypto::ARC4 _outputCrypto
Definition Warden.h:124
std::array< uint8, 16 > _inputKey
Definition Warden.h:120
Trinity::Crypto::ARC4 _inputCrypto
Definition Warden.h:123
bool _dataSent
Definition Warden.h:127
bool _initialized
Definition Warden.h:129
std::array< uint8, 16 > _seed
Definition Warden.h:122
WorldSession * _session
Definition Warden.h:119
std::array< uint8, 16 > _outputKey
Definition Warden.h:121
Player session in the World.
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
std::string GetPlayerInfo() const
void KickPlayer(std::string const &reason)
Kick a player out of the World.
uint32 GetAccountId() const
@ SMSG_WARDEN_DATA
Definition Opcodes.h:771
std::array< uint8, 16 > Seed
Definition Warden.h:69
std::array< uint32, 5 > ints
Definition Warden.cpp:160
std::array< uint8, 20 > bytes
Definition Warden.cpp:159