/* getting the new datas*/ int getthenewpiece() { int sd, i; char *xml, query[256], *post, *post2; if (firstrun) { splitserver(gijohnserver, &gijohnport); if ((xmlxml.newhashes = malloc(sizeof(char))) == NULL) { fprintf(stderr, "Malloc error...\n"); exit(1); } *xmlxml.newhashes = 0; if ((xmlxml.delhashes = malloc(sizeof(char))) == NULL) { fprintf(stderr, "Malloc error...\n"); exit(1); } *xmlxml.newhashes = 0; memset(xmlxml.format, '\0', 64); memset(xmlxml.keymap.firstword, '\0', 64); memset(xmlxml.keymap.lastword, '\0', 64); memset(xmlxml.keymap.charset, '\0', 256); memset(xmlxml.error, '\0', 1024); memset(xmlxml.sessionid, '\0', 33); } if (getnewsid) { getini(username, password); makeformatandperformancexml(&post, username, password); if ((post2 = malloc(sizeof(char)*strlen(post)*3+1)) == NULL) { fprintf(stderr, "Malloc error...\n"); exit(1); } urlencode(post, post2); free(post); post = post2; setbuf(stdout, NULL); if (options.flags & FLG_VERBOSE) printf("[+] Getting new session\n"); if (gijohnsmp > 1) { for (i = 1; i < gijohnsmp; i++) { if (!fork()) { sessionname = malloc(sizeof(char)*30); memset(sessionname, 0, 30); sprintf(sessionname, "gijohnfork_%d", i); rec_name = sessionname; break; } } } sprintf(query, "/newsession.php"); do { *xmlxml.error = 0; host_entry = getthehostname(gijohnserver); if ((sd = getconnection(host_entry, gijohnport)) < 0) { strncpy(xmlxml.error, "connection error", strlen("connection error")); printf("[-] Connection error\n[+]" " Sleeping for %dsec... and reconnection\n", SLEEP_TIME); sleep(SLEEP_TIME); } else { postxml(sd, &xml, query, gijohnserver, gijohnport, post); close(sd); parsexml(xml); free(xml); if (*xmlxml.error) { printf("[-] Error (new sessionid): %s\n[+]" " Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME); sleep(SLEEP_TIME); } } } while (*xmlxml.error); free(post); getnewsid = 0; if (options.flags & FLG_VERBOSE) printf("[+] New session is: %s\n", xmlxml.sessionid); } if (xmlxml.upgrade) { printf("[!] You have to upgrade your gijohn, because it's too old to use! Exiting...\n"); destroysession(); exit(1); } sprintf(query, "/getpieces.php?sessionid=%s", xmlxml.sessionid); do { *xmlxml.error = 0; if ((sd = getconnection(host_entry, gijohnport)) < 0) { strncpy(xmlxml.error, "connection error", strlen("connection error")); printf("[-] Connection error\n[+]" " Sleeping for %dsec... and reconnection\n", SLEEP_TIME); sleep(SLEEP_TIME); } else { getxml(sd, &xml, query, gijohnserver, gijohnport, options.flags & FLG_VERBOSE); close(sd); parsexml(xml); free(xml); if (*xmlxml.error) { printf("[-] Error (new keyspace): %s\n[+] " "Sleeping for %dsec... and resending\n", xmlxml.error, SLEEP_TIME); sleep(SLEEP_TIME); } } } while (*xmlxml.error); if (firstrun) { ldr_init_database(&database, &options.loader); } if (xmlxml.clearhashes) { memset(&database, '\0', sizeof(struct db_main)); ldr_init_database(&database, &options.loader); } if (*xmlxml.error == 0) { if (*xmlxml.newhashes) ldr_load_xml_array(&database, xmlxml.newhashes, xmlxml.format); if (*xmlxml.delhashes) ldr_load_xml_delarray(&database, xmlxml.delhashes); if (*xmlxml.newhashes || *xmlxml.delhashes) ldr_fix_xmldatabase(&database, xmlxml.clearhashes | firstrun); } else { printf("[-] Error: %s\n", xmlxml.error); exit(1); } if ((options.flags & FLG_VERBOSE) || firstrun) { log_event("Remaining %s", john_loaded_counts()); printf("[+] Loaded %s (%s [%s])\n", john_loaded_counts(), database.format->params.format_name, database.format->params.algorithm_name); } if (firstrun) { printf("[+] Server: %s\n[+] Charset: %s\n[+] Charset length: %d\n", gijohnserver, xmlxml.keymap.charset, (int)strlen(xmlxml.keymap.charset)); } return 0; }
void do_external_crack(struct db_main *db) { unsigned char *internal; c_int *external; log_event("Proceeding with external mode: %.100s", ext_mode); #ifdef HAVE_MPI if (mpi_p > 1) log_event("MPI: each node will process 1/%u of candidates", mpi_p); #endif internal = (unsigned char *)int_word; external = ext_word; while (*external) *internal++ = *external++; *internal = 0; status_init(&get_progress, 0); rec_restore_mode(restore_state); rec_init(db, save_state); crk_init(db, fix_state, NULL); do { if (gijohnmodule) { if (!first_time) { generate_external(); } else { first_time = 0; } } else { c_execute_fast(f_generate); } if (!ext_word[0]) break; if (f_filter) { c_execute_fast(f_filter); if (!ext_word[0]) continue; } #ifdef HAVE_MPI // MPI distribution if (mpi_line++ % mpi_p != mpi_id) continue; #endif int_word[0] = ext_word[0]; if ((int_word[1] = ext_word[1])) { internal = (unsigned char *)&int_word[2]; external = &ext_word[2]; do { if (!(internal[0] = external[0])) break; if (!(internal[1] = external[1])) break; if (!(internal[2] = external[2])) break; if (!(internal[3] = external[3])) break; internal += 4; external += 4; } while (1); } int_word[maxlen] = 0; if (crk_process_key(int_word)) break; } while (1); if (!event_abort) progress = 100; // For reporting DONE after a no-ETA run crk_done(); rec_done(event_abort); if (gijohnmodule) { if (!aborted_gijohn) { sig_done(); sendtheresults(); sig_init(); } else { sig_done(); destroysession(); } } }