【流放之路】加密算法还原
本帖最后由 小俊 于 2019-3-13 14:43 编辑# Path of Exile
## 分析工具
- IDA
- x64dbg
## 已识别的库
- CryptoPP
- libcurl
## 已识别的算法
- Diffie-Hellman // 交换key
- DSA // 第一个接收的数据包校验(可以无视)
- SHA-512 // 生成 Salsa20 key
- SHA-256 // 账号密码加密
- Salsa20 // 游戏中的算法
## 第一次数据交换
1. Client --> Server:
2. Client <-- Server:
++0x38++:字节,是DSA签名,可以不用管
## 加密过程伪代码
```c
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, publicKey;
dh.GenerateKeyPair(privateKey, publicKey);
// 发送本地公钥
send(publicKey);
// 接收服务器公钥
byte serverPublicKey;
recv(serverPublicKey)
// 通过本地私钥、服务器公钥,生成结果
byte agreedValue = {
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, 0x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xFC, 0xF0, 0x71, 0x42,
0x33, 0xFB, 0x15, 0x0F, 0xB8, 0x09, 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;
dh.Agree(&agreedValue, privateKey, otherPublicKey);
// 通过 SHA-512 计算出 0x40 字节的 Hash 值
byte hashValue;
sha512(hashValue,agreedValue);
// 通过 0x40 字节的 hash 值,生成 Salsa20 加密 Key
Salsa20::Encryption enc;
enc.SetKeyWithIV(hashValue, 0x20, &hashValue, 0x8);
// 通过 0x40 字节的 hash 值,生成 Salsa20 解密 Key
Salsa20::Decryption dec;
dec.SetKeyWithIV(hashValue, 0x20, &hashValue, 0x8);
// 到这里可以直接使用 ProcessData 进行加解密收发数据了
// 发送加密后的数据
byte sendData = "TestData";
enc.ProcessData(sendData)
send(sendData);
// 解密接收到的数据
byte recvData;
recv(recvData);
dec.ProcessData(recvData);
```
## 完整代码
```c
#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, byte publicKey)
{
// 随机
static AutoSeededRandomPool rnd;
// 初始化 p,q,g
static DH dh(P, Q, G);
// 生成 公钥、私钥
dh.GenerateKeyPair(rnd, privateKey, publicKey);
}
// 获取哈希表
void GetSalsa20Key(byte privateKey, byte otherPublicKey, Salsa20::Encryption &enc, Salsa20::Encryption &dec)
{
byte agreedValue = {
0x0C, 0x2E, 0x7F, 0xB6, 0x73, 0x1C, 0xDD, 0x0E, 0xF6, 0xAA, 0xC0, 0xA1, 0x86, 0xED, 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, 0xE7, 0x6C, 0xFC, 0xBE, 0xA7
};
// 初始化 p,q,g
static DH dh(P, Q, G);
// 生成结果
dh.Agree(&agreedValue, privateKey, otherPublicKey);
// 用来保存结果
byte sha512_Buff;
// sha512
SHA512 sha512;
sha512.CalculateDigest(sha512_Buff, agreedValue, sizeof(agreedValue));
// 初始化加密 Key
enc.SetKeyWithIV(sha512_Buff, 0x20, &sha512_Buff, 0x8);
// 初始化解密 key
dec.SetKeyWithIV(sha512_Buff, 0x20, &sha512_Buff, 0x8);
}
int main()
{
// 获取 Key
byte privateKey, publicKey;
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 = { 0x00, 0x02, 0x00, 0x80 };
memcpy_s(&sendPublicKey, 0x80, publicKey, 0x80);
send(sock, (char*)sendPublicKey, sizeof(sendPublicKey), 0);
// 接收服务器的公钥
byte recvBuff;
recv(sock, (char*)recvBuff, sizeof(recvBuff), 0);
// 加密key
Salsa20::Encryption enc;
// 解密key
Salsa20::Decryption dec;
GetSalsa20Key(privateKey, &recvBuff, 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, 0x20, &recvBuff, 0x8);
// 初始化解密 key
dec.SetKeyWithIV(&recvBuff, 0x20, &recvBuff, 0x8);
Sleep(3000);
// 第二个连接
addr.sin_addr.S_un.S_addr = *(ULONG*)&recvBuff;
addr.sin_port = *(u_short*)&recvBuff;
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 = *(DWORD*)&recvBuff;
*(WORD*)&inGame = *(WORD*)&recvBuff;
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;
}
```
## 游戏资源解析
- (https://1-1257202678.cos.ap-beijing.myqcloud.com/VisualGGPK.zip)
- (https://github.com/OmegaK2/PyPoE) 幕幽晓寂寂 发表于 2018-5-8 13:57
听说过之前龙之谷有过 就是组队自己刷图吗
脱机辅助是指不依赖官方发布的客户端程序就可以运行的辅助。就是说,连游戏客户端都不需要啦。 实现的原理说起来很简单,就是了解了这个游戏的客户端和服务器之间的通讯的数据包的几乎全部内容以后,做一个辅助程序,可以模拟官方的客户端进行登录、游戏。可以实现自动打怪、捡东西、交易等等。 ——来自百度知道
数据包都是加密的,所以我要还原他的加密算法才有可能实现脱机辅助啦
{:301_1005:} 不错,湛江市了 哇塞!厉害厉害我竟然一点都没看懂哈哈哈哈···· 默默问下这个干啥用!? 幕幽晓寂寂 发表于 2018-5-8 13:52
默默问下这个干啥用!?
听说过脱机辅助吗? 小俊 发表于 2018-5-8 13:56
听说过脱机辅助吗?
听说过之前龙之谷有过 就是组队自己刷图吗 哇塞!厉害厉害说的好详细 小俊 发表于 2018-5-8 14:08
脱机辅助是指不依赖官方发布的客户端程序就可以运行的辅助。就是说,连游戏客户端都不需要啦。 实现的原 ...
wo 我里个天!张姿势了 俊大大求大腿啊!{:1_899:} 幕幽晓寂寂 发表于 2018-5-8 14:14
wo 我里个天!张姿势了 俊大大求大腿啊!
万里长城才走了第一步,离大腿还有很多距离
{:301_1007:}