stdint fixes

This commit is contained in:
van Hauser 2017-07-06 22:25:09 +02:00
commit 11176a1080
3 changed files with 32 additions and 27 deletions

View file

@ -343,7 +343,7 @@ void hdrrepv(ptr_header_node * ptr_head, char *hdrname, char *new_value) {
if (cur_ptr->value) if (cur_ptr->value)
strcpy(cur_ptr->value, new_value); strcpy(cur_ptr->value, new_value);
else { else {
hydra_report(stderr, "[ERROR] Out of memory (hdrrepv %lu)", strlen(new_value) + 1); hydra_report(stderr, "[ERROR] Out of memory (hdrrepv %u)", strlen(new_value) + 1);
hydra_child_exit(0); hydra_child_exit(0);
} }
} }

View file

@ -1215,11 +1215,13 @@ char *hydra_address2string(char *address) {
#ifdef AF_INET6 #ifdef AF_INET6
if (address[0] == 16) { if (address[0] == 16) {
memcpy(&target6.sin6_addr, &address[1], 16); memcpy(&target6.sin6_addr, &address[1], 16);
inet_ntop(AF_INET6, &target6.sin6_addr, ipstring, sizeof(ipstring)); ipstring[0] = '[
inet_ntop(AF_INET6, &target6.sin6_addr, ipstring + 1, sizeof(ipstring) - 1);
if (address[17] != 0) { if (address[17] != 0) {
strcat(ipstring, "%"); strcat(ipstring, "%");
strcat(ipstring, address + 17); strcat(ipstring, address + 17);
} }
strcat(ipstring, "]");
return ipstring; return ipstring;
} else } else
#endif #endif

53
hydra.c
View file

@ -617,7 +617,7 @@ void hydra_debug(int32_t force, char *string) {
if (!debug && !force) if (!debug && !force)
return; return;
printf("[DEBUG] Code: %s Time: %lu\n", string, (uint64_t) time(NULL)); printf("[DEBUG] Code: %s Time: %llu\n", string, (uint64_t) time(NULL));
printf("[DEBUG] Options: mode %d ssl %d restore %d showAttempt %d tasks %d max_use %d tnp %d tpsal %d tprl %d exit_found %d miscptr %s service %s\n", printf("[DEBUG] Options: mode %d ssl %d restore %d showAttempt %d tasks %d max_use %d tnp %d tpsal %d tprl %d exit_found %d miscptr %s service %s\n",
hydra_options.mode, hydra_options.ssl, hydra_options.restore, hydra_options.mode, hydra_options.ssl, hydra_options.restore,
hydra_options.showAttempt, hydra_options.tasks, hydra_options.max_use, hydra_options.showAttempt, hydra_options.tasks, hydra_options.max_use,
@ -625,7 +625,7 @@ void hydra_debug(int32_t force, char *string) {
hydra_options.try_password_reverse_login, hydra_options.exit_found, hydra_options.try_password_reverse_login, hydra_options.exit_found,
STR_NULL(hydra_options.miscptr), hydra_options.service); STR_NULL(hydra_options.miscptr), hydra_options.service);
printf("[DEBUG] Brains: active %d targets %d finished %d todo_all %lu todo %lu sent %lu found %lu countlogin %lu sizelogin %lu countpass %lu sizepass %lu\n", printf("[DEBUG] Brains: active %d targets %d finished %d todo_all %llu todo %llu sent %llu found %llu countlogin %llu sizelogin %llu countpass %llu sizepass %llu\n",
hydra_brains.active, hydra_brains.targets, hydra_brains.finished, hydra_brains.active, hydra_brains.targets, hydra_brains.finished,
hydra_brains.todo_all + total_redo_count, hydra_brains.todo, hydra_brains.todo_all + total_redo_count, hydra_brains.todo,
hydra_brains.sent, hydra_brains.found, hydra_brains.sent, hydra_brains.found,
@ -637,7 +637,7 @@ void hydra_debug(int32_t force, char *string) {
for (i = 0; i < hydra_brains.targets; i++) { for (i = 0; i < hydra_brains.targets; i++) {
hydra_target* target = hydra_targets[i]; hydra_target* target = hydra_targets[i];
printf printf
("[DEBUG] Target %d - target %s ip %s login_no %lu pass_no %lu sent %lu pass_state %d redo_state %d (%d redos) use_count %d failed %d done %d fail_count %d login_ptr %s pass_ptr %s\n", ("[DEBUG] Target %d - target %s ip %s login_no %llu pass_no %llu sent %llu pass_state %d redo_state %d (%d redos) use_count %d failed %d done %d fail_count %d login_ptr %s pass_ptr %s\n",
i, STR_NULL(target->target), hydra_address2string(target->ip), i, STR_NULL(target->target), hydra_address2string(target->ip),
target->login_no, target->pass_no, target->sent, target->login_no, target->pass_no, target->sent,
target->pass_state, target->redo_state, target->redo, target->pass_state, target->redo_state, target->redo,
@ -740,7 +740,7 @@ void hydra_restore_write(int32_t print_msg) {
for (j = 0; j < hydra_options.max_use; j++) { for (j = 0; j < hydra_options.max_use; j++) {
memcpy((char *) &hh, hydra_heads[j], sizeof(hydra_head)); memcpy((char *) &hh, hydra_heads[j], sizeof(hydra_head));
if (j == 0 && debug) { if (j == 0 && debug) {
printf("[DEBUG] sizeof hydra_head: %lu\n", sizeof(hydra_head)); printf("[DEBUG] sizeof hydra_head: %u\n", sizeof(hydra_head));
printf("[DEBUG] memcmp: %d\n", memcmp(hydra_heads[j], &hh, sizeof(hydra_head))); printf("[DEBUG] memcmp: %d\n", memcmp(hydra_heads[j], &hh, sizeof(hydra_head)));
} }
hh.active = 0; // re-enable disabled heads hh.active = 0; // re-enable disabled heads
@ -1556,14 +1556,14 @@ int32_t hydra_send_next_pair(int32_t target_no, int32_t head_no) {
if (debug) if (debug)
printf printf
("[DEBUG] send_next_pair_init target %d, head %d, redo %d, redo_state %d, pass_state %d. loop_mode %d, curlogin %s, curpass %s, tlogin %s, tpass %s, logincnt %lu/%lu, passcnt %lu/%lu, loop_cnt %d\n", ("[DEBUG] send_next_pair_init target %d, head %d, redo %d, redo_state %d, pass_state %d. loop_mode %d, curlogin %s, curpass %s, tlogin %s, tpass %s, logincnt %llu/%llu, passcnt %llu/%llu, loop_cnt %d\n",
target_no, head_no, hydra_targets[target_no]->redo, hydra_targets[target_no]->redo_state, hydra_targets[target_no]->pass_state, hydra_options.loop_mode, target_no, head_no, hydra_targets[target_no]->redo, hydra_targets[target_no]->redo_state, hydra_targets[target_no]->pass_state, hydra_options.loop_mode,
hydra_heads[head_no]->current_login_ptr, hydra_heads[head_no]->current_pass_ptr, hydra_targets[target_no]->login_ptr, hydra_targets[target_no]->pass_ptr, hydra_heads[head_no]->current_login_ptr, hydra_heads[head_no]->current_pass_ptr, hydra_targets[target_no]->login_ptr, hydra_targets[target_no]->pass_ptr,
hydra_targets[target_no]->login_no, hydra_brains.countlogin, hydra_targets[target_no]->pass_no, hydra_brains.countpass, loop_cnt); hydra_targets[target_no]->login_no, hydra_brains.countlogin, hydra_targets[target_no]->pass_no, hydra_brains.countpass, loop_cnt);
if (loop_cnt > (hydra_brains.countlogin * 2) + 1 && loop_cnt > (hydra_brains.countpass * 2) + 1) { if (loop_cnt > (hydra_brains.countlogin * 2) + 1 && loop_cnt > (hydra_brains.countpass * 2) + 1) {
if (debug) if (debug)
printf("[DEBUG] too many loops in send_next_pair, returning -1 (loop_cnt %d, sent %lu, todo %lu)\n", loop_cnt, hydra_targets[target_no]->sent, hydra_brains.todo); printf("[DEBUG] too many loops in send_next_pair, returning -1 (loop_cnt %d, sent %llu, todo %llu)\n", loop_cnt, hydra_targets[target_no]->sent, hydra_brains.todo);
return -1; return -1;
} }
@ -1573,7 +1573,7 @@ int32_t hydra_send_next_pair(int32_t target_no, int32_t head_no) {
snpdone = 1; snpdone = 1;
} else { } else {
if (debug && (hydra_heads[head_no]->current_login_ptr != NULL || hydra_heads[head_no]->current_pass_ptr != NULL)) if (debug && (hydra_heads[head_no]->current_login_ptr != NULL || hydra_heads[head_no]->current_pass_ptr != NULL))
printf("[COMPLETED] target %s - login \"%s\" - pass \"%s\" - child %d - %lu of %lu\n", printf("[COMPLETED] target %s - login \"%s\" - pass \"%s\" - child %d - %llu of %llu\n",
hydra_targets[target_no]->target, hydra_heads[head_no]->current_login_ptr, hydra_heads[head_no]->current_pass_ptr, head_no, hydra_targets[target_no]->target, hydra_heads[head_no]->current_login_ptr, hydra_heads[head_no]->current_pass_ptr, head_no,
hydra_targets[target_no]->sent, hydra_brains.todo + hydra_targets[target_no]->redo); hydra_targets[target_no]->sent, hydra_brains.todo + hydra_targets[target_no]->redo);
hydra_heads[head_no]->redo = 0; hydra_heads[head_no]->redo = 0;
@ -1883,7 +1883,7 @@ int32_t hydra_send_next_pair(int32_t target_no, int32_t head_no) {
return 0; // not prevent disabling it, if its needed its already done in the above line return 0; // not prevent disabling it, if its needed its already done in the above line
} }
if (debug || hydra_options.showAttempt) { if (debug || hydra_options.showAttempt) {
printf("[%sATTEMPT] target %s - login \"%s\" - pass \"%s\" - %lu of %lu [child %d] (%d/%d)\n", printf("[%sATTEMPT] target %s - login \"%s\" - pass \"%s\" - %llu of %llu [child %d] (%d/%d)\n",
hydra_targets[target_no]->redo_state ? "REDO-" : snp_is_redo ? "RE-" : "", hydra_targets[target_no]->target, hydra_heads[head_no]->current_login_ptr, hydra_targets[target_no]->redo_state ? "REDO-" : snp_is_redo ? "RE-" : "", hydra_targets[target_no]->target, hydra_heads[head_no]->current_login_ptr,
hydra_heads[head_no]->current_pass_ptr, hydra_targets[target_no]->sent, hydra_brains.todo + hydra_targets[target_no]->redo, head_no, hydra_targets[target_no]->redo_state ? hydra_targets[target_no]->redo_state - 1 : 0, hydra_targets[target_no]->redo); hydra_heads[head_no]->current_pass_ptr, hydra_targets[target_no]->sent, hydra_brains.todo + hydra_targets[target_no]->redo, head_no, hydra_targets[target_no]->redo_state ? hydra_targets[target_no]->redo_state - 1 : 0, hydra_targets[target_no]->redo);
} }
@ -3165,11 +3165,11 @@ int32_t main(int32_t argc, char *argv[]) {
exit(-1); exit(-1);
} }
if (hydra_brains.countlogin > MAX_LINES) { if (hydra_brains.countlogin > MAX_LINES) {
fprintf(stderr, "[ERROR] Maximum number of logins is %d, this file has %lu entries.\n", MAX_LINES, hydra_brains.countlogin); fprintf(stderr, "[ERROR] Maximum number of logins is %d, this file has %llu entries.\n", MAX_LINES, hydra_brains.countlogin);
exit(-1); exit(-1);
} }
if (hydra_brains.sizelogin > MAX_BYTES) { if (hydra_brains.sizelogin > MAX_BYTES) {
fprintf(stderr, "[ERROR] Maximum size of the login file is %d, this file has %lu bytes.\n", MAX_BYTES, (uint64_t) hydra_brains.sizelogin); fprintf(stderr, "[ERROR] Maximum size of the login file is %d, this file has %llu bytes.\n", MAX_BYTES, (uint64_t) hydra_brains.sizelogin);
exit(-1); exit(-1);
} }
login_ptr = malloc(hydra_brains.sizelogin + hydra_brains.countlogin + 8); login_ptr = malloc(hydra_brains.sizelogin + hydra_brains.countlogin + 8);
@ -3194,11 +3194,11 @@ int32_t main(int32_t argc, char *argv[]) {
exit(-1); exit(-1);
} }
if (hydra_brains.countpass > MAX_LINES) { if (hydra_brains.countpass > MAX_LINES) {
fprintf(stderr, "[ERROR] Maximum number of passwords is %d, this file has %lu entries.\n", MAX_LINES, hydra_brains.countpass); fprintf(stderr, "[ERROR] Maximum number of passwords is %d, this file has %llu entries.\n", MAX_LINES, hydra_brains.countpass);
exit(-1); exit(-1);
} }
if (hydra_brains.sizepass > MAX_BYTES) { if (hydra_brains.sizepass > MAX_BYTES) {
fprintf(stderr, "[ERROR] Maximum size of the password file is %d, this file has %lu bytes.\n", MAX_BYTES, (uint64_t) hydra_brains.sizepass); fprintf(stderr, "[ERROR] Maximum size of the password file is %d, this file has %llu bytes.\n", MAX_BYTES, (uint64_t) hydra_brains.sizepass);
exit(-1); exit(-1);
} }
pass_ptr = malloc(hydra_brains.sizepass + hydra_brains.countpass + 8); pass_ptr = malloc(hydra_brains.sizepass + hydra_brains.countpass + 8);
@ -3241,11 +3241,11 @@ int32_t main(int32_t argc, char *argv[]) {
exit(-1); exit(-1);
} }
if (hydra_brains.countlogin > MAX_LINES / 2) { if (hydra_brains.countlogin > MAX_LINES / 2) {
fprintf(stderr, "[ERROR] Maximum number of colon file entries is %d, this file has %lu entries.\n", MAX_LINES / 2, hydra_brains.countlogin); fprintf(stderr, "[ERROR] Maximum number of colon file entries is %d, this file has %llu entries.\n", MAX_LINES / 2, hydra_brains.countlogin);
exit(-1); exit(-1);
} }
if (hydra_brains.sizelogin > MAX_BYTES / 2) { if (hydra_brains.sizelogin > MAX_BYTES / 2) {
fprintf(stderr, "[ERROR] Maximum size of the colon file is %d, this file has %lu bytes.\n", MAX_BYTES / 2, (uint64_t) hydra_brains.sizelogin); fprintf(stderr, "[ERROR] Maximum size of the colon file is %d, this file has %llu bytes.\n", MAX_BYTES / 2, (uint64_t) hydra_brains.sizelogin);
exit(-1); exit(-1);
} }
csv_ptr = malloc(hydra_brains.sizelogin + 2 * hydra_brains.countlogin + 8); csv_ptr = malloc(hydra_brains.sizelogin + 2 * hydra_brains.countlogin + 8);
@ -3465,7 +3465,7 @@ int32_t main(int32_t argc, char *argv[]) {
bail("No login/password combination given!"); bail("No login/password combination given!");
if (hydra_brains.todo < hydra_options.tasks) { if (hydra_brains.todo < hydra_options.tasks) {
if (verbose && hydra_options.tasks != TASKS) if (verbose && hydra_options.tasks != TASKS)
printf("[VERBOSE] More tasks defined than login/pass pairs exist. Tasks reduced to %lu\n", hydra_brains.todo); printf("[VERBOSE] More tasks defined than login/pass pairs exist. Tasks reduced to %llu\n", hydra_brains.todo);
hydra_options.tasks = hydra_brains.todo; hydra_options.tasks = hydra_brains.todo;
} }
} }
@ -3500,13 +3500,16 @@ int32_t main(int32_t argc, char *argv[]) {
if (hydra_options.ssl) if (hydra_options.ssl)
options = options | OPTION_SSL; options = options | OPTION_SSL;
if (hydra_options.colonfile != NULL) if (hydra_options.colonfile != NULL)
printf("[DATA] max %d task%s per %d server%s, overall %d tasks, %lu login tr%s, ~%lu tr%s per task\n", hydra_options.tasks, hydra_options.tasks == 1 ? "" : "s", printf("[DATA] max %d task%s per %d server%s, overall %d tasks, %llu login tr%s, ~%llu tr%s per task\n", hydra_options.tasks, hydra_options.tasks == 1 ? "" : "s",
hydra_brains.targets, hydra_brains.targets == 1 ? "" : "s", hydra_options.max_use, hydra_brains.todo, hydra_brains.todo == 1 ? "y" : "ies", math2, hydra_brains.targets, hydra_brains.targets == 1 ? "" : "s", hydra_options.max_use, hydra_brains.todo, hydra_brains.todo == 1 ? "y" : "ies", math2,
math2 == 1 ? "y" : "ies"); math2 == 1 ? "y" : "ies");
else else
printf("[DATA] max %d task%s per %d server%s, overall %d tasks, %lu login tr%s (l:%lu/p:%lu), ~%lu tr%s per task\n", hydra_options.tasks, hydra_options.tasks == 1 ? "" : "s", printf("[DATA] max %d task%s per %d server%s, overall %d task%s, %llu login tr%s (l:%llu/p:%llu), ~%llu tr%s per task\n", hydra_options.tasks, hydra_options.tasks == 1 ? "" : "s",
hydra_brains.targets, hydra_brains.targets == 1 ? "" : "s", hydra_options.max_use, hydra_brains.todo, hydra_brains.todo == 1 ? "y" : "ies", hydra_brains.targets, hydra_brains.targets == 1 ? "" : "s",
(uint64_t) hydra_brains.countlogin, (uint64_t) hydra_brains.countpass, math2, math2 == 1 ? "y" : "ies"); hydra_options.max_use, hydra_options.max_use == 1 ? "" : "s",
hydra_brains.todo, hydra_brains.todo == 1 ? "y" : "ies",
(uint64_t) hydra_brains.countlogin, (uint64_t) hydra_brains.countpass,
math2, math2 == 1 ? "y" : "ies");
printf("[DATA] attacking service %s on port %d%s\n", hydra_options.service, port, hydra_options.ssl == 1 ? " with SSL" : ""); printf("[DATA] attacking service %s on port %d%s\n", hydra_options.service, port, hydra_options.ssl == 1 ? " with SSL" : "");
if (hydra_options.miscptr != NULL && hydra_options.miscptr[0] != 0) if (hydra_options.miscptr != NULL && hydra_options.miscptr[0] != 0)
@ -3843,7 +3846,7 @@ int32_t main(int32_t argc, char *argv[]) {
case 'C': // head reports connect error case 'C': // head reports connect error
fck = write(hydra_heads[head_no]->sp[0], "Q", 1); fck = write(hydra_heads[head_no]->sp[0], "Q", 1);
if (debug) { if (debug) {
printf("[ATTEMPT-ERROR] target %s - login \"%s\" - pass \"%s\" - child %d - %lu of %lu\n", printf("[ATTEMPT-ERROR] target %s - login \"%s\" - pass \"%s\" - child %d - %llu of %llu\n",
hydra_targets[hydra_heads[head_no]->target_no]->target, hydra_heads[head_no]->current_login_ptr, hydra_heads[head_no]->current_pass_ptr, head_no, hydra_targets[hydra_heads[head_no]->target_no]->target, hydra_heads[head_no]->current_login_ptr, hydra_heads[head_no]->current_pass_ptr, head_no,
hydra_targets[hydra_heads[head_no]->target_no]->sent, hydra_brains.todo); hydra_targets[hydra_heads[head_no]->target_no]->sent, hydra_brains.todo);
} }
@ -3892,7 +3895,7 @@ int32_t main(int32_t argc, char *argv[]) {
hydra_increase_fail_count(hydra_heads[head_no]->target_no, head_no); hydra_increase_fail_count(hydra_heads[head_no]->target_no, head_no);
} }
} }
//if (debug) printf("DEBUG: bug hunt: %lu %lu\n", hydra_brains.todo_all, hydra_brains.sent); //if (debug) printf("DEBUG: bug hunt: %llu %llu\n", hydra_brains.todo_all, hydra_brains.sent);
usleepn(USLEEP_LOOP); usleepn(USLEEP_LOOP);
(void) wait3(NULL, WNOHANG, NULL); (void) wait3(NULL, WNOHANG, NULL);
@ -3927,11 +3930,11 @@ int32_t main(int32_t argc, char *argv[]) {
for (i = 0; i < hydra_options.max_use; i++) for (i = 0; i < hydra_options.max_use; i++)
if (hydra_heads[i]->active > 0 && hydra_heads[i]->pid > 0) if (hydra_heads[i]->active > 0 && hydra_heads[i]->pid > 0)
hydra_kill_head(i, 1, 3); hydra_kill_head(i, 1, 3);
printf("[BUG] %lu + %d < %lu\n", hydra_brains.todo_all, total_redo_count, hydra_brains.sent); printf("[BUG] %llu + %d < %llu\n", hydra_brains.todo_all, total_redo_count, hydra_brains.sent);
bail("[BUG] Weird bug detected where more tests were performed than possible. Please rerun with -d command line switch and post all output plus command line here: https://github.com/vanhauser-thc/thc-hydra/issues/113 or send it in an email to vh@thc.org"); bail("[BUG] Weird bug detected where more tests were performed than possible. Please rerun with -d command line switch and post all output plus command line here: https://github.com/vanhauser-thc/thc-hydra/issues/113 or send it in an email to vh@thc.org");
} }
*/ */
printf("[STATUS] %.2f tries/min, %lu tries in %02lu:%02luh, %lu to do in %02lu:%02luh, %d active\n", (1.0 * hydra_brains.sent) / (((elapsed_status - starttime) * 1.0) / 60), // tries/min printf("[STATUS] %.2f tries/min, %llu tries in %02llu:%02lluh, %llu to do in %02lu:%02luh, %d active\n", (1.0 * hydra_brains.sent) / (((elapsed_status - starttime) * 1.0) / 60), // tries/min
hydra_brains.sent, // tries hydra_brains.sent, // tries
(uint64_t) ((elapsed_status - starttime) / 3600), // hours (uint64_t) ((elapsed_status - starttime) / 3600), // hours
(uint64_t) (((elapsed_status - starttime) % 3600) / 60), // minutes (uint64_t) (((elapsed_status - starttime) % 3600) / 60), // minutes
@ -3976,7 +3979,7 @@ int32_t main(int32_t argc, char *argv[]) {
fprintf(stderr, "[ERROR] illegal target result value (%d=>%d)\n", i, hydra_targets[i]->done); fprintf(stderr, "[ERROR] illegal target result value (%d=>%d)\n", i, hydra_targets[i]->done);
} }
printf("%d of %d target%s%scompleted, %lu valid password%s found\n", hydra_brains.targets - j - k - error, hydra_brains.targets, hydra_brains.targets == 1 ? " " : "s ", printf("%d of %d target%s%scompleted, %llu valid password%s found\n", hydra_brains.targets - j - k - error, hydra_brains.targets, hydra_brains.targets == 1 ? " " : "s ",
hydra_brains.found > 0 ? "successfully " : "", hydra_brains.found, hydra_brains.found == 1 ? "" : "s"); hydra_brains.found > 0 ? "successfully " : "", hydra_brains.found, hydra_brains.found == 1 ? "" : "s");
error += j; error += j;
@ -4047,7 +4050,7 @@ int32_t main(int32_t argc, char *argv[]) {
printf("%s (%s) finished at %s\n", PROGRAM, RESOURCE, hydra_build_time()); printf("%s (%s) finished at %s\n", PROGRAM, RESOURCE, hydra_build_time());
if (hydra_brains.ofp != NULL && hydra_brains.ofp != stdout) { if (hydra_brains.ofp != NULL && hydra_brains.ofp != stdout) {
if (hydra_options.outfile_format == FORMAT_JSONV1) { if (hydra_options.outfile_format == FORMAT_JSONV1) {
fprintf(hydra_brains.ofp, "\n\t],\n\"success\": %s,\n\"errormessages\": [ %s ],\n\"quantityfound\": %lu }\n", fprintf(hydra_brains.ofp, "\n\t],\n\"success\": %s,\n\"errormessages\": [ %s ],\n\"quantityfound\": %llu }\n",
(error ? "false" : "true"), json_error, hydra_brains.found); (error ? "false" : "true"), json_error, hydra_brains.found);
} }
fclose(hydra_brains.ofp); fclose(hydra_brains.ofp);