简体   繁体   English

混淆C ++共享库

[英]Obfuscating C++ Shared Library

I've been asked to help obfuscate a library (written in C++) which will be distributed to clients. 我被要求帮助混淆一个将分发给客户的库(用C ++编写)。 I've already discussed why obfuscation is not necessarily a good idea, and seeing as licensing will be integrated into the software many concerns regarding copy protection are moot. 我已经讨论了为什么混淆不一定是个好主意,并且看到许可将被集成到软件中,许多关于复制保护的问题都没有实际意义。

Regardless, I've been asked to research methods anyway. 无论如何,我还是被要求研究方法。 I've looked into header mangling (and the like) as well as HARES, but I fail to find much that I can use for a library (naturally, these things would destroy any form of API rendering the library useless). 我已经查看了头文件(等等)以及HARES,但是我找不到可以用于库的任何东西(当然,这些东西会破坏任何形式的API,使库无用)。

What techniques can I apply that would work for libraries? 我可以应用哪些适用于图书馆的技术? While I would appreciate recommendations for tools (or compiler flags, etc.) that might be helpful I would like to stress that this is not a tool-focused (ie closable) question, but rather one focused on applicable techniques. 虽然我很感激可能有用的工具(或编译器标志等)的建议,但我想强调的是,这不是一个专注于工具(即可关闭)的问题,而是一个专注于适用技术的问题。

I wouldn't put much energy to doing it very thoroughly, because the reverse engineer is going to win this round. 我不会花太多精力去做这件事,因为逆向工程师将会赢得这一轮。

https://softwareengineering.stackexchange.com/questions/155131/is-it-important-to-obfuscate-c-application-code https://softwareengineering.stackexchange.com/questions/155131/is-it-important-to-obfuscate-c-application-code

Obfuscating C++ binaries is a bit of a losing battle. 混淆C ++二进制文件是一场失败的战斗。 It depends on who you are dealing with, but if your reverse engineer is smart enough to use IDA Pro and a couple of plugins, and a good debugger then it shall all be for naught. 这取决于你正在与谁打交道,但如果你的逆向工程师足够聪明,可以使用IDA Pro和一些插件,以及一个好的调试器,那么它一切都是徒劳的。

Obfuscation Priorities 混淆优先级

  • Where you can give the reverse engineer useless function names. 在哪里可以给逆向工程师无用的函数名称。

Honestly, this doesn't help that much, since ultimately your code will have to call some kind of non obfuscated shared library to get anything done. 老实说,这没有多大帮助,因为最终你的代码将不得不调用某种非混淆的共享库来完成任何事情。 At some point you will use the standard libary, or the STL, or even make a system call. 在某些时候,您将使用标准库,或STL,甚至进行系统调用。

  • Add false pathways to confound static analysis 添加错误的途径来混淆静态分析

So that the reverse engineer can have fun with a debugger. 因此,逆向工程师可以使用调试器获得乐趣。 Anti-analysis techniques are well known to the reverse engineer, and they can almost be circumvented with a debugger like ollydbg. 反分析技术是逆向工程师所熟知的,它们几乎可以通过像ollydbg这样的调试器来规避。

  • Write debugger foiling code 编写调试器代码

That reverse engineers love to play with. 反向工程师喜欢玩。 Again, this is an expected move, and the response is to just to step around the offending code, or to modify away the traps. 同样,这是一个预期的举动,响应只是绕过有问题的代码,或修改掉陷阱。 Anyone with any formal training in RE will blast past this. 任何在RE接受过正规训练的人都会过时。

  • Pack most of my binary into an encryped region which is decryped by a stub just before execution. 将我的大部分二进制文件打包到一个加密区域,该区域在执行之前由存根解密。

Same answer as above. 与上述答案相同。 Reverse engineers train for this from day one. 反向工程师从第一天开始为此进行培训。

  • Keep in mind the reverse engineers are looking for targeted morsals of information - very rarely are they trying to recreate the entire application. 请记住,逆向工程师正在寻找有针对性的信息 - 他们很少尝试重新创建整个应用程序。 Security intensive code, code for license validation, code for home base communication, networking code. 安全密集型代码,许可证验证代码,家庭基础通信代码,网络代码。 These are all prime targets - put your energy into making these thorny places to live. 这些都是主要目标 - 将精力投入到制造这些棘手的地方。

  • Keep in mind that binaries from the largest corporations on the earth are routinely reverse engineered by people in their early 20's. 请记住,来自地球上最大公司的二进制文件经常被20世纪初的人们逆向设计。

  • Don't leave your debugging symbols in the final binary, as those will definitely help with analysis. 不要将调试符号留在最终二进制文件中,因为这些符号肯定有助于分析。

  • If you are dedicated to doing this right, also focus on wasting the engineers time - time is always against the reverse engineer. 如果您致力于做到这一点,也要专注于浪费工程师的时间 - 时间总是反对逆向工程师。

Remember, that any meaningful obfuscation might also cost you the performance gains that justified working in C++ in the first place. 请记住,任何有意义的混淆都可能会使您首先在C ++中使用合理的性能提升。 There are many zones in the C world (and for that matter the Java world) where meaningful obfuscation just isn't possible. C世界中有许多区域(对于Java世界而言),有可能无法进行有意义的混淆。 Games for instance, cannot conceal their calls to the OpenGl APIs, nor can they truly prevent engineers from harvesting their shader code. 例如,游戏无法隐藏他们对OpenGl API的调用,也无法真正阻止工程师收集着色器代码。

Also remember that the reverse engineer is watching your code at the assembly level most of the time. 还要记住,逆向工程师大多数时间都在组装级别上查看代码。 He'd rather have your function names, but he can live without it if need be. 他宁愿拥有你的功能名称,但如果需要,他可以没有它。 He can see what your program is doing at the most finite level possible. 他可以在最有限的水平上看到你的程序正在做什么。 It is only a matter of time before he finds the critical routines. 他找到关键的惯例只是时间问题。

For your purposes, find a program to mangle function names, make your boss happy, and call it a day. 为了您的目的,找到一个程序来破坏功能名称,让老板高兴,并称之为一天。 At least at that point, reverse engineering the software will not be trivial . 至少在那时,对软件进行逆向工程并不是一件容易的事。

Well really you have 2 primary vectors that you have to guard against 那么你真的有两个主要的向量,你必须防范

  1. Disassembley Disassembley
  2. Debugging 调试

My favourite method for preventing the first issue is in memory decryption, take parts of your executable code and encrypt it, have it self decrypt in memory while your library is running, you can also checksum parts of the code and compare the checksum against what is loaded in ram ( have the encrypted portions check the decrypter and vice versa ) 我最喜欢的防止第一个问题的方法是在内存解密,获取可执行代码的一部分并加密它,在库运行时让它在内存中自我解密,你也可以校验部分代码并将校验和与什么是比较在ram中加载(加密部分检查解密器,反之亦然)

Another neat trick is to statically link libraries that you use into your executible so they cannot be easily swapped out to try to see what your code is doing. 另一个巧妙的技巧是将您使用的库静态链接到您的可执行文件中,这样就无法轻易地将它们换出来试图查看代码正在执行的操作。

Now debugging checking interrupt vectors helps, another trick is to check the 'timing' between various portions of code ( for example if more than a couple of milliseconds worth of delay occurs in code that should execute significantly faster than that then it can be assumed that the code is being debugged 现在调试检查中断向量有帮助,另一个技巧是检查代码的各个部分之间的“时序”(例如,如果代码中发生的延迟超过几毫秒,应该执行的速度明显快于那么可以假设代码正在调试中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM