| 1 |
/* |
| 2 |
* DIRB |
| 3 |
* |
| 4 |
* crea_wordlist.c - Crea la lista de palabras a probar |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include "dirb.h" |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
* CREA_WORDLIST: Crea la lista de palabras a probar a partir de un fichero |
| 14 |
* |
| 15 |
*/ |
| 16 |
|
| 17 |
struct words *crea_wordlist(char *ficheros) { |
| 18 |
FILE *file; |
| 19 |
struct words *current; |
| 20 |
char cbuffer[STRING_SIZE]; |
| 21 |
char current_file[STRING_SIZE]; |
| 22 |
char *apunt; |
| 23 |
|
| 24 |
|
| 25 |
// Inicializamos |
| 26 |
|
| 27 |
current=(struct words *)malloc(sizeof(struct words)); |
| 28 |
memset(current, 0, sizeof(struct words)); |
| 29 |
wordlist_base=current; |
| 30 |
contador=0; |
| 31 |
|
| 32 |
if(!options.silent_mode) printf("*** Generating Wordlist...\r"); |
| 33 |
fflush(stdout); |
| 34 |
|
| 35 |
|
| 36 |
// Bucle de generacion de wordlist |
| 37 |
|
| 38 |
while(strlen(ficheros)) { |
| 39 |
|
| 40 |
// Separamos la lista de ficheros |
| 41 |
|
| 42 |
strncpy(current_file, ficheros, STRING_SIZE-1); |
| 43 |
|
| 44 |
apunt=(char *)strchr(current_file, ','); |
| 45 |
|
| 46 |
if(apunt!=0) *apunt='\0'; |
| 47 |
|
| 48 |
ficheros=ficheros+strlen(current_file)+1; |
| 49 |
|
| 50 |
// Abrimos el fichero |
| 51 |
|
| 52 |
if((file=fopen(current_file, "r"))==0) { |
| 53 |
IMPRIME("\n(!) FATAL: Error opening wordlist file: %s\n", current_file); |
| 54 |
exit(-1); |
| 55 |
} |
| 56 |
|
| 57 |
// Bucle por cada fichero |
| 58 |
|
| 59 |
while(!feof(file)) { |
| 60 |
|
| 61 |
// Inicializamos |
| 62 |
|
| 63 |
memset(cbuffer, 0, STRING_SIZE); |
| 64 |
|
| 65 |
|
| 66 |
// Leemos y limpiamos |
| 67 |
|
| 68 |
if(fgets(cbuffer, STRING_SIZE-1, file)==0) { |
| 69 |
if(options.debuging>4) printf("[++++] crea_wordlist() Ending the parse of file: %s\n", current_file); |
| 70 |
break; |
| 71 |
} |
| 72 |
|
| 73 |
//limpiamos |
| 74 |
limpia_url(cbuffer); |
| 75 |
|
| 76 |
//comentario |
| 77 |
if(cbuffer[0]=='#') cbuffer[0]='\0'; |
| 78 |
|
| 79 |
if(strlen(cbuffer)) { |
| 80 |
strncpy(current->word, cbuffer, STRING_SIZE-1); |
| 81 |
contador++; |
| 82 |
current->siguiente=(struct words *)malloc(sizeof(struct words)); |
| 83 |
memset(current->siguiente, 0, sizeof(struct words)); |
| 84 |
current=current->siguiente; |
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
fclose(file); |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
// Operaciones finales |
| 95 |
|
| 96 |
wordlist_final=current; |
| 97 |
|
| 98 |
elimina_dupwords(wordlist_base); |
| 99 |
|
| 100 |
if(!options.silent_mode) printf(" \r"); |
| 101 |
fflush(stdout); |
| 102 |
IMPRIME("GENERATED WORDS: %d\n", contador); |
| 103 |
|
| 104 |
if(contador>BIGWORDLIST) { |
| 105 |
IMPRIME("(!) WARNING: Wordlist is too large. This will take a long time to end.\n"); |
| 106 |
IMPRIME(" (Use mode '-w' if you want to scan anyway)\n"); |
| 107 |
if(options.exitonwarn) exit(-3); |
| 108 |
} |
| 109 |
|
| 110 |
return wordlist_base; |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
/* |
| 116 |
* crea_wordlist_fich: Crea una lista de palabras a partir de un fichero |
| 117 |
* |
| 118 |
*/ |
| 119 |
|
| 120 |
struct words *crea_wordlist_fich(char *fichero) { |
| 121 |
FILE *file; |
| 122 |
char cbuffer[STRING_SIZE]; |
| 123 |
struct words *ecurrent; |
| 124 |
struct words *ebase; |
| 125 |
|
| 126 |
|
| 127 |
// Inicializamos |
| 128 |
|
| 129 |
ecurrent=(struct words *)malloc(sizeof(struct words)); |
| 130 |
memset(ecurrent, 0, sizeof(struct words)); |
| 131 |
memset(cbuffer, 0, STRING_SIZE); |
| 132 |
ebase=ecurrent; |
| 133 |
|
| 134 |
|
| 135 |
// Abrimos el fichero y creamos su lista |
| 136 |
|
| 137 |
if((file=fopen(fichero, "r"))==0) { |
| 138 |
IMPRIME("\n(!) FATAL: Error opening words file: %s\n", fichero); |
| 139 |
exit(-1); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
while(!feof(file)) { |
| 144 |
|
| 145 |
memset(cbuffer, 0, STRING_SIZE); |
| 146 |
|
| 147 |
// Leemos y limpiamos |
| 148 |
|
| 149 |
if(fgets(cbuffer, STRING_SIZE-1, file)==0) { |
| 150 |
if(options.debuging>4) printf("[++++] crea_wordlist_fich() Ending the parse of file: %s\n", fichero); |
| 151 |
break; |
| 152 |
} |
| 153 |
|
| 154 |
limpia_url(cbuffer); |
| 155 |
|
| 156 |
// Metemos en la lista |
| 157 |
|
| 158 |
strncpy(ecurrent->word, cbuffer, STRING_SIZE-1); |
| 159 |
|
| 160 |
if(options.debuging>5) printf("[+++++] crea_wordlist_fich() ADD_WORD: %s\n", ecurrent->word); |
| 161 |
|
| 162 |
ecurrent->siguiente=(struct words *)malloc(sizeof(struct words)); |
| 163 |
ecurrent=ecurrent->siguiente; |
| 164 |
memset(ecurrent, 0, sizeof(struct words)); |
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
elimina_dupwords(ebase); |
| 169 |
|
| 170 |
ecurrent=ebase; |
| 171 |
|
| 172 |
while(ecurrent->siguiente!=0) { |
| 173 |
if(options.debuging>5) printf("[+++++] crea_wordlist_fich() WORD: %s\n", ecurrent->word); |
| 174 |
ecurrent=ecurrent->siguiente; |
| 175 |
} |
| 176 |
|
| 177 |
fclose(file); |
| 178 |
|
| 179 |
return ebase; |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
/* |
| 186 |
* CREA_EXTSLIST: Crea la lista de extensiones |
| 187 |
* |
| 188 |
*/ |
| 189 |
|
| 190 |
struct words *crea_extslist(char *lista) { |
| 191 |
char cbuffer[STRING_SIZE]; |
| 192 |
struct words *ecurrent; |
| 193 |
struct words *ebase; |
| 194 |
char *apunt; |
| 195 |
|
| 196 |
|
| 197 |
// Inicializamos |
| 198 |
|
| 199 |
ecurrent=(struct words *)malloc(sizeof(struct words)); |
| 200 |
memset(ecurrent, 0, sizeof(struct words)); |
| 201 |
memset(cbuffer, 0, STRING_SIZE); |
| 202 |
ebase=ecurrent; |
| 203 |
|
| 204 |
|
| 205 |
while(strlen(lista)) { |
| 206 |
|
| 207 |
// Separamos la lista de extensiones |
| 208 |
|
| 209 |
strncpy(cbuffer, lista, STRING_SIZE-1); |
| 210 |
|
| 211 |
apunt=(char *)strchr(cbuffer, ','); |
| 212 |
|
| 213 |
if(apunt!=0) *apunt='\0'; |
| 214 |
|
| 215 |
lista=lista+strlen(cbuffer)+1; |
| 216 |
|
| 217 |
// Metemos en la lista |
| 218 |
|
| 219 |
strncpy(ecurrent->word, cbuffer, STRING_SIZE-1); |
| 220 |
|
| 221 |
if(options.debuging>5) printf("[+++++] crea_extslist() EXT: %s\n", ecurrent->word); |
| 222 |
|
| 223 |
ecurrent->siguiente=(struct words *)malloc(sizeof(struct words)); |
| 224 |
ecurrent=ecurrent->siguiente; |
| 225 |
memset(ecurrent, 0, sizeof(struct words)); |
| 226 |
|
| 227 |
} |
| 228 |
|
| 229 |
elimina_dupwords(ebase); |
| 230 |
|
| 231 |
ecurrent=ebase; |
| 232 |
|
| 233 |
while(ecurrent->siguiente!=0) { |
| 234 |
if(options.debuging>5) printf("[+++++] crea_extslist() EXT: %s\n", ecurrent->word); |
| 235 |
ecurrent=ecurrent->siguiente; |
| 236 |
} |
| 237 |
|
| 238 |
return ebase; |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
/* |
| 243 |
* COUNT_WORDS: Cuenta las palabras de una wordlist |
| 244 |
* |
| 245 |
*/ |
| 246 |
|
| 247 |
int count_words(struct words *list) { |
| 248 |
int count=0; |
| 249 |
struct words *ptr; |
| 250 |
|
| 251 |
ptr=list; |
| 252 |
|
| 253 |
while(ptr->siguiente!=0) { |
| 254 |
count++; |
| 255 |
ptr=ptr->siguiente; |
| 256 |
} |
| 257 |
|
| 258 |
return count; |
| 259 |
|
| 260 |
} |
| 261 |
|