mirror of
https://github.com/vanhauser-thc/thc-hydra.git
synced 2025-08-20 05:13:51 -07:00
Added function to stringify headers from linked list.
This commit is contained in:
parent
d273cb4807
commit
c466657496
1 changed files with 119 additions and 75 deletions
|
@ -106,6 +106,7 @@ int add_header(char *header, char *value){
|
||||||
// head is NULL, so the list is empty
|
// head is NULL, so the list is empty
|
||||||
ptr_head = new_ptr;
|
ptr_head = new_ptr;
|
||||||
|
|
||||||
|
// TODO Remove the debug messages
|
||||||
hydra_report_debug(stdout, "[add_header] Added header %s: %s", header, value);
|
hydra_report_debug(stdout, "[add_header] Added header %s: %s", header, value);
|
||||||
hydra_report_debug(stdout, "[add_header] len(header) = %d", strlen(header));
|
hydra_report_debug(stdout, "[add_header] len(header) = %d", strlen(header));
|
||||||
hydra_report_debug(stdout, "[add_header] len(value) = %d", strlen(value));
|
hydra_report_debug(stdout, "[add_header] len(value) = %d", strlen(value));
|
||||||
|
@ -137,9 +138,48 @@ int add_or_replace_header(char *header, char *value){
|
||||||
if(cur_ptr == NULL)
|
if(cur_ptr == NULL)
|
||||||
return add_header(header, value);
|
return add_header(header, value);
|
||||||
|
|
||||||
|
// TODO Remove the debug messages
|
||||||
|
hydra_report_debug(stdout, "[add_or_replace_header] Added header %s: %s", header, value);
|
||||||
|
hydra_report_debug(stdout, "[add_or_replace_header] len(header) = %d", strlen(header));
|
||||||
|
hydra_report_debug(stdout, "[add_or_replace_header] len(value) = %d", strlen(value));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Concat all the headers in the list in a single string, and clean the whole list.
|
||||||
|
*/
|
||||||
|
char * stringify_headers_and_clean(){
|
||||||
|
char * headers_str = NULL;
|
||||||
|
ptr_header_node cur_ptr = ptr_head, tmp_ptr = NULL;
|
||||||
|
int ttl_size = 0;
|
||||||
|
|
||||||
|
while(cur_ptr){
|
||||||
|
if(cur_ptr->header && cur_ptr->value){ // Check for NULLs
|
||||||
|
ttl_size += strlen(cur_ptr->header) + strlen(cur_ptr->value) + 1;
|
||||||
|
headers_str = (char *) realloc(headers_str, sizeof(char) * ttl_size);
|
||||||
|
if(headers_str){ // Check for errors
|
||||||
|
strcat(headers_str, cur_ptr->header);
|
||||||
|
strcat(headers_str, ": ");
|
||||||
|
strcat(headers_str, cur_ptr->value);
|
||||||
|
strcat(headers_str, "\r\n");
|
||||||
|
}else{
|
||||||
|
// Error: out of memory
|
||||||
|
hydra_report(stderr, "Out of memory for HTTP headers");
|
||||||
|
hydra_child_exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Clean it up and get to the next header
|
||||||
|
tmp_ptr = cur_ptr;
|
||||||
|
cur_ptr = cur_ptr->next;
|
||||||
|
free(tmp_ptr->header);
|
||||||
|
free(tmp_ptr->value);
|
||||||
|
free(tmp_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers_str;
|
||||||
|
}
|
||||||
|
|
||||||
int strpos(char *str, char *target) {
|
int strpos(char *str, char *target) {
|
||||||
char *res = strstr(str, target);
|
char *res = strstr(str, target);
|
||||||
|
|
||||||
|
@ -660,7 +700,7 @@ void service_http_form(char *ip, int sp, unsigned char options, char *miscptr, F
|
||||||
*ptr2++ = 0;
|
*ptr2++ = 0;
|
||||||
/*
|
/*
|
||||||
* At this point:
|
* At this point:
|
||||||
* - optional1 contains the header's name
|
* - (optional1 + 2) contains the header's name
|
||||||
* - ptr contains the header's value
|
* - ptr contains the header's value
|
||||||
*/
|
*/
|
||||||
header = (char *) malloc(strlen(optional1 + 2));
|
header = (char *) malloc(strlen(optional1 + 2));
|
||||||
|
@ -668,10 +708,7 @@ void service_http_form(char *ip, int sp, unsigned char options, char *miscptr, F
|
||||||
if(header && value){
|
if(header && value){
|
||||||
strcpy(header, optional1 + 2);
|
strcpy(header, optional1 + 2);
|
||||||
strcpy(value, hydra_strrep(ptr, "\\:", ":"));
|
strcpy(value, hydra_strrep(ptr, "\\:", ":"));
|
||||||
hydra_report_debug(stdout, "Adding header: %s: %s", header, value);
|
if(add_header(hydra_trim(header), hydra_trim(value))){
|
||||||
hydra_report_debug(stdout, "\tlen(header): %d", strlen(header));
|
|
||||||
hydra_report_debug(stdout, "\tlen(value): %d", strlen(value));
|
|
||||||
if(add_header(header, value)){
|
|
||||||
// Success: break the switch and go ahead
|
// Success: break the switch and go ahead
|
||||||
optional1 = ptr2;
|
optional1 = ptr2;
|
||||||
break;
|
break;
|
||||||
|
@ -683,14 +720,21 @@ void service_http_form(char *ip, int sp, unsigned char options, char *miscptr, F
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
// add a new header, or replace an existing one's value
|
// add a new header, or replace an existing one's value
|
||||||
// if (sizeof(userheader) - strlen(userheader) > 4) {
|
header = (char *) malloc(strlen(optional1 + 2));
|
||||||
// strncat(userheader, optional1 + 2, sizeof(userheader) - strlen(userheader) - 4);
|
value = (char *) malloc(strlen(ptr));
|
||||||
// strcat(userheader, ":");
|
if(header && value){
|
||||||
// strncat(userheader, hydra_strrep(ptr, "\\:", ":"), sizeof(userheader) - strlen(userheader) - 3);
|
strcpy(header, optional1 + 2);
|
||||||
// strcat(userheader, "\r\n");
|
strcpy(value, hydra_strrep(ptr, "\\:", ":"));
|
||||||
// }
|
if(add_or_replace_header(hydra_trim(header), hydra_trim(value))){
|
||||||
|
// Success: break the switch and go ahead
|
||||||
optional1 = ptr2;
|
optional1 = ptr2;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Error: abort execution
|
||||||
|
hydra_report(stderr, "[ERROR] Out of memory for HTTP headers.");
|
||||||
|
hydra_child_exit(1);
|
||||||
|
break;
|
||||||
// no default
|
// no default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue