<p>I'm playing around with a native (non-web) single-player game I'm writing, and it occured to me that having a daily/weekly/all-time <strong>online highscore list</strong> (think Xbox Live Leaderboard) would make the game much more interesting, adding some (small) amount of community and competition. However, I'm afraid people would see such a feature as an invitation to hacking, which would discourage regular players due to impossibly high scores.</p>

<p>I thought about the obvious ways of preventing such attempts (public/private key encryption, for example), but I've figured out reasonably simple ways hackers could circumvent all of my ideas (extracting the public key from the binary and thus sending fake encrypted scores, for example).</p>

<p>Have you ever implemented an online highscore list or leaderboard? Did you find a reasonably hacker-proof way of implementing this? If so, how did you do it? What are your experiences with hacking attempts?</p>

[{'answer_id': 26008, 'author': 'sparkes', 'author_id': 269, 'author_profile': 'https://Stackoverflow.com/users/269', 'pm_score': 3, 'selected': False, 'text': "<p>I honestly don't think it's possible.</p>\n\n<p>I've done it before using pretty simple key encryption with a compressed binary which worked well enough for the security I required but I honestly think if somebody considers cracking your online high score table a hack it will be done.  </p>\n\n<p>There are some pretty sad people out there who also happen to be pretty bright unless you can get them all laid it's a lost cause.</p>\n"}, {'answer_id': 26015, 'author': 'grapefrukt', 'author_id': 914, 'author_profile': 'https://Stackoverflow.com/users/914', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ve been doing some of this with my Flash games, and it\'s a losing battle really. Especially for ActionScript that can be decompiled into somewhat readable code without too much effort.</p>\n\n<p>The way I\'ve been doing it is a rather conventional approach of sending the score and player name in plain text and then a hash of the two (properly salted). Very few people are determined enough to take the effort to figure that out, and the few who are would do it anyway, negating all the time you put into it.  </p>\n\n<p>To summarize, my philosophy is to spend the time on making the game better and just make it hard enough to cheat. </p>\n\n<p>One thing that might be pretty effective is to have the game submit the score to the server several times as you are playing, sending a bit of gameplay information each time, allowing you to validate if the score is "realistic". But that might be a bit over-the-top really.</p>\n'}, {'answer_id': 26024, 'author': 'Matt Sheppard', 'author_id': 797, 'author_profile': 'https://Stackoverflow.com/users/797', 'pm_score': 5, 'selected': False, 'text': "<p>No solution is ever going to be perfect while the game is running on a system under the user's control, but there are a few steps you could take to make hacking the system more trouble. In the end, the goal can only be to make hacking the system more trouble than it's worth.</p>\n\n<ul>\n<li>Send some additional information with the high score requests to validate one the server side. If you get 5 points for every X, and the game only contains 10 Xs, then you've got some extra hoops to make the hacker to jump through to get their score accepted as valid.</li>\n<li>Have the server send a random challenge which must be met with a few bytes of the game's binary from that offset. That means the hacker must keep a pristine copy of the binary around (just a bit more trouble).</li>\n<li>If you have license keys, require high scores to include them, so you can ban people caught hacking the system. This also lets you track invalid attempts as defined above, to ban people testing out the protocol before the ever even submit a valid score.</li>\n</ul>\n\n<p>All in all though, getting the game popular enough for people to care to hack it is probably a far bigger challenge.</p>\n"}, {'answer_id': 26036, 'author': 'Ari Pernick', 'author_id': 2564, 'author_profile': 'https://Stackoverflow.com/users/2564', 'pm_score': 2, 'selected': False, 'text': '<p>As the other answer says, you are forced to trust a potentially malicious client, and a simple deterant plus a little human monitoring is going to be enough for a small game.</p>\n\n<p>If you want to get fancy, you then have to look for fraud patterns in the score data, simmular to a credit card company looking at charge data. The more state the client communicates onto your server, the potentially easier it is to find a pattern of correct or incorrect behavior via code. For example. say that the client had to upload a time based audit log of the score (which maybe you can also use to let another clients watch the top games), the server can then validate if the score log breaks any of the game rules.</p>\n\n<p>In the end, this is still about making it expensive enough to discourage cheating the scoreboard. You would want a system where you can always improve the (easier to update)server code to deal with any new attacks on your validation system.</p>\n'}, {'answer_id': 26047, 'author': 'Jorge Córdoba', 'author_id': 2695, 'author_profile': 'https://Stackoverflow.com/users/2695', 'pm_score': 2, 'selected': False, 'text': '<p>That\'s a really hard question.</p>\n\n<p>I\'ve never implemented such thing but here\'s a simple aproximmation.</p>\n\n<p>Your main concern is due to hackers guessing what is it your application is doing and then sending their own results.</p>\n\n<p>Well, first of all, unless your application has a great success I wouldn\'t be worried. Doing such thing is extremely difficult.</p>\n\n<p>Encryption won\'t help with the problem. You see, encryption helps to protect the data on its way but it doesn\'t protect either of the sides of the transaction before the data is encrypted (which is where the main vulnerability may be). So if you encrypt the sure, the data will remain private but it won\'t be safe.</p>\n\n<p>If you are really worried about it I will suggest obfuscating the code and designing the score system in a way which is not completely obvious what is doing. Here we can borrow some things from an encryption protocol. Here is an example:</p>\n\n<ol>\n<li>Let\'s say the score is some number m</li>\n<li>Compute some kind of check over the score (for example the CRC or any other system you see feet. In fact, if you just invent one, no matter how lame is it it will work better)</li>\n<li>Obtain the private key of the user (D) from your remote server (over a secure connection obviously). You\'re the only one which know this key.</li>\n<li>Compute X=m^D mod n (n being the public module of your public/private key algorithm) (that is, encrypt it :P)</li>\n</ol>\n\n<p>As you see that\'s just obfuscation of another kind. You can go down that way as long as you want. For example you can lookup the nearest two prime numbers to X and use them to encrypt the CRC and send it also to the server so you\'ll have the CRC and the score separately and with different encryption schemes.</p>\n\n<p>If you use that in conjunction with obfuscation I\'d say that would be difficult to hack. Nontheless even that could be reverse engingeered, it all depends on the interest and ability of the hacker but ... seriously, what kind of freak takes so much effort to change its results on a game? (Unless is WoW or something)</p>\n\n<p>One last note</p>\n\n<p><a href="http://www.preemptive.com/dotfuscator.html" rel="nofollow noreferrer">Obfuscator for .NET</a></p>\n\n<p><a href="http://www.sourceformat.com/code-obfuscator.htm" rel="nofollow noreferrer">Obfuscator for Delphi/C++</a></p>\n\n<p><a href="http://www.pelock.com/products/obfuscator" rel="nofollow noreferrer">Obfuscator for assembler (x86)</a></p>\n'}, {'answer_id': 33687, 'author': 'Martin', 'author_id': 2581, 'author_profile': 'https://Stackoverflow.com/users/2581', 'pm_score': 3, 'selected': False, 'text': "<p>If your game has a replay system built in, you can submit replays to the server and have the server calculate the score from the replay.</p>\n\n<p>This method isn't perfect, you can still cheat by slowing down the game (if it is action-based), or by writing a bot.</p>\n"}, {'answer_id': 33706, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 2, 'selected': False, 'text': '<p>@Martin.  </p>\n\n<p>This is how I believe Mario Kart Wii works. The added bonus is that you can let all the other players watch how the high score holder got the high score.  The funny thing about this is that if you check out the fastest "<a href="http://www.youtube.com/watch?v=joMbFFk6WZ8" rel="nofollow noreferrer">Grumble Volcano</a>" time trail, you\'ll see that somebody found a shortcut that let you skip 95% of the track. I\'m not sure if they still have that up as the fastest time.</p>\n'}, {'answer_id': 145450, 'author': 'Michael Labbé', 'author_id': 22244, 'author_profile': 'https://Stackoverflow.com/users/22244', 'pm_score': 6, 'selected': True, 'text': '<p>At the end of the day, you are relying on trusting the client.  If the client sends replays to the server, it is easy enough to replicable or modify a successful playthrough and send that to the server.</p>\n\n<p>Your best bet is to raise the bar for cheating above what a player would deem worth surmounting.  To do this, there are a number of proven (but oft-unmentioned) techniques you can use:</p>\n\n<ol>\n<li>Leave blacklisted cheaters in a honeypot.  They can see their own scores, but no one else can.  Unless they verify by logging in with a different account, they think they have successfully hacked your game.</li>\n<li>When someone is flagged as a cheater, defer any account repercussions from transpiring until a given point in the future.  Make this point random, within one to three days.  Typically, a cheater will try multiple methods and will eventually succeed.  By deferring account status feedback until a later date, they fail to understand what got them caught.</li>\n<li>Capture all game user commands and send them to the server.  Verify them against other scores within a given delta.  For instance, if the player used the shoot action 200 times, but obtained a score of 200,000, but the neighboring players in the game shot 5,000 times to obtain a score of 210,000, it may trigger a threshold that flags the person for further or human investigation.</li>\n<li>Add value and persistence to your user accounts.  If your user accounts have unlockables for your game, or if your game requires purchase, the weight of a ban is greater as the user cannot regain his previous account status by simply creating a new account through a web-based proxy.</li>\n</ol>\n'}, {'answer_id': 145469, 'author': 'MarkR', 'author_id': 13724, 'author_profile': 'https://Stackoverflow.com/users/13724', 'pm_score': 2, 'selected': False, 'text': '<p>You can\'t do it on a nontrusted client platform. In practice it is possible to defeat even some "trusted" platforms.</p>\n\n<p>There are various attacks which are impossible to detect in the general case - mainly modifying variables in memory. If you can\'t trust your own program\'s variables, you can\'t really achieve very much.</p>\n\n<p>The other techniques outlined above may help, but don\'t solve the basic problem of running on a nontrusted platform.</p>\n\n<hr>\n\n<p>Out of interest, are you sure that people will try to hack a high score table? I have had a game online for over two years now with a trivially-crackabe high score table. Many people have played it but I have no evidence that anyone\'s tried to crack the high scores. </p>\n'}, {'answer_id': 14008176, 'author': 'James', 'author_id': 1924423, 'author_profile': 'https://Stackoverflow.com/users/1924423', 'pm_score': 1, 'selected': False, 'text': "<p>Usually, the biggest defender against cheating and hacking is a community watch. If a score seems rather suspicious, a user can report the score for cheating. And if enough people report that score, the replay can be checked by the admins for validity. It is fairly easy to see the difference between a bot an an actual player, if there's already a bunch of players playing the game in full legitimacy.</p>\n\n<p>The admins must oversee only those scores that get questioned, because there is a small chance that a bunch of users might bandwagon to remove a perfectly hard-earned score. And the admins only have to view the few scores that do get reported, so it's not too much of their time, even less for a small game.</p>\n\n<p>Even just knowing that if you work hard to make a bot, just to be shot down again by the report system, is a deterrent in itself.</p>\n\n<p>Perhaps even encrypting the replay data wouldn't hurt, either. Replay data is often small, and encrypting it wouldn't take too much more space. And to help improve that, the server itself would try out the replay by the control log, and make sure it matches up with the score achieved.</p>\n\n<p>If there's something the anti-cheat system can't find, users will find it.</p>\n"}]
['https://Stackoverflow.com/questions/25999', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/996/']