我一直在思考如何保护我的C/ c++代码不被反汇编和逆向工程破坏。通常情况下,在我的代码中,我绝不会宽恕这种行为;然而,为了各种人的安全,我目前正在研究的协议决不能被检查或理解。

现在这对我来说是一个新的主题,互联网并没有真正的资源来防止逆向工程,而是描述了大量关于如何逆向工程的信息

到目前为止我想到的一些事情是:

Code injection (calling dummy functions before and after actual function calls) Code obfustication (mangles the disassembly of the binary) Write my own startup routines (harder for debuggers to bind to) void startup(); int _start() { startup( ); exit (0) } void startup() { /* code here */ } Runtime check for debuggers (and force exit if detected) Function trampolines void trampoline(void (*fnptr)(), bool ping = false) { if(ping) fnptr(); else trampoline(fnptr, true); } Pointless allocations and deallocations (stack changes a lot) Pointless dummy calls and trampolines (tons of jumping in disassembly output) Tons of casting (for obfuscated disassembly)

我的意思是,这些是我想过的一些事情,但它们都可以在适当的时间框架内由代码分析师解决。我还有别的选择吗?


当前回答

最好的反反汇编技巧,特别是在可变字长指令集上,是在汇编程序/机器代码中,而不是在c中

CLC
BCC over
.byte 0x09
over:

The disassembler has to resolve the problem that a branch destination is the second byte in a multi byte instruction. An instruction set simulator will have no problem though. Branching to computed addresses, which you can cause from C, also make the disassembly difficult to impossible. Instruction set simulator will have no problem with it. Using a simulator to sort out branch destinations for you can aid the disassembly process. Compiled code is relatively clean and easy for a disassembler. So I think some assembly is required.

I think it was near the beginning of Michael Abrash's Zen of Assembly Language where he showed a simple anti disassembler and anti-debugger trick. The 8088/6 had a prefetch queue what you did was have an instruction that modified the next instruction or a couple ahead. If single stepping then you executed the modified instruction, if your instruction set simulator did not simulate the hardware completely, you executed the modified instruction. On real hardware running normally the real instruction would already be in the queue and the modified memory location wouldnt cause any damage so long as you didnt execute that string of instructions again. You could probably still use a trick like this today as pipelined processors fetch the next instruction. Or if you know that the hardware has a separate instruction and data cache you can modify a number of bytes ahead if you align this code in the cache line properly, the modified byte will not be written through the instruction cache but the data cache, and an instruction set simulator that did not have proper cache simulators would fail to execute properly. I think software only solutions are not going to get you very far.

上面这些都是老的和众所周知的,我对当前的工具了解不够,不知道它们是否已经围绕这些事情工作了。自修改代码可能/将使调试器出错,但是人类可以/将缩小问题范围,然后看到自修改代码并解决它。

It used to be that the hackers would take about 18 months to work something out, dvds for example. Now they are averaging around 2 days to 2 weeks (if motivated) (blue ray, iphones, etc). That means to me if I spend more than a few days on security, I am likely wasting my time. The only real security you will get is through hardware (for example your instructions are encrypted and only the processor core well inside the chip decrypts just before execution, in a way that it cannot expose the decrypted instructions). That might buy you months instead of days.

另外,读读凯文·米特尼克的《欺骗的艺术》。这样的人可以拿起电话,让你或同事把秘密交给系统,以为那是公司其他部门的经理、其他同事或硬件工程师。你的安全系统也被破坏了。安全不仅仅是管理技术,还要管理人。

其他回答

为了能够做出正确的选择,你应该考虑以下几个方面:

有没有可能“新用户”不愿意花钱而是使用你的软件? 现有客户是否有可能需要比他们拥有的更多的许可证? 潜在用户愿意支付多少钱? 你想按用户/并发用户/工作站/公司发放许可证吗? 你的软件需要培训/定制才能有用吗?

如果问题5的答案是“是”,那么就不用担心非法拷贝。反正也没用。

如果问题1的答案是“是”,那么首先考虑定价问题(见问题3)。

如果你回答问题2“是”,那么“按使用付费”模式可能会 适合你。

从我的经验来看,按使用付费+定制和培训是最好的保护 为您的软件,因为:

新用户被定价模式所吸引(很少使用->很少付费) 几乎没有“匿名用户”,因为他们需要培训和定制。 没有软件限制会吓跑潜在客户。 现有客户源源不断地提供资金。 由于长期的业务关系,您可以从客户那里得到有价值的发展反馈。

在您考虑引入DRM或混淆之前,您可能会考虑这些要点,以及它们是否适用于您的软件。

关于隐藏代码要记住的第一件事:不是所有的代码都需要隐藏。

最终目标:我对大多数软件程序的最终目标是能够出售不同的许可证,这些许可证将打开和关闭我的程序中的特定功能。

最佳技术:我发现构建一个像WordPress提供的钩子和过滤器系统,绝对是迷惑对手的最佳方法。这允许您加密某些触发器关联,而无需实际加密代码。

这样做的原因是,您希望加密尽可能少的代码。

了解你的破解者:了解这一点:破解代码的主要原因不是因为恶意分发许可,实际上是因为需要更改你的代码,而他们真的不需要分发免费副本。

入门:撇开少量要加密的代码,其余的代码应该尝试塞到一个文件中,以增加复杂性和可理解性。

准备加密:你将在我的系统中分层加密,这也将是一个非常复杂的过程,所以构建另一个程序来负责加密过程。

第一步:使用base64名称来混淆所有内容。完成之后,将混淆的代码base64,并将其保存到一个临时文件中,该文件稍后将用于解密和运行此代码。有意义吗?

我重复一遍,因为你会一次又一次地这样做。您将创建一个base64字符串,并将其保存到另一个文件中,作为将被解密和呈现的变量。

第二步:您将把这个临时文件作为一个字符串读入并混淆它,然后将它作为base64并将其保存到第二个临时文件中,该文件将用于解密并为最终用户呈现它。

第三步:重复第二步,你想重复多少次都行。一旦你让它正常工作,没有解密错误,然后你就会想要开始为你的对手埋地雷。

雷区一:你一定要把你收到通知这件事绝对保密。因此,在第2层构建一个破解尝试安全警告邮件系统。这将让你知道你的对手的细节,如果有任何事情是错误的。

地雷二:依赖。你不希望你的对手能够运行第1层,而没有第3层、第4层或第5层,甚至没有实际设计的程序。因此,请确保在第一层中包含某种终止脚本,如果程序不存在,该脚本将被激活,或在其他层中。

我相信你能想出你自己的地雷,玩得开心。

需要记住的事情:你可以加密你的代码,而不是base64。这样,简单的base64就不会解密程序。

奖励:记住,这实际上是你和对手之间的一种共生关系。我总是在第一层里面放一条评论,评论祝贺破解者,并给他们一个促销码,以便从你那里获得现金奖励。

让现金奖励意义重大,但不涉及偏见。我通常会说500美元左右。如果你的男朋友是第一个破解密码的人,那就付钱给他,成为他的朋友。如果他是你的朋友,他就不会分发你的软件。问问他是怎么做到的,你可以如何改进!

好运!

为了避免逆向工程,您不能将代码提供给用户。也就是说,我建议使用在线应用程序……然而(因为你没有给出背景),这对你来说可能是毫无意义的。

最近有一篇论文叫做“程序混淆和一次性程序”。如果你真的想保护你的应用程序。本文主要围绕使用简单通用硬件的理论不可能结果。

如果你负担不起额外的硬件,那么还有另一篇论文,在所有具有相同功能和相同大小的程序中,给出了理论上的最佳可能混淆“On最佳可能混淆”。然而,本文表明,信息理论的最佳可能意味着多项式层次结构的崩溃。

如果这些结果不能满足你的需要,这些论文至少应该给你足够的参考书目引导去查阅相关文献。

更新:一种新的混淆概念,称为不可区分混淆,可以减轻不可能性结果(论文)

很多时候,担心你的产品被逆向工程是多余的。是的,它可以被逆向工程;但它是否会在短时间内变得如此出名,以至于黑客们会发现它值得逆转。它吗?(对于大量的代码行来说,这项工作不是一个小时间活动)。

如果它真的能赚钱,那么你就应该筹集足够的资金,通过专利或版权等合法途径来保护它。

恕我直言,采取你将要采取的基本预防措施,然后释放它。如果它成为逆向工程的一个点,这意味着你已经做得非常好,你自己会找到更好的方法来克服它。祝你好运。