如何从服务器源代码中提取网络协议?
我正在尝试为流行网络编写一个聊天客户端。原始客户端是专有的,比我想要的大大约 15 GB。 (公平地说,其他人称其为游戏。)
互联网上绝对没有可用的协议文档,并且大多数搜索结果仅返回客户端的脚本接口。我可以理解,由于使用方式错误,它可能会导致破坏其他人的体验。
我已经下载了几个替代服务器的源代码,包括我想要连接的服务器,但是
- 除了安装说明之外,这些服务器不包含任何文档,
- 评论很差(我做了肤浅的浏览),
- 内容很大(
src目标服务器的
文件夹包含 12 MB 的.cpp
和.h
文件),并且grep
没有找到任何内容相关
我也尝试过搜索他们的论坛并联系服务器的维护人员,但到目前为止,没有运气。
数据包嗅探不太可能有帮助,因为该协议严重依赖于加密。
在这一点上,我所有的希望就是我有能力咀嚼大量的代码。我该如何开始?
编辑:相关问题。
I'm trying to write a chat client for a popular network. The original client is proprietary, and is about 15 GB larger than I would like. (To be fair, others call it a game.)
There is absolutely no documentation available for the protocol on the internet, and most search results only come back with the client's scripting interface. I can understand that, since used in the wrong way, it could lead to ruining other people's experience.
I've downloaded the source code of a couple of alternative servers, including the one I want to connect to, but those
- contain no documentation other than install instructions
- are poorly commented (I did a superficial browsing)
- are HUGE (the
src
folder of the target server contains 12 MB worth of.cpp
and.h
files), andgrep
didn't find anything related
I've also tried searching their forums and contacting the maintainers of the server, but so far, no luck.
Packet sniffing isn't likely to help, as the protocol relies heavily on encryption.
At this point, all my hope is my ability to chew through an ungodly amount of code. How do I start?
Edit: A related question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您的原始代码使用一些众所周知的库(如 OpenSSL 或 Ctypto++)进行加密,那么为这些库的主要入口点编写包装器,然后延迟对实际库的调用可能会很有用。如果您进行此类替换并成功构建项目,您将能够跟踪以纯文本方式发出的所有内容。
如果您的项目没有使用第三方加密库,希望仍然可以用一些包装器替换加密例程,这些包装器跟踪其输入,然后将加密委托给实际代码。
您可以打赌,加密通常是在单独的、数量相对较少的源文件中实现的,因此您应该更容易跟踪这些文件中的输入/输出。
祝你好运!
If your original code is encrypted with some well known library like OpenSSL or Ctypto++ it might be useful to write your wrapper for the main entry points of these libraries, then delagating the call to the actual library. If you make such substitution and build the project successfully, you will be able to trace everything which goes out in the plain text way.
If your project is not using third party encryption libs, hopefully it is still possible to substitute the encryption routines with some wrappers which trace their input and then delegate encryption to the actual code.
Your bet is that usually enctyption is implemented in separate, relatively small number of source files so that should be easier for you to track input/output in these files.
Good luck!
我会说
在此过程中,您将能够记录解密(或更可能尚未加密)的网络活动。
I'd say
On the way, you will be able to log decrypted (or, more likely, not yet encrypted) network activity.
IMO,最好的答案是阅读替代服务器的源代码。尝试使用一个好的 C++ IDE 来帮助您。这将会带来很大的不同。
您需要了解的协议相关材料很可能仅限于文件的子集。这些将包含对网络套接字和事物的引用。从那里开始,根据需要向外努力。
IMO, the best answer is to read the source code of the alternative server. Try using a good C++ IDE to help you. It will make a lot of difference.
It is likely that the protocol related material you need to understand will be limited to a subset of the files. These will contain references to network sockets and things. Start from there and work outwards as far as you need to.
一种可行的方法是将其视为加密挑战来解决。这很容易,因为你可以控制很多事情。
例如,您可以使用当前客户端向服务器发送已知消息,然后检查服务器内存中是否有该字符串。一旦找到字符串在哪个对象中结束,就可以通过代码追踪其祖先。在对象的任何非常量方法上设置断点,并查找堆栈跟踪。这使您可以实时查看消息如何到达服务器,以及消息处理所必需的核心功能列表。接下来您可以找到相关函数(列表中函数的调用者/被调用者)。
A viable approach is to tackle this as a crypto challenge. That makes it easy, because you control so much.
For instance, you can use a current client to send a known message to the server, and then check server memory for that string. Once you've found out in which object the string ends, it also becomes possible to trace its ancestry through the code. Set a breakpoint on any non-const method of the object, and find the stacktraces. This gives you a live view of how messages arrive at the server, and a list of core functions essential to message processing. You can next find related functions (caller/callee of the functions on your list).