####################################################################### Luigi Auriemma Applicazione: Empire http://www.wolfpackempire.com http://sourceforge.net/projects/empserver Versioni: <= 4.3.2 Platforms: Windows, *nix, *BSD and more Bug: crash caused by strncat misuse Exploitation: remote, versus server Date: 12 May 2006 Author: Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org ####################################################################### 1) Introduzione 2) Bug 3) The Code 4) Fix ####################################################################### =============== 1) Introduzione =============== Empire e' un war game giocabile su Internet ed e' molto conosciuto. ####################################################################### ====== 2) Bug ====== Il bug e' un crash del server causato dall'accesso ad una zona di memoria non valida. Cio' avviene a causa dell'utilizzo errato di strncat nella funzione client_cmd per aggiungere le stringhe di testo inviate dall'attacker al buffer player->client. Da lib/player/login.c: static int client_cmd(void) { int i; if (!player->argp[1]) return RET_SYN; for (i = 1; player->argp[i]; ++i) { if (i > 1) strncat(player->client, " ", sizeof(player->client) - 1); strncat(player->client, player->argp[i], sizeof(player->client) - 1); } player->client[sizeof(player->client) - 1] = '\0'; pr_id(player, C_CMDOK, "talking to %s\n", player->client); return RET_OK; } ####################################################################### =========== 3) The Code =========== http://aluigi.org/poc/empiredos.zip ####################################################################### ====== 4) Fix ====== Il CVS corrente e' stato corretto. In ogni caso di seguito c'e' il diff creato dagli sviluppatori: --- login.c.~1.37.~ 2006-04-26 20:50:40.000000000 +0200 +++ login.c 2006-05-09 08:36:04.000000000 +0200 @@ -133,17 +133,23 @@ player_login(void *ud) static int client_cmd(void) { - int i; + int i, sz; + char *p, *end; if (!player->argp[1]) return RET_SYN; + p = player->client; + end = player->client + sizeof(player->client) - 1; for (i = 1; player->argp[i]; ++i) { if (i > 1) - strncat(player->client, " ", sizeof(player->client) - 1); - strncat(player->client, player->argp[i], sizeof(player->client) - 1); + *p++ = ' '; + sz = strlen(player->argp[i]); + sz = MIN(sz, end - p); + memcpy(p, player->argp[i], sz); + p += sz; } - player->client[sizeof(player->client) - 1] = '\0'; + *p = 0; pr_id(player, C_CMDOK, "talking to %s\n", player->client); return RET_OK; } #######################################################################