mirror of
https://github.com/vanhauser-thc/thc-hydra.git
synced 2025-08-21 05:43:52 -07:00
Merge pull request #409 from Galaxy-cst/master
Rebuild JSON report file in first time and append while using -R
This commit is contained in:
commit
a5ade64bdb
1 changed files with 13 additions and 7 deletions
20
hydra.c
20
hydra.c
|
@ -3552,23 +3552,29 @@ int main(int argc, char *argv[]) {
|
||||||
// printf("[DATA] with additional data %s\n", hydra_options.miscptr);
|
// printf("[DATA] with additional data %s\n", hydra_options.miscptr);
|
||||||
|
|
||||||
if (hydra_options.outfile_ptr != NULL) {
|
if (hydra_options.outfile_ptr != NULL) {
|
||||||
if ((hydra_brains.ofp = fopen(hydra_options.outfile_ptr, "a+")) == NULL) {
|
char outfile_open_type[] = "a+"; //Default open in a+ mode
|
||||||
|
if (hydra_options.outfile_format == FORMAT_JSONV1 && hydra_options.restore != 1) {
|
||||||
|
outfile_open_type[0] = 'w'; //Creat new outfile, if using JSON output and not using -R. The open mode should be "w+".
|
||||||
|
}
|
||||||
|
if ((hydra_brains.ofp = fopen(hydra_options.outfile_ptr, outfile_open_type)) == NULL) {
|
||||||
perror("[ERROR] Error creating outputfile");
|
perror("[ERROR] Error creating outputfile");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
if (hydra_options.outfile_format == FORMAT_JSONV1) {
|
if (hydra_options.outfile_format == FORMAT_JSONV1) {
|
||||||
fprintf(hydra_brains.ofp, "{ \"generator\": {\n"
|
if (hydra_options.restore != 1) { // No JSON head while using -R
|
||||||
|
fprintf(hydra_brains.ofp, "{ \"generator\": {\n"
|
||||||
"\t\"software\": \"%s\", \"version\": \"%s\", \"built\": \"%s\",\n"
|
"\t\"software\": \"%s\", \"version\": \"%s\", \"built\": \"%s\",\n"
|
||||||
"\t\"server\": \"%s\", \"service\": \"%s\", \"jsonoutputversion\": \"1.00\",\n"
|
"\t\"server\": \"%s\", \"service\": \"%s\", \"jsonoutputversion\": \"1.00\",\n"
|
||||||
"\t\"commandline\": \"%s",
|
"\t\"commandline\": \"%s",
|
||||||
PROGRAM, VERSION, hydra_build_time(),
|
PROGRAM, VERSION, hydra_build_time(),
|
||||||
hydra_options.server == NULL ? hydra_options.infile_ptr : hydra_options.server, hydra_options.service, prg);
|
hydra_options.server == NULL ? hydra_options.infile_ptr : hydra_options.server, hydra_options.service, prg);
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
char *t = hydra_string_replace(argv[i],"\"","\\\"");
|
char *t = hydra_string_replace(argv[i],"\"","\\\"");
|
||||||
fprintf(hydra_brains.ofp, " %s", t);
|
fprintf(hydra_brains.ofp, " %s", t);
|
||||||
free(t);
|
free(t);
|
||||||
|
}
|
||||||
|
fprintf(hydra_brains.ofp, "\"\n\t},\n\"results\": [");
|
||||||
}
|
}
|
||||||
fprintf(hydra_brains.ofp, "\"\n\t},\n\"results\": [");
|
|
||||||
} else { // else default is plain text aka == 0
|
} else { // else default is plain text aka == 0
|
||||||
fprintf(hydra_brains.ofp, "# %s %s run at %s on %s %s (%s", PROGRAM, VERSION, hydra_build_time(),
|
fprintf(hydra_brains.ofp, "# %s %s run at %s on %s %s (%s", PROGRAM, VERSION, hydra_build_time(),
|
||||||
hydra_options.server == NULL ? hydra_options.infile_ptr : hydra_options.server, hydra_options.service, prg);
|
hydra_options.server == NULL ? hydra_options.infile_ptr : hydra_options.server, hydra_options.service, prg);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue