Client can Change user variable?

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

SkaiCloud
Posts: 8
Joined: 01 May 2013, 04:20

Client can Change user variable?

Postby SkaiCloud » 09 May 2013, 00:15

Hello,
I have a game that access uservariable and roomvariable. My test team report that they can change uservariable by using cheat engine. I was almost sure that this wouldn't be possible. Am I doing something wrong.

Code: Select all

if(Sfs.MySelf.GetVariable("PlayerMoney").GetIntValue() >= Sfs.LastJoinedRoom.GetVariable(ItemID+"Price").GetIntValue())
{
 Debug.log("Item Buy Success");
  //update player money
 List<UserVariable> userVariables = new List<UserVariable>();
userVariables.Add(new SFSUserVariable("PlayerMoney", (int)Sfs.MySelf.GetVariable("PlayerMoney").GetIntValue() Sfs.LastJoinedRoom.GetVariable(ItemID+"Price").GetIntValue()));
Sfs.Send(new SetUserVariablesRequest(userVariables));
}
else
{
 Debug.log("Insufficient Funds");
}
anniyan137
Posts: 25
Joined: 20 Nov 2012, 10:49

Re: Client can Change user variable?

Postby anniyan137 » 09 May 2013, 06:34

Firstly, this question has to be moved to the.NET/C# Unity Client side forum.

And secondly, may I ask what exactly is the issue here? Could you elaborate on what exactly is going wrong? That way we may be able to help you better.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client can Change user variable?

Postby Lapo » 09 May 2013, 07:33

( Moved in the proper section )
Lapo
--
gotoAndPlay()
...addicted to flash games
SkaiCloud
Posts: 8
Joined: 01 May 2013, 04:20

Re: Client can Change user variable?

Postby SkaiCloud » 09 May 2013, 07:36

First sorry I thought this would be a server side issue.

This is my setup.
My room variable is manually assign to the room via admin panel.
zone configuration > MyZone > MyRoom > RoomVariable > add (multiple item variable inside here. Mostly Price of the items)

Client login to game > database send SfsObject data back to client to load proper data and convert it into UserVariable.

example:

Code: Select all

         List<UserVariable> userVariables = new List<UserVariable>();
         userVariables.Add(new SFSUserVariable("CharLevel",(int)ObjIn.GetInt("LVL")));
         userVariables.Add(new SFSUserVariable("CharChr",(int)ObjIn.GetInt("CHR")));
         userVariables.Add(new SFSUserVariable("CharStr",(int)ObjIn.GetInt("STR")));
         userVariables.Add(new SFSUserVariable("CharVig",(int)ObjIn.GetInt("VIG")));
         userVariables.Add(new SFSUserVariable("CharSilver",(int)ObjIn.GetInt("SILV")));
         Sfs.Send(new SetUserVariablesRequest(userVariables));


Player Go into Shop and try to buy an item and client code does this check:

Code: Select all

if(Sfs.MySelf.GetVariable("CharSilver").GetIntValue() >= Sfs.LastJoinedRoom.GetVariable(ItemID+"Price").GetIntValue())
{
 Debug.log("Item Buy Success");
  //update player money
 List<UserVariable> userVariables = new List<UserVariable>();
userVariables.Add(new SFSUserVariable("CharSilver", (int)Sfs.MySelf.GetVariable("CharSilver").GetIntValue() -Sfs.LastJoinedRoom.GetVariable(ItemID+"Price").GetIntValue()));
Sfs.Send(new SetUserVariablesRequest(userVariables));
}
else
{
 Debug.log("Insufficient Funds");
}


Then we would use CheatEngine to hack the game money by changing it's value and it successfully accomplish its task. I was under the impression that a uservariable is stored on the server though the client can see it they shouldn't be able to change it's value without sending a SetUserVariablesRequest.
Is there something I'm not understanding correctly here?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client can Change user variable?

Postby Lapo » 09 May 2013, 08:03

No, the RoomVariables and UserVariables are transmitted to the client and your code takes place exclusively on the client, therefore there's no way to avoid this kind of cheating.

In order to protect your client from these attacks you need to move the shopping logic to the server side, this way cheating is not possible.
Also you need to protect RoomVariables that represent price by making them private.

Please make sure to read this:
http://docs2x.smartfoxserver.com/Develo ... -variables
Lapo

--

gotoAndPlay()

...addicted to flash games
SkaiCloud
Posts: 8
Joined: 01 May 2013, 04:20

Re: Client can Change user variable?

Postby SkaiCloud » 09 May 2013, 08:23

Thanks for the reply Lapo but I was under the impression that once you convert the local variable to UserVariable it would be stored in the smartfoxserver and the only way to change it's value was via SetUserVariable request through the Api. According to the link if I set the UserVariable flag to private and do my shop calculation on the server end would that fix it? All my RoomVariable is already set to private and persistence.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client can Change user variable?

Postby Lapo » 09 May 2013, 08:40

What you are saying is correct. You can only set variables (Room or User) via SetUserVariable / SetRoomVariable requests.

But you have posted this:
My test team report that they can change uservariable by using cheat engine.


Of course if you hack the local memory with some tool you can cheat in the system. That's why the client is not to be trusted when you need security and that's why you need to keep your sensitive information on the server side and guard it via validation code.

If you want to learn more about security take a look at our Security White Paper here:
http://docs2x.smartfoxserver.com/Overview/white-papers
Lapo

--

gotoAndPlay()

...addicted to flash games
anniyan137
Posts: 25
Joined: 20 Nov 2012, 10:49

Re: Client can Change user variable?

Postby anniyan137 » 10 May 2013, 13:17

Whoah! Had never considered this scenario for my project! :shock:

Need to work on this right away.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Client can Change user variable?

Postby Lapo » 10 May 2013, 13:39

Yep :) Take a look at the whitepaper there's lots of material on how to secure your application on both sides.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 32 guests