Path of Exile
分析工具
已识别的库
已识别的算法
- Diffie-Hellman // 交换key
- DSA // 第一个接收的数据包校验(可以无视)
- SHA-512 // 生成 Salsa20 key
- SHA-256 // 账号密码加密
- Salsa20 // 游戏中的算法
第一次数据交换
- Client --> Server:[0x80]
- Client <-- Server:[0x80,0x38]
++0x38++:字节,是DSA签名,可以不用管
加密过程伪代码
Integer p("0xc5d1fff6e1e0b5b5a4220a369a4f504d"
"59c7482724053c0d4b05426328031633"
"bc79249c1c58c91b32e6802f20a1e762"
"6859da201e7faad8406c702796cbdf32"
"08a6cccb77baa29bec763a9a1fb868d7"
"9182f00957e890d762806b443e7fd2f7"
"5ef2eed5f56e92e5939ec15533a642b2"
"212504b62ba72ca8e6c7fe28bbc8f687");
Integer q("0x62e8fffb70f05adad211051b4d27a826"
"ace3a41392029e06a582a13194018b19"
"de3c924e0e2c648d997340179050f3b1"
"342ced100f3fd56c20363813cb65ef99"
"04536665bbdd514df63b1d4d0fdc346b"
"c8c17804abf4486bb14035a21f3fe97b"
"af79776afab74972c9cf60aa99d32159"
"1092825b15d396547363ff145de47b43");
Integer g("0x2");
// 使用 p,q,g 初始化 Diffie-Hellman
DH dh(p, q, g);
// 生成 公钥、私钥
byte privateKey[0x80], publicKey[0x80];
dh.GenerateKeyPair(privateKey, publicKey);
// 发送本地公钥
send(publicKey);
// 接收服务器公钥
byte serverPublicKey[0x80];
recv(serverPublicKey)
// 通过本地私钥、服务器公钥,生成结果
byte agreedValue[0x200] = {
0x0C, 0x2E, 0x7F, 0xB6, 0x73, 0x1C, 0xDD, 0x0E, 0xF6, 0xAA, 0xC0, 0xA1, 0x86, 0xED, 0x16, 0x77,
0x81, 0xAD, 0xEE, 0xC5, 0xAA, 0xE8, 0x76, 0x2A, 0x2F, 0x5D, 0xD4, 0x9B, 0x1A, 0x46, 0xEA, 0xD0,
0x7B, 0x8C, 0xEE, 0x09, 0x2D, 0x90, 0xF6, 0x8B, 0xB6, 0x4A, 0x41, 0xB6, 0xA6, 0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09, 0xBA, 0xAF, 0xB8, 0x3C, 0x9D, 0x3F, 0xB3, 0xC5, 0x8A, 0x42,
0x61, 0xFD, 0x35, 0x6C, 0xDE, 0x1C, 0x47, 0xF6, 0xD7, 0x2C, 0x4D, 0xD9, 0x45, 0x27, 0xC7, 0x13,
0x1F, 0x8D, 0x92, 0x43, 0x27, 0x08, 0x8B, 0x56, 0x06, 0xD1, 0x8C, 0x25, 0x4B, 0x8C, 0x51, 0x0D,
0xEE, 0x03, 0xB5, 0x0E, 0x90, 0xDD, 0x5E, 0xCB, 0xD8, 0x51, 0x10, 0xA2, 0xC6, 0xD6, 0xFF, 0xC9,
0xAF, 0x18, 0xA7, 0x3E, 0x17, 0x05, 0x8A, 0x34, 0xD2, 0xB9, 0x60, 0x1F, 0x38, 0xCA, 0x1B, 0xAB,
0xF8, 0x9F, 0xC6, 0x43, 0xA6, 0x32, 0x94, 0x32, 0x64, 0x3C, 0xA2, 0x45, 0xA4, 0x6B, 0xCD, 0xA8,
0xB5, 0xDE, 0xDF, 0x26, 0xA4, 0x06, 0xAB, 0xAD, 0x1D, 0x1F, 0x26, 0xCB, 0xD7, 0x58, 0xC3, 0x4C,
0x5A, 0x04, 0xC1, 0x23, 0x90, 0xED, 0xE3, 0x20, 0xBD, 0xA9, 0x7D, 0xF4, 0x76, 0x4D, 0xA4, 0x90,
0x4C, 0x2A, 0x7E, 0x49, 0x47, 0xDE, 0xF5, 0x15, 0xB6, 0x92, 0x7A, 0xC9, 0xF6, 0xDC, 0x3E, 0xEF,
0xFF, 0x93, 0xBB, 0x51, 0x0D, 0x5C, 0xDA, 0x65, 0x0A, 0x3C, 0x52, 0xE7, 0x6C, 0xFC, 0xBE, 0xA7
};
byte agreedValue[0x80];
dh.Agree(&agreedValue[0x180], privateKey, otherPublicKey);
// 通过 SHA-512 计算出 0x40 字节的 Hash 值
byte hashValue[0x40];
sha512(hashValue,agreedValue);
// 通过 0x40 字节的 hash 值,生成 Salsa20 加密 Key
Salsa20::Encryption enc;
enc.SetKeyWithIV(hashValue, 0x20, &hashValue[0x20], 0x8);
// 通过 0x40 字节的 hash 值,生成 Salsa20 解密 Key
Salsa20::Decryption dec;
dec.SetKeyWithIV(hashValue, 0x20, &hashValue[0x30], 0x8);
// 到这里可以直接使用 ProcessData 进行加解密收发数据了
// 发送加密后的数据
byte sendData[1024] = "TestData";
enc.ProcessData(sendData)
send(sendData);
// 解密接收到的数据
byte recvData[1024];
recv(recvData);
dec.ProcessData(recvData);
完整代码
#include <Windows.h>
#include <cryptlib.h>
#include <osrng.h>
#include <dh.h>
#include <sha.h>
#include <salsa.h>
using namespace CryptoPP;
Integer P("0xc5d1fff6e1e0b5b5a4220a369a4f504d"
"59c7482724053c0d4b05426328031633"
"bc79249c1c58c91b32e6802f20a1e762"
"6859da201e7faad8406c702796cbdf32"
"08a6cccb77baa29bec763a9a1fb868d7"
"9182f00957e890d762806b443e7fd2f7"
"5ef2eed5f56e92e5939ec15533a642b2"
"212504b62ba72ca8e6c7fe28bbc8f687");
Integer Q("0x62e8fffb70f05adad211051b4d27a826"
"ace3a41392029e06a582a13194018b19"
"de3c924e0e2c648d997340179050f3b1"
"342ced100f3fd56c20363813cb65ef99"
"04536665bbdd514df63b1d4d0fdc346b"
"c8c17804abf4486bb14035a21f3fe97b"
"af79776afab74972c9cf60aa99d32159"
"1092825b15d396547363ff145de47b43");
Integer G("0x2");
// 获取 Key
void GetKey(byte privateKey[0x80], byte publicKey[0x80])
{
// 随机
static AutoSeededRandomPool rnd;
// 初始化 p,q,g
static DH dh(P, Q, G);
// 生成 公钥、私钥
dh.GenerateKeyPair(rnd, privateKey, publicKey);
}
// 获取哈希表
void GetSalsa20Key(byte privateKey[0x80], byte otherPublicKey[0x80], Salsa20::Encryption &enc, Salsa20::Encryption &dec)
{
byte agreedValue[0x200] = {
0x0C, 0x2E, 0x7F, 0xB6, 0x73, 0x1C, 0xDD, 0x0E, 0xF6, 0xAA, 0xC0, 0xA1, 0x86, 0xED, 0x16, 0x77,
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6C, 0xFC, 0xBE, 0xA7
};
// 初始化 p,q,g
static DH dh(P, Q, G);
// 生成结果
dh.Agree(&agreedValue[0x180], privateKey, otherPublicKey);
// 用来保存结果
byte sha512_Buff[0x40];
// sha512
SHA512 sha512;
sha512.CalculateDigest(sha512_Buff, agreedValue, sizeof(agreedValue));
// 初始化加密 Key
enc.SetKeyWithIV(sha512_Buff, 0x20, &sha512_Buff[0x20], 0x8);
// 初始化解密 key
dec.SetKeyWithIV(sha512_Buff, 0x20, &sha512_Buff[0x30], 0x8);
}
int main()
{
// 获取 Key
byte privateKey[0x80], publicKey[0x80];
GetKey(privateKey, publicKey);
// 链接游戏服务
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
SOCKADDR_IN addr{};
addr.sin_addr.S_un.S_addr = inet_addr("172.65.204.192");
addr.sin_port = htons(20481);
addr.sin_family = AF_INET;
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
connect(sock, (sockaddr*)&addr, sizeof(addr));
// 发送公钥
byte sendPublicKey[0x86] = { 0x00, 0x02, 0x00, 0x80 };
memcpy_s(&sendPublicKey[4], 0x80, publicKey, 0x80);
send(sock, (char*)sendPublicKey, sizeof(sendPublicKey), 0);
// 接收服务器的公钥
byte recvBuff[1024];
recv(sock, (char*)recvBuff, sizeof(recvBuff), 0);
// 加密key
Salsa20::Encryption enc;
// 解密key
Salsa20::Decryption dec;
GetSalsa20Key(privateKey, &recvBuff[4], enc, dec);
// 测试登录数据
byte loginBuff[] = {
0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0F, 0x78, 0x00, 0x35, 0x00, 0x63, 0x00, 0x31, 0x00,
0x34, 0x00, 0x70, 0x00, 0x61, 0x00, 0x40, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00,
0x2E, 0x00, 0x72, 0x00, 0x75, 0x00, 0xE0, 0x8D, 0x1E, 0x1F, 0x4B, 0xC4, 0x7B, 0xF7, 0xF9, 0x05,
0xE7, 0xD4, 0xDE, 0xE1, 0x2B, 0x7E, 0xA0, 0x59, 0xD9, 0x64, 0x2D, 0xD4, 0xAC, 0x67, 0x68, 0x4B,
0x3C, 0xEE, 0xFE, 0xF8, 0x06, 0x2E, 0xB5, 0x9A, 0x07, 0x1C, 0x83, 0xA0, 0xA5, 0x0B, 0x17, 0x6E,
0x8D, 0x4B, 0xD3, 0x35, 0x36, 0xC2, 0x6C, 0xE3, 0x82, 0xBF, 0x85, 0x61, 0x40, 0xF5, 0x90, 0xF7,
0x11, 0x7A, 0x66, 0xBD, 0x88, 0xF0, 0x01, 0x81, 0x36, 0x65, 0xB3, 0x44, 0x22, 0xCA, 0x9A, 0xC8,
0x4E, 0x87, 0x29, 0x1D, 0xF6, 0xEE, 0x48, 0xF7, 0x56, 0xA2, 0xA7, 0x1B, 0x0B, 0xC9, 0x20, 0xD1,
0x46, 0xDC, 0x47, 0xA5, 0x94, 0x62, 0x00, 0x00, 0x00
};
// 加密
enc.ProcessData(loginBuff, loginBuff, sizeof(loginBuff));
// 发送加密后的数据
send(sock, (char*)loginBuff, sizeof(loginBuff), 0);
// 接收登录结果
int recvSize = recv(sock, (char*)recvBuff, sizeof(recvBuff), 0);
// 解密接收到的数据
dec.ProcessData(recvBuff, recvBuff, recvSize);
// 0x24 0x12
byte temp0x24[] = { 0x00, 0x24 };
byte temp0x12[] = { 0x00, 0x12 };
// 加密
enc.ProcessData(temp0x24, temp0x24, sizeof(temp0x24));
enc.ProcessData(temp0x12, temp0x12, sizeof(temp0x12));
// 发送
send(sock, (char*)temp0x24, sizeof(temp0x24), 0);
send(sock, (char*)temp0x12, sizeof(temp0x12), 0);
// 接收数据
recvSize = recv(sock, (char*)recvBuff, sizeof(recvBuff), 0);
dec.ProcessData(recvBuff, recvBuff, recvSize);
Sleep(3000);
// 选择角色
byte selectRole[] = { 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x01 };
enc.ProcessData(selectRole, selectRole, sizeof(selectRole));
send(sock, (char*)selectRole, sizeof(selectRole), 0);
// 接收关键数据包
recvSize = recv(sock, (char*)recvBuff, sizeof(recvBuff), 0);
dec.ProcessData(recvBuff, recvBuff, recvSize);
// 初始化加密 Key
enc.SetKeyWithIV(&recvBuff[0x2B], 0x20, &recvBuff[0x4B], 0x8);
// 初始化解密 key
dec.SetKeyWithIV(&recvBuff[0x2B], 0x20, &recvBuff[0x5B], 0x8);
Sleep(3000);
// 第二个连接
addr.sin_addr.S_un.S_addr = *(ULONG*)&recvBuff[0x13];
addr.sin_port = *(u_short*)&recvBuff[0x11];
SOCKET sock2 = socket(AF_INET, SOCK_STREAM, 0);
connect(sock2, (sockaddr*)&addr, sizeof(addr));
// 进入游戏,发送的第一个包
byte inGame[] = {
0x00, 0x03, 0x00, 0x00, 0x24, 0x35, 0x00, 0x02, 0x00, 0x08, 0x54, 0x00, 0x65, 0x00, 0x73, 0x00,
0x74, 0x00, 0x50, 0x00, 0x61, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x0B, 0xC1, 0xE9, 0xEB, 0x00, 0x00,
0x00, 0x00, 0x20, 0x00
};
*(DWORD*)&inGame[0x1A] = *(DWORD*)&recvBuff[2];
*(WORD*)&inGame[0x4] = *(WORD*)&recvBuff[0xC];
send(sock2, (char*)inGame, sizeof(inGame), 0);
// 线路+地图生成是数据
byte unkPack1[] = {
0x00, 0x47, 0x73, 0x0B, 0x3B, 0x7A, 0x00, 0x00, 0x00, 0x00
};
enc.ProcessData(unkPack1, unkPack1, sizeof(unkPack1));
send(sock2, (char*)unkPack1, sizeof(unkPack1), 0);
Sleep(1000);
// 0xD3
byte unkPack2[] = {
0x00, 0xD3
};
enc.ProcessData(unkPack2, unkPack2, sizeof(unkPack2));
send(sock2, (char*)unkPack2, sizeof(unkPack2), 0);
Sleep(1000);
// 0x5D
byte unkPack3[] = {
0x00, 0x5D, 0x01, 0x00
};
enc.ProcessData(unkPack3, unkPack3, sizeof(unkPack3));
send(sock2, (char*)unkPack3, sizeof(unkPack3), 0);
Sleep(5000);
// 发送私聊
byte msg[] = {
0x00, 0x08, 0x00, 0x0C, 0x40, 0x00, 0x70, 0x00, 0x4F, 0x00, 0x6E, 0x00, 0x4F, 0x00, 0x71, 0x00,
0x20, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x00
};
enc.ProcessData(msg, msg, sizeof(msg));
send(sock2, (char*)msg, sizeof(msg), 0);
system("pause");
return 0;
}
游戏资源解析