[Tutorial] Debugging common script errors, crashes, and exploits.
#1

A brief tutorial on debugging:

This tutorial basically aims to help scripters debug script issues, exploits, and crashes. This is not a full, long, and extremely detailed tutorial however I hope it will help a bit.

Debugging Server-Related Crashes(using crashdetect):

Client-Sided:
Sometimes a player can crash due to a fault in the script. This is when crashdetect can provide information to the server about the client crashing. Note that this won't report crashes if it's due to a client's game, and or related to them specifically(and not the server).

Server-Sided:

Commonly, scripters make the smallest mistake which ends up making their whole server crash. This can be due to a missing folder / file / directory, faulty code, and more.

Using crashdetect:
Crashdetect is very simple to use. The first thing you need to do is download it from the release thread. Thereafter, you'll need to copy the pawno + plugins directories into your server folder.

After that, you'll need to open your gamemode script(or whatever script you are aiming to fix / debug / get crash information) from. You'll simply need to include crashdetect as seen below,
pawn Code:
#include <crashdetect>
Obviously, you'll need to recompile for it to take effect. Then you need to include the crashdetect plugin(before everything else) inside server.cfg.

Then start your server, and you should get runtime and crash errors.

Debugging (forced) crashes / exploits:

Exploits / crashers can be hard to debug, and fix sometimes. It really helps if you have access to the exploit's / crashers source code and or understand how it works.

You'll want to debug related / common callbacks / functions to look for irregular patterns. An example is the bullet crasher.

After debugging OnPlayerWeaponShot, IstuntmanI found the following data:
pawn Code:
OnPlayerWeaponShot(0,0,1,0,2004318080.000000,2004318080.000000,2004318080.000000)
As you can see the data is very abnormal / irregular. The fX is 2004318080, that is impossible without modifications.

Since he had that data, he was able to fix it with the following code:
pawn Code:
public OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ )
{
    if( hittype != BULLET_HIT_TYPE_NONE ) // Bullet Crashing uses just this hittype
    {
        if( !( -1000.0 <= fX <= 1000.0 ) || !( -1000.0 <= fY <= 1000.0 ) || !( -1000.0 <= fZ <= 1000.0 ) ) // a valid offset, it's impossible that a offset bigger than 1000 is legit (also less than -1000.0 is impossible, not used by this hack, but still, let's check for it, just for the future, who knows what hacks will appear). The object with biggest offset is having ~700-800 radius.
        {
            /*
                If you want, here you can kick the cheater
            */

            return 0; // let's desynchronize that bullet, so players won't crash
        }
    }
    return 1;
}
He probably did something like this to get the original data:
pawn Code:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float: fX, Float: fY, Float: fZ)
{
         printf("OnPlayerWeaponShot(%d,%d,%d,%d,%f,%f,%f)", playerid, weaponid, hittype, hitid, fX, fY, fZ);
         return 1;
}
From that small amount of code he was able to fix the bullet crasher. That's all it took! Now, let's take apart the patch he provided.

His patch starts with using the callback he originally did the debugging on. This isn't always the case, but since the bullet crasher only uses shootable weapons 0 can be returned in this callback desyncing the shots from the server.


Debugging the "file or function not found" run-time error:

Similar to debugging crashes, we need to use a plugin. We can use nativechecker made by Zeex to find what file or function is missing. We simply download the plugin, and put it after every other plugin inside server.cfg, and when you start the server it'll give useful information.

Debugging possible server exploits and or failures

Q: My server randomly froze and when I join it says "Connected. Joining the game" but after about a minute the server closes the connection. Is this an attack?

A: This is not an attack, this is usually an issue caused when the script accidentally creates a infinite loop. An infinite loop is as the name of it suggests a never ending loop.

Let's take an example while loop:
pawn Code:
new i;
while(i != 1)
{
      i = 0;
}
This will never end because the i variable will never be 1. This causes the server to freeze where it can't process anything else because it's stuck processing the loop which NEVER ENDS.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)