Damian666 / Orion-Plus-Game-Engine

Simple 2D ORPG game engine written in VB.Net.
Other
20 stars 17 forks source link

Password encryption #39

Closed Krilliac closed 7 years ago

Krilliac commented 7 years ago

0000 a0 21 b7 aa 04 ca 98 de d0 21 a6 a0 08 00 45 00 .!.......!....E. 0010 00 4b 51 cf 40 00 80 06 29 9b c0 a8 01 05 6b af .KQ.@...).....k. 0020 51 e6 d5 a8 1b 59 72 bd 00 ca 4b 24 7b aa 50 18 Q....Yr...K${.P. 0030 0f 2c 32 a4 00 00 1f 00 00 00 03 00 00 00 04 00 .,2............. 0040 00 00 74 65 73 74 04 00 00 00 74 65 73 74 07 00 ..test....test.. 0050 00 00 31 2e 30 2e 30 2e 31 ..1.0.0.1

from a packet sniff, username and password can be seen clear as day.

Krilliac commented 7 years ago

0000 98 de d0 21 a6 a0 a0 21 b7 aa 04 ca 08 00 45 00 ...!...!......E. 0010 00 d3 7c 78 40 00 72 06 0c 6a 6b af 51 e6 c0 a8 ..|x@.r..jk.Q... 0020 01 05 1b 59 d5 a8 4b 24 9d fb 72 bd 01 01 50 18 ...Y..K$..r...P. 0030 01 00 7d 69 00 00 20 00 00 00 42 00 00 00 01 00 ..}i.. ...B..... 0040 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................ 0050 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 16 00 ................ 0060 00 00 01 00 00 00 24 00 00 00 73 00 00 00 1e 00 ......$...s..... 0070 00 00 67 00 00 00 38 37 3b 31 30 31 3b 31 30 38 ..g...87;101;108 0080 3b 39 39 3b 31 31 31 3b 31 30 39 3b 31 30 31 3b ;99;111;109;101; 0090 33 32 3b 31 31 36 3b 31 31 31 3b 33 32 3b 31 31 32;116;111;32;11 00a0 36 3b 31 30 34 3b 31 30 31 3b 33 32 3b 37 39 3b 6;104;101;32;79; 00b0 31 31 34 3b 31 30 35 3b 31 31 31 3b 31 31 30 3b 114;105;111;110; 00c0 34 33 3b 33 32 3b 36 39 3b 31 31 30 3b 31 30 33 43;32;69;110;103 00d0 3b 31 30 35 3b 31 31 30 3b 31 30 31 3b 0b 00 00 ;105;110;101;... 00e0 00 .

NPC Movement coords (I think) don't know if this is a concern.. maybe reverse engineers/emulators trying to get WP data?

SpiceyWolf commented 7 years ago

The only packet information that should be of any concern is User information or movement/attack requests. Anything else like npc data or inventory count is handled purely server side and not hackable

SpiceyWolf commented 7 years ago

If damian or his friend whos been helping lately(Dunno if he still is, its been a while since i checked in on them) dont know much about encryption in .net ill give them a Asyncronous Keypair encryption system for the engine later on.

Krilliac commented 7 years ago

Server side packets should still be considered for encryption, since if lets say you made a game using this engine.. its big and popular, some one grabs all the opcodes (which are conveniently seen in the client) and make a packet sniffer that intercepts ClientTCP_OnRecieve and ClientTCP_OnSend and a parser that names them with their opcode (Like CMSG and SMSG), some one can use that to emulate the game and easily send edited packet data.. refer to this video as to what I'm talking about

https://www.youtube.com/watch?v=KWu5if3gSWY

Though since this is all in vb.net and open source, server side enryption may not even be necessary... since it's open source, but I've been in the WoW Emulation Community for 9 years.. and how easy it is to get info and data from the client and packets is just stupidly easy, easy enough to create an almost exact replica of every version of WoW except for the more 2/3 recent expansions.

But also, Blizzard recently tried obfuscation and further encryption in the game client, it was cracked within a couple days... so idk if it's even worth.

Damian666 commented 7 years ago

as far as I am aware, its not needed. because the server is written to handle all stuff, client has no power.

but yes, ill make at least the login stuff obfuscated.

SpiceyWolf commented 7 years ago

Encryption is an expensive process and you dont just use it on everything sent for the sake of using it... you only use it when you "have to" meaning only on important data that CAN NOT risk being seen like account data. Anything else is standard shit you do not throw performance away like free candy like that.

SpiceyWolf commented 7 years ago

Also Damian i just went through and optimized my encryption system and made sure it was really fckin tight -> Async Keypairs are the most complex encryption u can have because you got 2 keys -> One that can password lock and one that can open it up, guessing the openseseme password from the lock password is damn near impossible as large as this is and would still take a rediculous amount of time from a super computer to do.

My new lib ima update you with contains a built in encryption system using the Keypairs. It also generates unique keys by a simple generate function(Saves and loads to xml btw).

Using it be as simple as check if a key file exists, if not generate keys and create one, then just send the client when they connect the lock password and they can pack the data before sending it to server. Server then uses the open password to view it properly.

SpiceyWolf commented 7 years ago

Also when i get it off to you, theres a section called Generic Encryption -> Its light weight encryption thats optimal for IO encryption as if u got the files u probably got the key somewhere anyway so no need to get a super high quality key -> A simple one generated from a user set password works :D

SpiceyWolf commented 7 years ago

hey damian lemme know when ur around next if its okay to make a pull on the source to mod and reupload for you with the lib switch -> The file handle stuff requires a slight change(higher performance though) so i can make those changes for you and ill mod the network example code to include the encryption stuff so u can reference it

Krilliac commented 7 years ago

The server should check client movement speed to see if it correctly matches what ever is on the server.

Because i attached cheat engine to the client, turned on speed hack (which is GetTickCount and QueryPerformanceCounter) and was able to run around like a mad man with no resistance, server was acknowledging the movement because the amount of movement packets being logged ramped up drastically as you move around.

Movement speed is also handled client side

https://github.com/Damian666/Orion-Plus-Game-Engine/blob/master/Source/Client/Source/Modules/ClientConstants.vb#L48

which idk if it should be like that.. but correct me if im wrong in thinking these values should be moved over to the server and the client requests for the speed in the form of Opcodes/Packets

Krilliac commented 7 years ago

Yeah, just tested it again, ramped up cheat engine speed hack to max, and now the server is overloaded and trying to process every single packet request after being bombarded with client packets, needless to say.. all functions in game no longer work until it has fully processed all the packets.

My latency in game is 10000, it wont go past that.

One good thing though is after enough packets, you seem to get "Soft Disconnected" which means your still in game, but no CMSGs are being recieved by the server.. and you don't see any NPCs or anything being spawned.. but the server acknowledges you as being there as NPCs and items are still loaded and sending SMSGs, which they unload when all players exit the area.

Damian666 commented 7 years ago

I never said I was perfect :P

Krilliac commented 7 years ago

lol, it took about 20 minutes for the server to completely recover after a minute of cheat engine.. Server CPU Load also hanged around 40-80 % tell it was done

Threading in network classes would defiantly help

Krilliac commented 7 years ago

Stronger CPU seems to defiantly help though.. VPS is a Xeon E5-2620 v2 @ 2.1 Ghz, which took 20 min to process the speed hack... while on my computer which is a I7-7700k @ 4.8 Ghz brushed off the speed hack like it was a piece of meat being fed to a pack of hungry rottweilers

SpiceyWolf commented 7 years ago

for that you need a method of limiting packet requests (to where it starts refusing or dropping all packets that exceed a slightly more than reasonable backlog of packets limit) and for correcting the movement system its a fairly difficult system to implement, as if the client or server experiences any lag whatsoever than handling that can make timing off visually... and make a very buggy appearance... i still havent figured out fully out to approach it, best i can come up with is make speedhacking only "super slightly" useful as u get the extra step in speed every 3 or so steps... Its just not an easy system to tackle in a tile based movement system... if it were pixel based you could use "on/off" switches for movement and the server can just keep processing a speed * direction until it receives the off switch from client and just keep updating new locations to the clients that need to visually reproduce the results... similar to how movement in 3d mmos are

Damian666 commented 7 years ago

personally, I think its not that big of a deal within these kind of engines, but seeing he is used to WoW, I understand why he looks at that stuff.

lets face it, that's a whole different ball game then this :P

SpiceyWolf commented 7 years ago

its still something you have to be responsible for if u are making an online game as if someone happens to lose their personal info even if its bullshit info thats grounds for the authorities to step in and have your shit shutdown and possibly sued for it.

SpiceyWolf commented 7 years ago

Basicly if you are handling someones info, even if its fake info, you are responsible for how it ends up being used exposed and distributed unless that responsibility is explicitly waved via license/terms of use agreement. You cant just get by with oh well its a shit product anyway so you just gotta expect it not to be safe. You are still legally held accountable.

SpiceyWolf commented 7 years ago

PS the reason i just mentioned is DIRECTLY the only reason i even made a encryption system and a damn good one apart of the ArchaicSoft framework dll because im not down for being sued over someones bullshit avatar info -> And i have my own game project ive been working on that uses the framework

Krilliac commented 7 years ago

Unless i suddenly forgot how to use wireshark, that encryption system is damn good.. because wireshark isn't picking up any packets on the port 7001

SpiceyWolf commented 7 years ago

lol dont meen to make you seem a fool but no encryption can mask the EXISTENCE of a packet, and the encryption hasnt been implemented yet... i left it in there for damian to implement with the simple tools containing it as im not familiar enough with the engine to implement it quickly or properly without loads of bug testing.

SpiceyWolf commented 7 years ago

plus if you are going off of the "localhost" ip connection then you shouldnt be detecting any packets as they never leave your pc data is simply pointed to your other applicaiton

SpiceyWolf commented 7 years ago

ill go ahead and give implementing the encryption systema try though since im just chilling for the next hour

SpiceyWolf commented 7 years ago

by the way that stuff u mentioned about it not mattering earlier for the encryption since its vb.net and open source anyway... Thats the real beauty of async keypairs, in order to even use it you have to generate unique keys when u want them, simply forcing the server to generate a new unique pair when one is not prepackaged (In the case of the source it wouldnt be) then everyones game will have its own unique encryption code and ull never have people cracking that and breaking every ones game

Krilliac commented 7 years ago

On WoW i can capture packets from the client with the server running locally, but i suppose the networking there is completely different, and by keypairs, do you mean if i where to crack the encryption and decompile the client, add a function to a packet, recompile it, it won't work with the server? because that i'd imagine would make altering movement packets easy (or what ever packet that could be altered in such way)

With how much effort Blizzard puts into trying to secure their code, every single time they try, it gets cracked within a matter of days every time for the past 13 years, but i suppose it doesn't help the fact their encryption key was leaked by an employee ages ago.

SpiceyWolf commented 7 years ago

No the movement system is a problem because it relies on a trust system and it existed like that even since VB6 days because its incredibly difficult to make a game that has a smooth appearance and is speedhack safe...

But Async KeyPairs is a system of encryption where you have 2 keys... 1 key is for locking, and 1 key is for opening... its like having a box with 2 locks... one can only ever lock the box but it cant unlock it to open it back up, so you send someone that box and the key that locks it... then have them send it back... only the person containing the unlock key can EVER open it...

This makes it so even if everyone can visibly see the key that locks the information up and can do whatever they please with it itll NEVER actually help them in an endeavor to opening the information. The only remaining option is brute forcing it.

In normal encryption brute forcing you may just try to have it scan every possible key combination, but if you make an async super long, this basicly becomes a many year task EVEN for super computers that only some government is going to have access to.

SpiceyWolf commented 7 years ago

i realized i didnt elaborate too much on the movement point at first... Anyway its a trust system, the server because theres no way it can accurately predict movement time in a tile based setting, just "trusts" the client to figure out the information about movement, like when the player has finished moving to the next square and "canMove" again. The timing on movement isnt strict its based off of a inconsistent timer where it just gets some sort of time and adds that to its location currently until one of the times it adds that time it happens to be fully in the next square, visually it produces a smooth transition... But its an inconsistent transition that if you made it consistent in tile based movement rules, itd look very jaggedy and the only way you can ensure the server is going to produce proper results in determining location on its own is via a consistent movement timer.

Krilliac commented 7 years ago

AH, i see, i like this implantation of encryption then, very smart.

But lets say hypothetically, some one managed to brute force the key, would that allow them to hack away Scot free and what not? What would it mean to break such encryption in this case.

And Movement checking probably isn't exactly the best way to go about anticheats, as witnessed on 2k+ WoW PServers, the ones running with Movement anticheat patches can't hold more than 2k players.. after that the Server Time Diff (Load) rockets past 500ms, which means absolutely unplayable lag. But on retail it reports back how fast you are moving.. so if you are moving at an impossible speed, then that's reason of suspicion.

SpiceyWolf commented 7 years ago

Ok just implemented the encryption, i dont see any problems currently on my end but im not being too thorough on the bug testing of it, if theres any im sure theyll occur fast enough for someone to encounter it... the foundation of the system is definitely laid out so i meen even damian should be capable of figuring out a problem with it :D

SpiceyWolf commented 7 years ago

The issue of movement as far as that goes would really be a fault of implementation, if they have the "On/Off" switch system of movement i mentioned earlier you would have SOME form of slow down on the processes but you can expect SIGNIFICANTLY less packet spam, and set a super low packet limitation close to one youd expect to limit a chat system by to prevent spam bots... and in that case you could ensure no more performance is lost due to someone rapidly sending packets as only slightly higher than the drop off limit(Where you start dropping new packets after a certain number until all have been processed entirely before resetting to 0) only slightly higher than that you can put another limit that just says Ok by this point they are obviously spamming through meens of hacking, and then just kick or ban them. That operation to check for spam is virtually invisible as far as visible cost unless literally ur entire server is people trying to hack all at the same time xD Even then by speed hack all the cheat engine would do or something is cause it to send packets faster (whcih usually are determined by the client whether you need them or not) which on the on/off switch ur client wouldnt determine that changes are actually needed until that situation is changed, so you couldnt actually alter movement speed in a properly built -non tile based- movement system.

SpiceyWolf commented 7 years ago

Anyway, hypothetically yes it is possible for someone to EVENTUALLY brute force properly built async key pairs, however these key pairs are ONLY necessary to one specific task which is masking personal information that is transfered over the network this could include (but doesnt in current implementation of this engine of course) stuff like a in game store where credit card info may be passed or something... and login and registration info as i currently implemented... but on even the best computer anyone would have in a home even as a top of the line rig would still take a rediculous amount of time like to the point of the information no longer being relevant by the time it is cracked. Because this is information that doesnt affect what account details may be sitting in say the server database, theres nothing stopping you from simply regenning a new async keypair every server startup if you are really paranoid about it...

Another issue of trying to decrypt stuff on that magnitude is even if the content is "Decrypted" it still requires a manual check of if the information even APPEARS to be what might really be contained in the encrypted data as well as you can get stuff thats kinda close or so far apart in tests that it literally requires trial and error on every generated result for EVERY key combination out there... Even if someone does decrypt the results, its not even likely theyll know for a fact its correct as that requires human interpretation. 200+ character brute forcing is not something a human is even going to be able to sift through so im not joking when i say its not something you should be concerned about.

SpiceyWolf commented 7 years ago

Take github for example, they generate those SSH keys or whatever they call em to verify an authorized access... those are a form of Async Keypair security... thats the SAME stuff i just implemented into the engine.

Krilliac commented 7 years ago

Yeah, a packet limiter would likely solve the issues with speed hack, as well as connection based DOS attacks, which i have a program to do just that and was testing it on the server.. 1000 connections later and a little bit of lag 😁

SpiceyWolf commented 7 years ago

If damian ever swaps out the networking to the one i left inside my Framework DLL this engine is now using, the networking would be rediculously fast... like even compared to its alright speeds its getting now.

Krilliac commented 7 years ago

I understand the GitHub SSH keys, so that's actually really nice to be implemented into an engine like this.

SpiceyWolf commented 7 years ago

hell even if he only swapped out the existing buffer system to mine(as they are identicle i just dont got the patience to do all that right now) it wouldnt be hard to modify whats left to my networking and my shit is optimized to the last grain ive spent 3 years working on it xD

SpiceyWolf commented 7 years ago

cant say its impossible to crash as i dont have the help required to test that, but its super quick to implement fixes in any place it MIGHT have that, but ive done really thorough testing myself and havent been able to produce crashes for a while so meh

SpiceyWolf commented 7 years ago

Packet limiters are also an implementation in my network* already

Krilliac commented 7 years ago

Nice 👍

SpiceyWolf commented 7 years ago

lol i honestly have no idea why orion checks if a packet it is handling is the right packet in the handler xD It only got invoked cause it was already determined to be correct LOL

SpiceyWolf commented 7 years ago

oh yeah my networking even tells some pretty solid information related to why a crash may have happened and it doesnt stall before crashing that socket and moving on... unlike the ugly try catch orion implements xD

Krilliac commented 7 years ago

Hey, try catches can still be very useful lol, mainly would use them to log information though, like why function A failed or to properly dispose of the packet so it s not eating away at memory

Krilliac commented 7 years ago

the VB.Net WoW Emu i work on, uses alot of Try Catches to log information that would other wise crash the core... but instead of crashing, it prints out the function name and file directory/class and the offending line number, which has saved my ass many times when working on it.

Krilliac commented 7 years ago

https://github.com/mangosvb/serverZero/blob/master/Server/WorldServer/Server/WS.Network.vb#L402

For an example.

SpiceyWolf commented 7 years ago

Ew thats aweful, Try catches are the lazy implementation for error handling, they can be useful for debugging but should never be used in full production implementation. Anything a try catch is capable of saving is either something that could be prevented entirely by a more proper implementation anyway or will only detect the same errors you can already check for before they occur. When an error DOES occur that a try catch has to handle, its super slow because its the same thing as starting up like ruby or python or something like that to go simulate your code, detect then handle then shutdown... really its doing this any time that code runs error or not but on processing the error its just something even worse as it locks a thread while it retrieves information...

To put into perspective of how bad try catches are EVEN WITHOUT ERRORS, my own network had errors i found early on that i "fixed" with try catches. It had been losing alot of performance as a result that i didnt see till after i did something crazy that as a .net coder you might not be familiar with...

I actually added 7 other checks that basicly all could detect an error was GOING to happen that would have been caught in the try catches anyway, but these checks will occur at all times even when errors dont happen, logically you would assume that wastes alot of performance for the little it saves when a problem happens, but simply having those instead of try catches, gained back SO much extra performance, that just on the receive handler i got a 16% performance increase. This being when no errors ever happen on try catch vs the prechecked. And when an error did occur, like reproducing the error quickly on multiple sockets, the server could actually lock up for a few seconds... doing the same multicrash check with the other error handlers literally didnt even take a dent out of the performance of the server, no lockup, no slow down, just as smooth as if no problem ever occured

SpiceyWolf commented 7 years ago

Also, by prechecking you always have access to more "sub checks" which can give you significantly more detailed error information than try catches are capable of telling you.

SpiceyWolf commented 7 years ago

Also another issue especially in stuff like the receive code for example, lets say it does the invoke system that Orion does... if the crash doesnt actually happen in the network but inside the function thats processing the data that was received, like Packet_Login or something... u dont actually get enough information to know thats what caused it, you just kinda return that a error happened some time between the start of try and the end of try and any sub functions called... only way to catch it in the right place is have another try catch INSIDE the packet handler itself... like the Packet_Login function, and thats just even more wasted performance... The compiler wont optimize any code in try catches either, so on top of being emulated, its also as messy as you write it at runtime and the language cant do anything to make up for that...

SpiceyWolf commented 7 years ago

I actually decided im going through and trying to swap out the buffer system since myne is legit so freakin compatible its BARELY different in functionality so the work isnt that big...

Krilliac commented 7 years ago

Hmm.. very interesting.. now im curious to see an implantation o_o and it does make sense, the goal of MVB how ever wasn't about performance but more about learning Multi Process Clustering, with a master node for them to talk to each other with. It's estimated that it can only hold no more then 30ish players due to the Object Manager being done On The Fly with no optimization instead of Static which can hold 25k players, but by being static, we can't have clustering since we would run into issues of DB Corruption, like posting something into the Auction House for it to dissapear immediately afterword, even though you can see that it was inserted into the DB.

SpiceyWolf commented 7 years ago

Literally these days only time i use a try catch is if im using some new library that throws exceptions that im not familiar with... and ill tweak stuff on errors till i know exactly what is producing the error in the first place then go back through and add proper precheck error handlers and theres no more need for the try catch