| 1 |
/* |
| 2 |
* DIRB |
| 3 |
* |
| 4 |
* calculanec.c - Obtiene el codigo NEC |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "dirb.h" |
| 9 |
#include "http_codes.h" |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
* GET_NECS: Obtienes los NECs correspondientes a cada extension |
| 14 |
* |
| 15 |
*/ |
| 16 |
|
| 17 |
int get_necs(char *direccion){ |
| 18 |
char initial_url[STRING_SIZE]; |
| 19 |
int exts_pos=0; |
| 20 |
int necs=0; |
| 21 |
|
| 22 |
|
| 23 |
if(!options.silent_mode) printf("*** Calculating NOT_FOUND code...\r"); |
| 24 |
fflush(stdout); |
| 25 |
|
| 26 |
// Inicializamos |
| 27 |
|
| 28 |
memset(initial_url, 0, STRING_SIZE); |
| 29 |
|
| 30 |
exts_current=exts_base; |
| 31 |
|
| 32 |
strncpy(initial_url, direccion, STRING_SIZE-1); |
| 33 |
|
| 34 |
|
| 35 |
// Bucle |
| 36 |
|
| 37 |
for(exts_pos=0;exts_pos<exts_num;exts_pos++) { |
| 38 |
|
| 39 |
nec[exts_pos]=calcula_nec(initial_url); |
| 40 |
|
| 41 |
if(options.debuging>1) printf("[+] calcula_nec() NEC[%s]: %d -> %s\n", exts_current->word, nec[exts_pos]->codigo_http, code2string(code2message, nec[exts_pos]->codigo_http)); |
| 42 |
|
| 43 |
if(options.debuging>1) printf("[+] calcula_nec() (Size: %d - Location: '%s')\n", nec[exts_pos]->body_size, nec[exts_pos]->location); |
| 44 |
|
| 45 |
if(options.debuging>1) printf("[+] calcula_nec() SERVER_BANNER[%s]: %s\n", exts_current->word, nec[exts_pos]->server); |
| 46 |
|
| 47 |
exts_current=exts_current->siguiente; |
| 48 |
|
| 49 |
necs++; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
exts_current=exts_base; |
| 54 |
|
| 55 |
if(!options.silent_mode) printf(" \r"); |
| 56 |
fflush(stdout); |
| 57 |
|
| 58 |
return necs; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
/* |
| 64 |
* CALCULA_NEC: Obtiene el codigo de pagina no existente |
| 65 |
* |
| 66 |
*/ |
| 67 |
|
| 68 |
struct result *calcula_nec(char *direccion) { |
| 69 |
struct result nec1, nec2; |
| 70 |
struct result *mynec; |
| 71 |
char url[STRING_SIZE]; |
| 72 |
char rand_url1[STRING_SIZE]="randomfile1"; |
| 73 |
char rand_url2[STRING_SIZE]="frand2"; |
| 74 |
|
| 75 |
// Inicializamos |
| 76 |
|
| 77 |
mynec=malloc(sizeof(struct result)); |
| 78 |
memset(mynec, 0, sizeof(struct result)); |
| 79 |
|
| 80 |
memset(&nec1, 0, sizeof(struct result)); |
| 81 |
memset(&nec2, 0, sizeof(struct result)); |
| 82 |
|
| 83 |
|
| 84 |
// Calculo del primer NEC |
| 85 |
|
| 86 |
memset(url, 0, STRING_SIZE); |
| 87 |
strncpy(url, direccion, STRING_SIZE-1); |
| 88 |
|
| 89 |
strncat(rand_url1, exts_current->word, STRING_SIZE-1-strlen(rand_url1)); |
| 90 |
strncat(url, rand_url1, STRING_SIZE-1-strlen(url)); |
| 91 |
|
| 92 |
nec1=get_url(url); |
| 93 |
|
| 94 |
if(options.debuging>2) printf("[++] calcula_nec() NEC1: %d\n", nec1.codigo_http); |
| 95 |
|
| 96 |
|
| 97 |
switch(nec1.codigo_http) { |
| 98 |
|
| 99 |
case 200: |
| 100 |
if(options.finetunning==1) nec1.body_size=nec1.body_words; |
| 101 |
break; |
| 102 |
|
| 103 |
case 301: |
| 104 |
case 302: |
| 105 |
if(options.finetunning==1) { |
| 106 |
location_clean(nec1.location, rand_url1); |
| 107 |
} |
| 108 |
|
| 109 |
break; |
| 110 |
|
| 111 |
default: |
| 112 |
if(options.finetunning==1) nec1.body_size=nec1.body_words; |
| 113 |
break; |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
// Calculo del segundo NEC |
| 119 |
|
| 120 |
memset(url, 0, STRING_SIZE); |
| 121 |
strncpy(url, direccion, STRING_SIZE-1); |
| 122 |
|
| 123 |
strncat(rand_url2, exts_current->word, STRING_SIZE-1-strlen(rand_url2)); |
| 124 |
strncat(url, rand_url2, STRING_SIZE-1-strlen(url)); |
| 125 |
|
| 126 |
nec2=get_url(url); |
| 127 |
|
| 128 |
if(options.debuging>2) printf("[++] calcula_nec() NEC2: %d\n", nec2.codigo_http); |
| 129 |
|
| 130 |
|
| 131 |
// Comparamos |
| 132 |
|
| 133 |
if(nec1.codigo_http==nec2.codigo_http) { |
| 134 |
|
| 135 |
switch(nec2.codigo_http) { |
| 136 |
|
| 137 |
case 200: |
| 138 |
if(options.finetunning==1) nec2.body_size=nec2.body_words; |
| 139 |
|
| 140 |
if(nec1.body_size!=nec2.body_size) { |
| 141 |
IMPRIME("(!) WARNING: NOT_FOUND[%s] page not stable, unable to determine the correct URLs {200}.\n", exts_current->word); |
| 142 |
IMPRIME(" (Try using FineTunning: '-f')\n"); |
| 143 |
if(options.exitonwarn) { next_dir=1; } |
| 144 |
} else { |
| 145 |
mynec->body_size=nec1.body_size; |
| 146 |
} |
| 147 |
break; |
| 148 |
|
| 149 |
case 301: |
| 150 |
case 302: |
| 151 |
if(options.finetunning==1) { |
| 152 |
location_clean(nec2.location, rand_url2); |
| 153 |
} |
| 154 |
|
| 155 |
if(strncmp(nec1.location, nec2.location, STRING_SIZE-1)!=0) { |
| 156 |
IMPRIME("(!) WARNING: NOT_FOUND[%s] not stable, unable to determine correct URLs {30X}.\n", exts_current->word); |
| 157 |
IMPRIME(" (Try using FineTunning: '-f')\n"); |
| 158 |
if(options.exitonwarn) { next_dir=1; } |
| 159 |
} else { |
| 160 |
strncpy(mynec->location, nec1.location, STRING_SIZE-1); |
| 161 |
} |
| 162 |
break; |
| 163 |
|
| 164 |
default: |
| 165 |
mynec->body_size=nec1.body_size; |
| 166 |
break; |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
} else { |
| 171 |
|
| 172 |
IMPRIME("(!) WARNING: NOT_FOUND[%s] not stable, unable to determine the correct URLs {%d,%d}.\n", exts_current->word, nec1.codigo_http, nec2.codigo_http); |
| 173 |
IMPRIME(" (Server is returning random responses)\n"); |
| 174 |
if(options.exitonwarn) { next_dir=1; } |
| 175 |
} |
| 176 |
|
| 177 |
mynec->codigo_http=nec1.codigo_http; |
| 178 |
strncpy(mynec->server, nec1.server, STRING_SIZE-1); |
| 179 |
|
| 180 |
if(options.debuging>2) printf("[++] calcula_nec() NEC: %d - %d\n", mynec->codigo_http, mynec->body_size); |
| 181 |
|
| 182 |
return mynec; |
| 183 |
|
| 184 |
} |
| 185 |
|
| 186 |
|