1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Protecting data sent over GET

Discussion in 'PHP' started by qscomputing, Jan 2, 2006.

  1. #1
    Hi,

    I am developing an online highscoreboard system using PHP and MySQL. I need a way for scores to be sent from the game to the highscoreboard over HTTP. My first thought was to simple open a webpage:
    http://my-server/my-script.php?score=42

    However, this is clearly open to abuse once people work out the name of the script.

    So, I need a way of protecting the score data, or some kind of checksum which allows the server to verify that the data actually came from the game (ie. the game computes a checksum from the score and sends it with the score to the server, which checks whether the checksum is correct). I hope this is clear enough.

    Any suggestions for a reasonably secure system, and how to implement it in PHP?

    Oh, the highscoreboard system will be an open-source general system that can be dropped into any game.

    TIA,
    - QS Computing.
     
    qscomputing, Jan 2, 2006 IP
  2. n0other

    n0other Peon

    Messages:
    146
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'd suggest you to look into mcrypt extension and 'shared secrets' message protection. You encrypt your data on one end (game) using some secret key, send it over network to another end (scoreboard), which knows the secret key and can decrypt the data. Good luck.
     
    n0other, Jan 2, 2006 IP
  3. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #3
    besides that, maybe you can check that the referrer is a valid referrer... e.g. the referrer must be from another page from your site...

    this way, if someone tries to key in the url directly into the browser or codes the url into one of their own webpages, you'd not process the request...
     
    daboss, Jan 2, 2006 IP
  4. n0other

    n0other Peon

    Messages:
    146
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh, referer info can be faked easily. Or turned off. Not a reliable source I'd say.
     
    n0other, Jan 2, 2006 IP
  5. Voyager2K

    Voyager2K Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    is chance to first of all secure send decode key. After all GET data will be encoded and decoded by recipient.
     
    Voyager2K, Jan 2, 2006 IP
  6. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #6
    Why not just use a $_POST instead?
     
    fsmedia, Jan 2, 2006 IP
  7. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Because that can be spoofed as well.

    Why not just use a form to submit the scores that requires a password.


    
    if($_POST['password'] == 'somepassword')
    {
           //update scores
    }
    
    Code (markup):
    Using GET would just be a pain in my opinion.

    *edit*

    If you must use GET, I would add a unique field for a key on every game/score in your table something like:

    table games
    team1_id
    team2_id
    team1_score
    team2_score
    key (unique)
    score_locked (enum yes/no)

    So after passing your script something like ?team1_score=30&team2_score=50&key=jkjkjkjkjk and checking them for garbage you would use this query

    "select key from games where key = '$key' and score_locked = 'no' limit 1";

    If it found a match, you would then update as necessary.

    -the mole
     
    themole, Jan 2, 2006 IP
  8. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If you have access to the game server why would you trust the client to pass it to you? When the game's over, check the HighScores table, and update it if needed.

    Otherwise, about your only option is to trust the client. (Well, the suggestions about encrypting/signing work, but why bother, if you have access to the game server?)

    Or maybe I'm missing an important point.
     
    jimrthy, Jan 2, 2006 IP
  9. tccoder

    tccoder Peon

    Messages:
    69
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    hmm how about using https?
     
    tccoder, Jan 3, 2006 IP
  10. TMan

    TMan Peon

    Messages:
    126
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Why don't you sent the data in http headers? It's possible to hack this for sure, but quite a lot less obvious than using get...

    Maybe you should check how trackbacks (used on blogs) work exactly, something with xmlrpc I believe? You could use that I guess.

    Otherwise, there are quite some standard encryption functions in php I believe.
     
    TMan, Jan 3, 2006 IP
  11. Juls

    Juls Well-Known Member

    Messages:
    1,867
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    170
    #11
    if he is talking about implementing this with flash games then his only option is to send it via a get or post.

    Encrypting your data is definitely a good idea and possibly with a rotating key that changes daily or weekly.
     
    Juls, Jan 3, 2006 IP
  12. qscomputing

    qscomputing Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Actually, it's most probably going to be offline games, probably made with a tool like Game Maker (www.gamemaker.nl). The reason I say GET is that I know that that system has a command to open a web browser to a given page, which can of course include GET. Although it can use DLLs so I could use a more powerful language like Delphi or C++ to code something more sophisticated.

    I think the encryption is probably the best idea; does anyone know of a reasonable encryption module that can be implemented in both PHP and Delphi?

    Thanks,
    - QS Computing.
     
    qscomputing, Jan 3, 2006 IP
  13. n0other

    n0other Peon

    Messages:
    146
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I think you should look for whatever supports the encryption algorithm you are going to use, not for the same libs.. mcrypt for PHP. Don't know about delphi, but I'm sure there are plenty.

    I just got this idea.. Don't expect to be 100% secure even with encryption. You'd need to store the key on the users machine, probably in the game binary itself. Strings from binaries can be seen using such tool as 'strings' which is available on *nix like OS'es. Haven't tested it yet, but I'm pretty sure you could find the key if you wanted to. Of course you could retrieve the key in encrypted form from your server, but we'd encounter same problems as we would when we'd be sending our data.. Just brain storming. Howerer, don't give up on security thinking 'no one will bother cracking it'. Be sure, someone will. It's nice you've asked this question in the first place though.
     
    n0other, Jan 4, 2006 IP
  14. cornelius

    cornelius Peon

    Messages:
    206
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #14
    hmm why dont u either

    *remotely connect to the database
    or
    *use webservices
     
    cornelius, Jan 4, 2006 IP
  15. qscomputing

    qscomputing Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Remote database connections are out because of the way my server is set up.
    and
    Sorry, I don't know much about webservices, can you point me to some more information?

    Thanks,
    - QS Computing.
     
    qscomputing, Jan 4, 2006 IP
  16. TMan

    TMan Peon

    Messages:
    126
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #16
    How about a socket connection to your server? One could still intercept the data though, but that problem will last forever.
     
    TMan, Jan 5, 2006 IP
  17. Sham

    Sham Peon

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    lets say you have a field called highScore
    why not auto generate another field within your game called scoreCheck using some secret clientside function.

    Then, use a GET as normal, and in your server side script, perform the same function server side on highScore and see if you end up with scoreCheck again.

    If you do, then you know the highScore sent is legit. If not, then the user has modified either highScore or scoreCheck.

    Of course, you wanna be careful about hiding the function that generated scoreCheck, maybe obfuscating it in some way.

    Sham.
     
    Sham, Jan 6, 2006 IP
  18. ctdp

    ctdp Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    The most secure way is to generate a public key on your game server, then send the public key to the client, possibly with an additional known value attached. The client would use javascript to encrypt the answer and the known value and the server would decrypt the data using the private key. The known value should be a match when decrypted and the answer should be a numeric answer.

    The problem is that I do not know of any way to encrypt data with javascript. It can be done but requires math of a higher level of precision than javascript supports. I did find some code that does high precision math in javascript and would like to apply it to some other applications but I have yet to figure out how to get javascript to encrypt/decrypt using a public/private key system.
     
    ctdp, Jan 6, 2006 IP
  19. qscomputing

    qscomputing Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I'm looking at using mcrypt to decrypt the data and using a Delphi implementation of the same functions to encrypt and then send over HTTP. However, I know little about encryption so can somebody please tell me which algorithms are the best for my purposes?

    Thanks,
    - QS Computing.
     
    qscomputing, Jan 7, 2006 IP
  20. Sham

    Sham Peon

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #20

    A pretty good attempt, with minimal effort or learning, would be to do something simple, like divide the highsore by 53, add 16 and reverse the numbers, or something like that.

    Then do the opposite on the server end to get the score back?...

    Obviously, if someone REALLY really wanted to, they could experiement with changing the numbers - and may get lucky and end up with a big highscore by pure chance...
     
    Sham, Jan 7, 2006 IP