openkore icon indicating copy to clipboard operation
openkore copied to clipboard

How to mod the package manually in order to login to a private server?

Open simonpunk opened this issue 9 years ago • 10 comments

Hello, everyone, and developers. I am now trying to run openkore on a private server. And I know there are many configs need to be changed to apply on a custom server, and actually I have modified some of the source code to get me succeed to the character login page, but after loading to the mad,I encountered this issue.

In a correct sequence of exchanging packages start from the character login page, it should be like this: (captured by wireshark)

me >> server : a package of len = 3 server >> me: a package of len = 28 me >> server: a package of len = 19 (here I have modified the first two byte to another, the origin send to server is "0x72 0x00") server >> me: a package of len = 6 server >> me: a package of len = 40 (I think this is a welcome message?) server >> me: a package of len = 208 (below is actually where my error package send to server, just mark it as the key point here first) me >> server: a package of len = 6 (0xb2 0xXX 0x89 0xXX 0x4a 0xXX) me >> server: a package of len = 2 (0x04 0xXX) server >> me: a package of len > 1000 me >> server: a package of len = 28 server >> me: a package of len > 1400 server >> me: a package of len > 280 me >> server: a package of len = 2 (0xe1 0xXX) (-----after that it starts to send a sync package to server-----) me >> server: a package of len = 6 (0x09 0x00, gettickcount)

So, above is the correct sequence.

Now, in my case, start from key point, it is like this:

me >> server: a package of len = 2 (which are "0x4d 0x01") server >> me: a package of len = 14 (which probably a error message)

then I got the error message from terminal "Disconnected from Map Server, connecting to Account Server in 30 seconds..."

from this point, I can't find which of the function is responsible for that package, as I need to make it send two packages with the len of 6 and 2 respectively instead of one package.

Can anyone here help me out of this issue?? if you need a cap file I can pm you by email. Thanks.

simonpunk avatar Feb 06 '17 08:02 simonpunk

me >> server: a package of len = 2 (which are "0x4d 0x01")

So we can grep for 014d (or for 4d and filter with 01 if that fails) and find out that it's guild_check packet and there is sendGuildMasterMemberCheck function which sends the packet. Looking for that function name yields some calls in different serverTypes (pick ones you use) and in Receive.pm/Send.pm (common base for everything).

You can try to tweak things there, it's not clear what's wrong without knowing exact serverType and content of 0xXX packets.

farrainbow avatar Feb 07 '17 07:02 farrainbow

Hi, @farrainbow , Big thanks for your advise. But let me answer your question first. the target serverType is twRO, and I changed the info of theserver "Free (Moonlight, Baphomet, Poring)" to my target private server, and luckily it doesn't encrypt my password when logging to the server. And the reason I used '0xXX' is just because I though it was not good to disclose the whole server info...

after a few more hours, I just realized that my openkore doesnt shuffle the packet every time it sends, so I end up downloading the a mod openkore exclusive for twRO official server from github: openkoreTW and it has shuffle function. But now I get stuck again, when I get to step "map_login" after I choose the character, the first two bytes it sends are encrypted by 3 keys defined at "key.txt", originally it is "0072" by default if it is not encrypted.

I also downloaded a latest packet_extractor from the same github, but still no luck to extract the keys.

if you will to help to give a try, here is the link of that client patch: private_server_patch

simonpunk avatar Feb 10 '17 18:02 simonpunk

@farrainbow , hi!!! What a great news!!! I actually found out the parttern!!!!!! I use IDA pro to reserve the exe and look for the text "0x7FFF" and there is one line saying "and eax, 0x7FFF", and I saw a window contains 3 Dword integer which seem to be the crpty_keys, and it just slightly change the crypt pattern to crypt_key = ((crypt_key[1] * crypt_key + crypt_key[2]) & 0xFFFFFFFF), and then I just wrote a simple python script to reverse how many times of shuffle when the first sync packet send to server!! and I got the original sync packet number is 0x035f!! now I just need to figure out the rest of packet no using stupid method. Also, I noticed that it actually shuffles the crypt_keys 10 times before it sends the first packet to server after loading to the map.

Anyway, thanks for your help, but maybe I still need more time to mod the openkore as I don't know where the shuffle function actually is as I want to make it start shuffling just after login to the map.

simonpunk avatar Feb 13 '17 11:02 simonpunk

@simonpunk can you share your phyton script and the method to find the custom packet key ? i really need it since the private server i played use the custom packet key T_T thank you :D

Razalka avatar Mar 07 '17 01:03 Razalka

@Razalka it would be useless if your server didn't use the same encrypt method as the TWRO server, then my script will not work definitely. If you manage to load into the map and fail at receiving the first sync packet the server sends to you, then you will need to check whether the first two byte of the packet you receive are the same in the Receive/ServerType0.pm. If not, all the packets from the server is likely encrypted by the shuffle method, then at this time, you may need to reverse the exe and try to locate the function which does the encrypt part, and then find out the encrypt keys, after that, the rest of all would be just a piece of cake.

P.S. just use wireshark to capture the packet, and try logging to the game again and again to just find out the packet pattern, for example, when you move, what's the first two byte of the packet the server sends to you? if every time you move and the first two byte of the packet you receive is not always the same, then you can say it uses the shuffle function as well. If not, things can be done much easier, some times they may just swap all the packets code to another, e.g. 006D in kRO stands for moving, but the server just changes it to another for example 007E, and so on. Thats why you have to check over and over again to find out the pattern.....

simonpunk avatar Mar 09 '17 13:03 simonpunk

@simonpunk The owner of the ragnarok challange me to botting in their server. Heres the website ro.rakki.org They use custom version and cryptkey. I found the version from wpe with reverse hex packet. And successfully logged into the server, but rejected in the map server because the custom cryptkey was wrong. All server config was done right, the GM verified itself, and they said i juts have to find the custom cryptkey. And the packet, grf was encrypted too.. But i cant find any method to find the custom cryptkey, except from the PEEK, but its a default cryptkey. Would you teach me to find it? Thanks before and sorry for being noob and my bad english.

Razalka avatar Mar 09 '17 15:03 Razalka

@Razalka, I know the OK developer has created a tutorial page of how to extract the recvpacket.txt for private server, but nowadays most of the server has its own encryption method, thats why PEEK always not working with them, in other words, you may need to conduct a reverse engineering to that client exe and look for the encrypt keys or something else useful. In my though, most of private server may just change to different encrypt_keys instead of shuffling all the packet numbers, but sometimes they dont use encrypt keys at all, they just make a pin code verification after you have logged into the map server. However, I am not a pro or programmer, I just figure it out by luck and all credits to google.

Anyway, I will give a try to reverse your client exe as I just want to proof it works the same ways as I though.

P.S. Still its not easy to avoid begin caught by GMs, I have got caught already, the most ideal way is to use a vpn connection to test or play on that server, just in case they block your real ip.

simonpunk avatar Mar 10 '17 10:03 simonpunk

@simonpunk Yeaa you right, by now most of private server change the default into the custom, worth method to prevent the botters.

Thank you for helping me :D

Anyway, maybe this can help if you want to try to connect.

Port 6900 Version 29061990 Master_Version 55 Addtabble (latest one) clientHash (must be include this, or the server reject)

Once again, thanks for helping :D

Razalka avatar Mar 10 '17 10:03 Razalka

@simonpunk Sorry, wrong version. This the right one. Version 26061990

Razalka avatar Mar 10 '17 10:03 Razalka

@Razalka Do you have a modded openkore exclusive for idRO which has the shuffle function code inside? cause in my case I used another modded openkore exclusive for TWRO which the author has add the shuffle function and at that time I just need to find out the different encrypt_key.

I have just took a look at your client exe, I think it is a totally different from my TWRO server, and seems it is much harder and complicated than I thought, if you have someone created a modded openkore for a official idRO already, then it would be better to help to find out the crypte_key and its pattern. Now seems it's too hard for me to do it. Sorry.

simonpunk avatar Mar 11 '17 13:03 simonpunk