For many of you packet hackers around here I noticed many are slightly modifying captured packets and resending them. Which usually results in getting disconnected. The majority of the time it's due to not including the new checksum of the packet, the other time it's because the packet wasn't encrypted.
To create a packet checksum, you must first be familiar with the structure of a basic 9Dragons packet. A sample packet looks like the following:
The first byte of every packet is the size or length of the data. In this case it's 12 bytes long. Many people mistake this thinking the first byte is the packet id. The second byte is an identifier which tells us if the packet is encrypted or not. Have you seen 0x10 here before? That means the data was encrypted. The rest of the packet is our data, except the last 2 bytes.
So what are the last 2 bytes? You've probably guessed it already, that's the checksum. How do you create a checksum? The first step is creating a byte array with a size big enough to hold the checksum. You would do it like the following using our packet from before:
In C#:
In VB:
To create the checksum, we need to iterate through the byte array and increment on each byte + the sum of the previous byte. Since there is no previous byte on the first run, you start with 0x0. Here is the function I use to create a checksum:
In C#:
In VB:
And I suppose you thought this was going to be difficult. As you can see what we did here was just as stated above, and then at the end of the code we add the checksum to the end of byte array. The checksum will take 2 bytes, so we insert it at buffer[0] - 2 (remember offset 0 = the size of the packet?) With a basic function to create valid checksums you'll have far greater success in sending modified packets that the server will try to do something with instead of booting you off the server!
I posted the function as simple as possible, for those of you who are using a different programming language it should be easy for you to translate it accordingly.
To create a packet checksum, you must first be familiar with the structure of a basic 9Dragons packet. A sample packet looks like the following:
Code:
0C 00 62 02 1D 73 04 0A 01 00 F5 D3
So what are the last 2 bytes? You've probably guessed it already, that's the checksum. How do you create a checksum? The first step is creating a byte array with a size big enough to hold the checksum. You would do it like the following using our packet from before:
In C#:
Code:
byte[] packet = new byte[] { 0x0C, 0, 0x62, 2, 0x1D, 0x73, 4, 0x0A, 1, 0, 0, 0 };
Code:
Dim buffer As Byte() = New Byte() { &H0C, 0, &H62, 2, &H1D, &H73, 4, &H0A, 1, 0, 0, 0 }
In C#:
Code:
public static void CreateCheckSum(byte[] buffer)
{
if (buffer != null)
{
byte num = 0;
for (int i = 0; i < (buffer[0] - 2); i++)
{
num = (byte) (num + buffer[i]);
}
buffer[buffer[0] - 2] = (byte) (1 - num);
}
}
Code:
Public Shared Sub CreateCheckSum(ByVal buffer As Byte())
If (Not buffer Is Nothing) Then
Dim num As Byte = 0
Dim i As Integer
For i = 0 To (buffer(0) - 2) - 1
num = CByte((num + buffer(i)))
Next i
buffer((buffer(0) - 2)) = CByte((1 - num))
End If
End Sub
I posted the function as simple as possible, for those of you who are using a different programming language it should be easy for you to translate it accordingly.