int main(){ int op,a,indice,n; while(1){ menu(); scanf("%d", &op); getchar(); switch(op){ case 1: INSERE(); break; case 2: REMOVE(); break; case 3: IMPRIME(); break; case 4: SAIR(); default: printf("Opcao invalida!\n"); break; } } }
struct words *crea_wordlist(char *ficheros) { FILE *file; struct words *current; char cbuffer[STRING_SIZE]; char current_file[STRING_SIZE]; char *apunt; // Inicializamos current=(struct words *)malloc(sizeof(struct words)); memset(current, 0, sizeof(struct words)); wordlist_base=current; contador=0; if(!options.silent_mode) printf("*** Generating Wordlist...\r"); fflush(stdout); // Bucle de generacion de wordlist while(strlen(ficheros)) { // Separamos la lista de ficheros strncpy(current_file, ficheros, STRING_SIZE-1); apunt=(char *)strchr(current_file, ','); if(apunt!=0) *apunt='\0'; ficheros=ficheros+strlen(current_file)+1; // Abrimos el fichero if((file=fopen(current_file, "r"))==0) { IMPRIME("\n(!) FATAL: Error opening wordlist file: %s\n", current_file); exit(-1); } // Bucle por cada fichero while(!feof(file)) { // Inicializamos memset(cbuffer, 0, STRING_SIZE); // Leemos y limpiamos if(fgets(cbuffer, STRING_SIZE-1, file)==0) { if(options.debuging>4) printf("[++++] crea_wordlist() Ending the parse of file: %s\n", current_file); break; } //limpiamos limpia_url(cbuffer); //comentario if(cbuffer[0]=='#') cbuffer[0]='\0'; if(strlen(cbuffer)) { strncpy(current->word, cbuffer, STRING_SIZE-1); contador++; current->siguiente=(struct words *)malloc(sizeof(struct words)); memset(current->siguiente, 0, sizeof(struct words)); current=current->siguiente; } } fclose(file); } // Operaciones finales wordlist_final=current; elimina_dupwords(wordlist_base); if(!options.silent_mode) printf(" \r"); fflush(stdout); IMPRIME("GENERATED WORDS: %d\n", contador); if(contador>BIGWORDLIST) { IMPRIME("(!) WARNING: Wordlist is too large. This will take a long time to end.\n"); IMPRIME(" (Use mode '-w' if you want to scan anyway)\n"); if(options.exitonwarn) exit(-3); } return wordlist_base; }
struct words *crea_wordlist_fich(char *fichero) { FILE *file; char cbuffer[STRING_SIZE]; struct words *ecurrent; struct words *ebase; // Inicializamos ecurrent=(struct words *)malloc(sizeof(struct words)); memset(ecurrent, 0, sizeof(struct words)); memset(cbuffer, 0, STRING_SIZE); ebase=ecurrent; // Abrimos el fichero y creamos su lista if((file=fopen(fichero, "r"))==0) { IMPRIME("\n(!) FATAL: Error opening words file: %s\n", fichero); exit(-1); } while(!feof(file)) { memset(cbuffer, 0, STRING_SIZE); // Leemos y limpiamos if(fgets(cbuffer, STRING_SIZE-1, file)==0) { if(options.debuging>4) printf("[++++] crea_wordlist_fich() Ending the parse of file: %s\n", fichero); break; } limpia_url(cbuffer); // Metemos en la lista strncpy(ecurrent->word, cbuffer, STRING_SIZE-1); if(options.debuging>5) printf("[+++++] crea_wordlist_fich() ADD_WORD: %s\n", ecurrent->word); ecurrent->siguiente=(struct words *)malloc(sizeof(struct words)); ecurrent=ecurrent->siguiente; memset(ecurrent, 0, sizeof(struct words)); } elimina_dupwords(ebase); ecurrent=ebase; while(ecurrent->siguiente!=0) { if(options.debuging>5) printf("[+++++] crea_wordlist_fich() WORD: %s\n", ecurrent->word); ecurrent=ecurrent->siguiente; } fclose(file); return ebase; }
void resume(void) { FILE *desc; char *home=NULL; char *dumppath=NULL; char *optionspath=NULL; char *wordlistpath=NULL; char *dirlistpath=NULL; resuming=1; home = getenv("HOME"); asprintf(&dumppath,"%s/%s",home,DUMP_DIR); asprintf(&optionspath, "%s/%s",home,OPTIONS_DUMP); asprintf(&wordlistpath, "%s/%s",home,WORDLIST_DUMP); asprintf(&dirlistpath, "%s/%s",home,DIRLIST_DUMP); // Recuperamos la estructura options if((desc=fopen(optionspath, "r"))==0) { printf("\n(!) FATAL: Error opening input file: %s\n", optionspath); exit(-1); } fread(&options, sizeof(struct opciones), 1, desc); fclose(desc); // Inicializamos check_url(options.current_dir); get_options(); init_exts(); IMPRIME("CURRENT_BASE: %s\n", options.current_dir); IMPRIME("CURRENT_WORD: %s\n", options.current_word); IMPRIME("\n-----------------\n\n"); // Mutations /* if(options.mutations_file) { muts_base=crea_wordlist_fich(options.mutation_file); } else if(options.mutations_list) { muts_base=crea_extslist(options.mutation_list); } */ // Recuperamos la dirlist dirlist_current=crea_wordlist_fich(dirlistpath); dirlist_base=dirlist_current; while(dirlist_current->siguiente!=0) { dirlist_current=dirlist_current->siguiente; } dirlist_final=dirlist_current; dirlist_current=dirlist_base; // Recuperamos la wordlist wordlist_current=crea_wordlist_fich(wordlistpath); wordlist_base=wordlist_current; while(wordlist_current->siguiente!=0) { wordlist_current=wordlist_current->siguiente; } wordlist_final=wordlist_current; wordlist_current=wordlist_base; while(wordlist_current->siguiente!=0 && strncmp(wordlist_current->word, options.current_word, STRING_SIZE-1)!=0) { wordlist_current=wordlist_current->siguiente; } // Avanzamos la wordlist en 1 wordlist_current=wordlist_current->siguiente; // Relanzamos el scan lanza_ataque(options.current_dir, wordlist_current); // Finalizamos cierre(); exit(0); }
int main(int argc, char **argv) { struct words *palabras; int c=0; banner(); // Inicializaciones globales memset(&options, 0, sizeof(struct opciones)); options.exitonwarn=1; options.ignore_nec=0; options.default_nec=404; options.lasting_bar=1; options.speed=0; options.add_header=0; encontradas=0; descargadas=0; listable=0; exts_num=0; strncpy(options.agente, AGENT_STRING, STRING_SIZE-1); dirlist_current=(struct words *)malloc(sizeof(struct words)); memset(dirlist_current, 0, sizeof(struct words)); dirlist_base=dirlist_current; dirlist_final=dirlist_current; curl=curl_easy_init(); // Recepcion de parametros if(argc<2) { ayuda(); exit(-1); } if(strncmp(argv[1], "-resume", 7)==0) { printf("(!) RESUMING...\n\n"); resume(); } strncpy(options.url_inicial, argv[1], STRING_SIZE-1); if(argc==2 || strncmp(argv[2], "-", 1)==0) { strncpy(options.mfile, DEFAULT_WORDLIST, STRING_SIZE-1); optind+=1; } else { strncpy(options.mfile, argv[2], STRING_SIZE-1); optind+=2; } while((c = getopt(argc,argv,"a:c:d:fgh:H:ilm:M:n:N:o:p:P:rRsSvwx:X:u:tz:"))!= -1){ switch(c) { case 'a': options.use_agent=1; strncpy(options.agente, optarg, STRING_SIZE-1); break; case 'c': options.use_cookie=1; strncpy(options.cookie, optarg, STRING_SIZE-1); break; case 'd': options.debuging=atoi(optarg); break; case 'f': options.finetunning=1; break; case 'g': options.save_found=1; break; case 'h': options.use_vhost=1; strncpy(options.vhost, optarg, STRING_SIZE-1); break; case 'H': if(options.add_header) { strcat(options.header_string, "\n"); strncat(options.header_string, optarg, STRING_SIZE-strlen(options.header_string)-2); } else { strncpy(options.header_string, optarg, STRING_SIZE-1); } options.add_header++; break; case 'i': options.insensitive=1; break; case 'l': options.print_location=1; break; case 'm': options.mutations_file=1; strncpy(options.mutation_file, optarg, STRING_SIZE-1); break; case 'M': options.mutations_list=1; strncpy(options.mutation_list, optarg, STRING_SIZE-1); break; case 'N': options.ignore_nec=atoi(optarg); break; case 'o': options.saveoutput=1; strncpy(options.savefile, optarg, STRING_SIZE-1); break; case 'p': options.use_proxy=1; strncpy(options.proxy, optarg, STRING_SIZE-1); break; case 'P': options.use_proxypass=1; strncpy(options.proxypass_string, optarg, STRING_SIZE-1); break; case 'r': options.dont_recurse=1; break; case 'R': options.interactive=1; break; case 's': options.verify_ssl=1; break; case 'S': options.silent_mode=1; break; case 't': options.lasting_bar=0; break; case 'u': options.use_pass=1; strncpy(options.pass_string, optarg, STRING_SIZE-1); break; case 'v': options.nothide=1; break; case 'w': options.exitonwarn=0; break; case 'x': options.extensions_file=1; strncpy(options.exts_file, optarg, STRING_SIZE-1); break; case 'X': options.extensions_list=1; strncpy(options.exts_list, optarg, STRING_SIZE-1); break; case 'z': options.speed=(atoi(optarg)<=0)?0:atoi(optarg); break; default: printf("\n(!) FATAL: Incorrect parameter\n"); exit(-1); break; } } // Limpia el input limpia_url(options.url_inicial); if(options.lasting_bar && !strchr(options.url_inicial, '?')) barra(options.url_inicial); check_url(options.url_inicial); limpia_url(options.mfile); // Chequeos iniciales get_options(); init_exts(); IMPRIME("\n-----------------\n\n"); // Creamos la lista de palabras palabras=crea_wordlist(options.mfile); // Abrimos el fichero de mutations y creamos la lista /* if(options.mutations_file) { muts_base=crea_wordlist_fich(options.mutation_file); } else if(options.mutations_list) { muts_base=crea_extslist(options.mutation_list); } */ // Lanzamos el bucle de descarga lanza_ataque(options.url_inicial, palabras); // Finalizamos cierre(); exit(0); }