[Release]Proxy / PacketSniffer

09/05/2011 00:06 GrandSlam#1
Ok well here is a little project I have been working on. It does what it needs to do. This is for anyone who is into developing like packet based stuff.

This is my first project I've worked on dealing with C# and sockets from the ground up.

[Only registered and activated users can see links. Click Here To Register...]


How to use
1. Get IP of the server of you're choosing (Except DK Evolution).
2. You can either change the usual places for IP's to 127.0.0.1:7880 or IP of you're choosing and ports 50005 for the game server.
3. Use a dll to redirect the connect function to 127.0.0.1 or IP of you're choosing for the authentication.
4. In the Config.ini the ExternalIP is the Server IP, and the ProxyIP is the IP for the client to connect to.

Bugs:
  • Packets does not send properly, Even though I encrypt it. (I cannot figure out why)
If you find any quirks, or things that don't work well let me know.

For those looking for packet structure. (-Credits- Nebular)
Code:
0 - Packet CRC (calculated/checked by upon encryption/decryption)
4 - Number (starts from 0; synchronization,GG’s CSA are not counted)
6 - Size (header+data => 16bytes minimum )
8 - Timestamp (used to distinguish between requests/responces in some commnads)
12 - Command (Describes what action to take)
16 - Data (optional; varies in size and not all areas of it are always used)
I believe the problem with sending a packet to either Server or Client is because of the first 4 bytes which is the crc, the Packet counter, and the Timestamp which I have no idea how to handle or even go about. I've read stuff based on Environment.Tick for a timestamp but yeaaaaa. I'm stuck on that part.


If anyone knows how to send a packet correctly PM me
If you have ideas on bigger packet based projects or would like to help me out My MSN is [Only registered and activated users can see links. Click Here To Register...]


UPDATE:
I have fixed the reconnection issue. You can now log out, log in, change character without the proxy crashing etc. I have taken out Send functionality till I can resolve that issue DCing when sending a packet to either Server or Client.
09/05/2011 01:04 Zektor#2
Why don't you catch the exception to find out why it's crashing?
09/05/2011 01:09 GrandSlam#3
Quote:
Originally Posted by Zektor View Post
Why don't you catch the exception to find out why it's crashing?
I have exception handling there, but it just crashes no matter what. I'll probably just log it to a file to get around that.

EDIT: Yea it closes before the exception can be logged or displayed. Logging it to a file didn't work either, So i used SmartAssembly's Self-Diagnostic to check the programs crashes.
09/05/2011 20:11 MaGNoX#4
i'm not a player of DK but may i just ask if i can use this to bypass north american IP for the game i'm playing??
09/05/2011 23:36 Zektor#5
Quote:
Originally Posted by GrandSlam View Post
I have exception handling there, but it just crashes no matter what. I'll probably just log it to a file to get around that.

EDIT: Yea it closes before the exception can be logged or displayed. Logging it to a file didn't work either, So i used SmartAssembly's Self-Diagnostic to check the programs crashes.
Wrap the entire code section with a try{catch{}}
And show the messagebox like this
MessageBox.Show(exception.ToString());
09/06/2011 00:41 GrandSlam#6
Quote:
Originally Posted by Zektor View Post
Wrap the entire code section with a try{catch{}}
And show the messagebox like this
MessageBox.Show(exception.ToString());
Yea I found out my problem. Since I'm using a dll to redirect my connection, I forgot that I kept forcing the client to use port 7880 instead of redirecting the IP I was doing both. So I was working based on the idea that the client was connecting to 50005 while being redirected.

But I've fixed both my problems with the logging out issue.
09/13/2011 10:49 EliteDKTrader#7
CryptKey does change when you connect to any channels.
CryptKey = buffer[24] ^ buffer[28]; from handshake reply (server packet).

buffer[24] = cryptkeyLowbyte
buffer[28] = cryptkeyHigbyte

CryptKey is used to encrypt packets.

You can change the packet timestamp to 0. Server doesn't check time on packet when u send it.
09/15/2011 07:28 GrandSlam#8
Quote:
Originally Posted by EliteDKTrader View Post
CryptKey does change when you connect to any channels.
CryptKey = buffer[24] ^ buffer[28]; from handshake reply (server packet).

buffer[24] = cryptkeyLowbyte
buffer[28] = cryptkeyHigbyte

CryptKey is used to encrypt packets.

You can change the packet timestamp to 0. Server doesn't check time on packet when u send it.
Thanks, I get the crypt key no problem but the problem is still how the packet encrypts. Either I'm completely missing something, or my buffer gets messed up on the encryption or something. I'm trying to resolve it now. With a Flagbyte of 0x16, Cryptkey = 0x0F.

When I get the cryptkey from 20081 (8100200) *Handshake Reply*

and I use that, It still doesn't work.
09/15/2011 17:55 Zektor#9
You should take a look at my threads, it's just one byte in the packet that represents the XOR key (I can't remember which byte but it's in my thread)

Strings are null terminated, so if you see your name and then a bunch of random strings ignore them (they don't get parsed by the client/server).
edit:
Code:
        public static byte[] CryptBody(byte[] PacketData, int len)
        {
            if (len <= 14 || PacketData[14] == 0x00)
            {
                return PacketData;
            }
            byte[] DecryptedData = new byte[len];
            ulong key = PacketData[14];
            for (int i = 0; i < 12; i++)
            {
//We leave the checksum/timestamp alone
                DecryptedData[i] = (byte)(PacketData[i]);
            }
            for (int i = 12; i < len; i++)
            {
//XOR the value to it self 
                DecryptedData[i] = (byte)(PacketData[i] ^ key);
            }
            return DecryptedData;
        }
09/16/2011 03:05 GrandSlam#10
I got it now, Gonna post up a video soon.

Using what EliteDKTrader of getting buffer[24] and buffer[28] Gives the flagbyte and the XOR'ing that value by 0x19 gives be the crypt key for the session.

I was looking through the decryption routine and was like hmmmm let me test it out and it worked! So i can now send a packet correctly to client and server! Going to keep on testing just to make sure it doesn't weird out or so something funky before I update the thread.

So yes thank you for the help guys i REALLY appreciate it, as I am learning how to code and how everything works as I go along, and the help from ya'll have gotten me to figure it out. So thank you!

Edit: Looks like you can't send just anything to the server, like a chat packet, you can send it back to the client though, but not to the server
12/28/2015 15:05 Naniooooo#11
what im doing wrong
do i need proxy program ?



System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address (protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at (Object , EndPoint )
at A.cea78dd7300b5ee57add85aba47ea738d.cf130e3c72e649 c16b5ded18e0bec6ca8(Object , EndPoint )
at A.c3a9cd10b73bc9ab90eb81bc5421c35be..ctor(Int32 , Int32 , cffddba850fd5ad588615b8e57cbea576 )
at A.c5fe356fd1e36f2a7bc2d13bbe59f9761..ctor()
[DekaronProxy]Start Listening on 192.168.1.4
[DekaronProxy]GameIP = 51.254.211.176
[DekaronProxy]AuthPort = 50905 GamePort = 50005
[DekaronProxy]Setup Complete. Ready for Connections..
01/04/2016 15:25 ADHDKiD#12
Interesting. This may help in my strive for an Emulator of Dekaron.
02/02/2016 21:46 LogLife#13
can give me source code ?