简体   繁体   English

Java代码,安全性

[英]Java code, Being Secure

I am creating a client program that talks to a server (which I programmed). 我正在创建与服务器(我已编程)对话的客户端程序。 I am making a little game for myself in which I roll a dice and the server does also. 我正在为自己制作一个小游戏,我掷骰子,服务器也这样做。 Whoever gets the higher numbers wins. 获得更高数字的人将获胜。 However within my code, I send the server commands when the user presses a button, and then the server responds by sending back what it rolled, so it can be shown in the GUI window. 但是,在我的代码中,我在用户按下按钮时发送服务器命令,然后服务器通过发回滚动内容进行响应,因此可以在GUI窗口中显示。 However, I find this a very insecure method. 但是,我发现这是一种非常不安全的方法。 For example, a person could just simply decompile the jar file, and make it so they always roll a 12. Since the only place that both rolls are together (the users and the servers) is the users screen, I have to evaluate the game from the client, obviously not very secure. 例如,一个人可以简单地反编译jar文件,并使其始终滚动12。由于两个滚动(用户和服务器)在一起的唯一位置是用户屏幕,因此我必须评估游戏从客户端,显然不是很安全。 I am trying to make my game more secure, and have found 2 options. 我试图使我的游戏更加安全,并找到2个选项。

  1. Obfuscators 混淆器

    • Unless someone knows of a very easy one to use, I cannot figure out how to set any of them up, as they rarely come with a gui that I can easily "pop" my .jar file into 除非有人知道一个非常易于使用的文件,否则我无法弄清楚如何设置其中的任何文件,因为它们很少带有gui,我可以轻松地将我的.jar文件“弹出”到其中。
  2. Binding to an .exe 绑定到.exe

    • I honestly dont know how secure this is. 老实说,我不知道这有多安全。 There are programs in which I can "bind" two things (mostly for making viruses which I am obviously not doing), into a single .exe file. 在某些程序中,我可以将两件事(主要是使我显然没有在做的病毒)“绑定”到一个.exe文件中。 I can bind my .jar into an .exe, but I still dont know if the .exe could be decompiled back into the .jar file and from there back into the .java code. 我可以将.jar绑定到.exe中,但是我仍然不知道.exe是否可以反编译为.jar文件,然后再反编译为.java代码。

By the way, another security issue is that it connects to the server from my ip adress (which I do not want the client user to know about) 顺便说一句,另一个安全问题是它从我的ip地址连接到服务器(我不希望客户端用户知道)

Never trust client input. 永远不要相信客户的意见。

The only truly "secure" method is to have the server generate both its own roll and a roll for the client. 唯一真正的“安全”方法是让服务器既生成自己的滚动又为客户端生成滚动。

Of course, if the outcome of the comparison of the rolls has no impact beyond what the user sees (in other words, the client does not report back who won), then really, who cares? 当然,如果掷骰子比较的结果没有超出用户看到的影响(换句话说,客户不会报告谁赢了),那么,真的,谁在乎? I could patch Solitaire to let me always win, but that's no fun. 我可以给Solitaire打补丁,让我总是赢,但这没什么好玩的。

If the code is on someone's computer, you should consider it compromised and exploited already. 如果该代码在某人的计算机上,则应认为该代码已被盗用。 In the race between crackers and developers, the crackers always win because the crackers have everything they need. 在饼干和开发人员之间的竞赛中,饼干总是赢家,因为饼干拥有他们所需的一切。 Jars can be (easily) decompiled and deobfuscated, .exes can be picked apart, and at extreme levels the OS can be modified to go behind your back - literally. Jars可以(轻松)反编译和反混淆,.exe可以分拆,并且在极端情况下,OS可以修改为落后。

Instead, you should reconsider your architecture: do you really need the client to roll the dice? 相反,您应该重新考虑您的体系结构:您是否真的需要客户端掷骰子? Could the server roll both? 服务器可以同时滚动吗?

Both obfuscation and compiling to a ".exe" can be defeated relatively easily. 混淆和编译为“ .exe”都可以相对轻松地克服。 Hackers / crackers, and anti-virus security experts do this kind of thing every day. 黑客/破解者和防病毒安全专家每天都会做这种事情。

Basically, you cannot trust any application that is running on any machine that could be controlled by someone you don't trust. 基本上,您不能信任在不受您信任的人控制的任何计算机上运行的任何应用程序。 In practice, this means anything that isn't in your (locked and firewalled) server room. 实际上,这意味着不在您的服务器房(锁定和防火墙)中。

(Aside: even systems based on TPM are potentially vulnerable, since there have been successful attacks on TPM chips. And that wouldn't be practical anyway, since TPM is not available for securing application-level code. AFAIK, it is not even used at the OS level ... though I've heard that the next version of Windows is going to require hardware that is TPM encumbered.) (此外:由于对TPM芯片进行了成功的攻击,即使是基于TPM的系统也很容易受到攻击。而且,由于TPM无法用于保护应用程序级代码,因此无论如何这都是不实际的。AFAIK,甚至都没有使用它在操作系统级别...尽管我听说Windows的下一版本将需要使用受TPM约束的硬件。)

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

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