我说的是一款没有得分上限的动作游戏,也没有办法通过重玩动作等方式来验证服务器上的分数。

我真正需要的是在Flash/PHP中最强的加密,以及一种防止人们调用PHP页面而不是通过我的Flash文件的方法。我在过去尝试了一些简单的方法,对一个分数进行多次调用,完成一个校验和/斐波那契序列等,也用Amayeta SWF加密混淆SWF,但他们最终都被黑客入侵了。

感谢StackOverflow的响应,我现在从Adobe找到了更多的信息- http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps_12.html和https://github.com/mikechambers/as3corelib -我认为我可以使用加密。但我不确定这是否能让我绕过CheatEngine。

我需要知道AS2和AS3的最佳解决方案,如果它们是不同的。

主要的问题似乎是TamperData和LiveHTTP报头,但我知道还有更高级的黑客工具,比如CheatEngine(感谢Mark Webster)


当前回答

使用已知(私有)可逆密钥进行加密是最简单的方法。我不完全使用AS,所以我不确定有哪些类型的加密提供商。

但你也可以加入游戏长度(同样是加密的)和点击次数等变量。

所有这类事情都可以逆向工程,所以可以考虑扔进一堆垃圾数据来迷惑人们。

编辑:可能也值得加入一些PHP会话。当玩家点击“开始游戏”时便开始游戏,并记录时间。当他们提交分数时,你可以检查他们是否有一个开放的游戏,他们没有过早或过大地提交分数。

也许有必要计算出一个标量,比如每秒钟/分钟游戏的最大分数。

这两件事都不是不可避免的,但这将有助于在Flash之外的地方设置一些逻辑,让人们可以看到它。

其他回答

Whenever your highscore system is based on the fact that the Flash application sends unencrpyted/unsigned highscore data via the network, that can be intercepted and manipulated/replayed. The answer follows from that: encrypt (decently!) or cryptographically sign highscore data. This, at least, makes it harder for people to crack your highscore system because they'll need to extract the secret key from your SWF file. Many people will probably give up right there. On the other hand, all it takes is a singly person to extract the key and post it somewhere.

真正的解决方案包括在Flash应用程序和高分数据库之间进行更多的通信,以便后者能够验证给定的分数是否真实。这可能很复杂,这取决于你的游戏类型。

使用已知(私有)可逆密钥进行加密是最简单的方法。我不完全使用AS,所以我不确定有哪些类型的加密提供商。

但你也可以加入游戏长度(同样是加密的)和点击次数等变量。

所有这类事情都可以逆向工程,所以可以考虑扔进一堆垃圾数据来迷惑人们。

编辑:可能也值得加入一些PHP会话。当玩家点击“开始游戏”时便开始游戏,并记录时间。当他们提交分数时,你可以检查他们是否有一个开放的游戏,他们没有过早或过大地提交分数。

也许有必要计算出一个标量,比如每秒钟/分钟游戏的最大分数。

这两件事都不是不可避免的,但这将有助于在Flash之外的地方设置一些逻辑,让人们可以看到它。

这是网络游戏和竞赛的一个经典问题。你的Flash代码与用户一起决定游戏的得分。但是用户不受信任,Flash代码运行在用户的计算机上。你是SOL,你无法阻止攻击者伪造高分:

Flash甚至比你想象的更容易进行反向工程,因为字节码有良好的文档记录,并描述了一种高级语言(Actionscript)——当你发布一款Flash游戏时,你就是在发布你的源代码,不管你是否知道。 攻击者控制Flash解释器的运行时内存,因此任何知道如何使用可编程调试器的人都可以在任何时候改变任何变量(包括当前分数),或者改变程序本身。

对系统最简单的攻击是通过代理运行游戏的HTTP流量,捕获高分保存,然后以更高的分数重放。

你可以尝试通过将每个高分保存绑定到游戏的单个实例来阻止这种攻击,例如在游戏启动时向客户端发送加密令牌,如下所示:

hex-encoding( AES(secret-key-stored-only-on-server, timestamp, user-id, random-number))

(您也可以使用会话cookie来达到同样的效果)。

游戏代码将这个令牌用高分保存回服务器。但攻击者仍然可以再次启动游戏,获得令牌,然后立即将该令牌粘贴到重放的高分保存文件中。

因此,接下来不仅要提供一个令牌或会话cookie,还要提供一个高分加密会话密钥。这将是一个128位AES密钥,它本身是用硬编码到Flash游戏中的密钥加密的:

hex-encoding( AES(key-hardcoded-in-flash-game, random-128-bit-key))

现在,在游戏发布高分之前,它会解密高分加密会话密钥,这是因为你将高分加密会话密钥硬编码到Flash二进制文件中。你用这个解密的密钥加密高分,以及高分的SHA1哈希值:

hex-encoding( AES(random-128-bit-key-from-above, high-score, SHA1(high-score)))

服务器上的PHP代码检查令牌,以确保请求来自一个有效的游戏实例,然后解密加密的高分,检查以确保高分与高分的SHA1匹配(如果跳过这一步,解密只会产生随机的,可能非常高的高分)。

So now the attacker decompiles your Flash code and quickly finds the AES code, which sticks out like a sore thumb, although even if it didn't it'd be tracked down in 15 minutes with a memory search and a tracer ("I know my score for this game is 666, so let's find 666 in memory, then catch any operation that touches that value --- oh look, the high score encryption code!"). With the session key, the attacker doesn't even have to run the Flash code; she grabs a game launch token and a session key and can send back an arbitrary high score.

你现在已经到了大多数开发者放弃的时候了——在与攻击者纠缠了几个月之后:

用异或操作打乱AES键 用计算键的函数替换键字节数组 在二进制文件中散布假密钥加密和高分帖子。

这基本上是在浪费时间。不用说,SSL也帮不了你;当两个SSL端点中的一个是邪恶的时,SSL无法保护您。

以下是一些能够有效减少高分作弊的方法:

Require a login to play the game, have the login produce a session cookie, and don't allow multiple outstanding game launches on the same session, or multiple concurrent sessions for the same user. Reject high scores from game sessions that last less than the shortest real games ever played (for a more sophisticated approach, try "quarantining" high scores for game sessions that last less than 2 standard deviations below the mean game duration). Make sure you're tracking game durations serverside. Reject or quarantine high scores from logins that have only played the game once or twice, so that attackers have to produce a "paper trail" of reasonable looking game play for each login they create. "Heartbeat" scores during game play, so that your server sees the score growth over the lifetime of one game play. Reject high scores that don't follow reasonable score curves (for instance, jumping from 0 to 999999). "Snapshot" game state during game play (for instance, amount of ammunition, position in the level, etc), which you can later reconcile against recorded interim scores. You don't even have to have a way to detect anomalies in this data to start with; you just have to collect it, and then you can go back and analyze it if things look fishy. Disable the account of any user who fails one of your security checks (for instance, by ever submitting an encrypted high score that fails validation).

记住,你只是在阻止高分欺诈。你无法阻止它的发生。如果你的游戏中存在金钱风险,那么总有人会打败你所想出的任何系统。我们的目标不是阻止这次袭击;这是为了让攻击变得更加昂贵,而不仅仅是精通游戏并击败它。

一种简单的方法是提供高分值的加密散列及其本身的分数。例如,当通过HTTP GET发布结果时: http://example.com/highscores.php?score=500&checksum=0a16df3dc0301a36a34f9065c3ff8095

当计算这个校验和时,应该使用一个共享秘密;这个秘密永远不应该通过网络传输,而应该在PHP后端和flash前端中硬编码。上面的校验和是通过将字符串“secret”前置到分数“500”前,并通过md5sum运行来创建的。

Although this system will prevent a user from posting arbitrary scores, it does not prevent a "replay attack", where a user reposts a previously calculated score and hash combination. In the example above, a score of 500 would always produce the same hash string. Some of this risk can be mitigated by incorporating more information (such as a username, timestamp, or IP address) in the string which is to be hashed. Although this will not prevent the replay of data, it will insure that a set of data is only valid for a single user at a single time.

为了防止任何重放攻击的发生,必须创建某种类型的挑战-响应系统,例如:

The flash game ("the client") performs an HTTP GET of http://example.com/highscores.php with no parameters. This page returns two values: a randomly generated salt value, and a cryptographic hash of that salt value combined with the shared secret. This salt value should be stored in a local database of pending queries, and should have a timestamp associated with it so that it can "expire" after perhaps one minute. The flash game combines the salt value with the shared secret and calculates a hash to verify that this matches the one provided by the server. This step is necessary to prevent tampering with salt values by users, as it verifies that the salt value was actually generated by the server. The flash game combines the salt value with the shared secret, high score value, and any other relevant information (nickname, ip, timestamp), and calculates a hash. It then sends this information back to the PHP backend via HTTP GET or POST, along with the salt value, high score, and other information. The server combines the information received in the same way as on the client, and calculates a hash to verify that this matches the one provided by the client. It then also verifies that the salt value is still valid as listed in the pending query list. If both these conditions are true, it writes the high score to the high score table and returns a signed "success" message to the client. It also removes the salt value from the pending query list.

请记住,如果用户可以访问共享秘密,则上述任何技术的安全性都会受到损害

作为一种替代方法,可以通过强制客户端通过HTTPS与服务器通信,并确保客户端预先配置为只信任由您单独有权访问的特定证书颁发机构签署的证书来避免这种来回。

在接受的答案中,tqbf提到你可以对分数变量进行内存搜索(“我的分数是666,所以我在内存中寻找666这个数字”)。

这是有办法的。我在这里有一门课:http://divillysausages.com/blog/safenumber_and_safeint

基本上,你有一个对象来存储你的分数。在setter中,它将您传递给它的值与一个随机数(+和-)相乘,而在getter中,您将保存的值除以随机乘数以获得原始值。这很简单,但有助于停止记忆搜索。

另外,看看PushButton引擎背后的一些人的视频,他们谈论了一些对抗黑客的不同方法:http://zaa.tv/2010/12/the-art-of-hacking-flash-games/。他们是这门课背后的灵感。