Exemple #1
0
void do_regex_crack(struct db_main *db, const char *regex) {
	c_simplestring_ptr buffer = c_simplestring_new();
	c_iterator_ptr iter = NULL;
	charset encoding = CHARSET_UTF8;
	int ignore_case = 0;
	char word[WORDSIZE];

	if (john_main_process)
		fprintf(stderr, "Warning: regex mode currently can't be "
		        "resumed if aborted\n");

	rexgen_setlocale();
	status_init(&get_progress, 0);
	rec_restore_mode(restore_state);
	rec_init(db, save_state);
	crk_init(db, fix_state, NULL);
	iter = c_regex_iterator_cb(regex, ignore_case, encoding, callback);
	if (!iter) {
		fprintf(stderr, "Error, invalid regex expression.  John exiting now\n");
		exit(1);
	}
	while (c_iterator_next(iter)) {
		c_iterator_value(iter, buffer);
		c_simplestring_to_binary_string(buffer, &word[0], sizeof(word));
		c_simplestring_clear(buffer);
		if (ext_filter((char*)word)) {
			if (crk_process_key((char*)word))
				break;
		}
	}
	c_simplestring_delete(buffer);
	c_iterator_delete(iter);
	crk_done();
	rec_done(event_abort);
}
Exemple #2
0
int _tmain(int argc, _TCHAR* argv[]) {
  c_simplestring_ptr buffer = NULL;
  char binary_string[512];
  c_regex_ptr regex = NULL;
  c_iterator_ptr iter = NULL;
  int retval = 0;
  const char* regex_str = NULL;
#ifdef DEBUG_STATE
  char* state = NULL;
#endif /* DEBUG_STATE */

#ifdef YYDEBUG
#if YYDEBUG == 1
  rexgen_debug = 1;
#endif
#endif

  rexgen_setlocale();
  regex_str = rexgen_parse_arguments(argc, argv);
  if (regex_str == NULL) {
    rexgen_usage();
    return 1;
  }

  if (infile_name != NULL) {
    if (0 == _tcscmp(infile_name, _T("-"))) {
      infile = stdin;
    } else {
      infile = _tfopen(infile_name, _T("r"));
      if (infile == NULL) {
        perror("unable to open input file");
        return 1;
      }
    }
  }

  regex = c_regex_cb(regex_str, callback);
  if (regex == NULL) {
    fprintf(stderr, "Syntax Error:\n%s\n", c_rexgen_get_last_error());
    retval = 1;
    goto cleanup_and_exit;
  }

  if (c_regex_uses_callback(regex) && infile == NULL) {
    fprintf(stderr, "You must specify a filename when you use '\\0'\n");
    retval = 1;
    goto cleanup_and_exit;
  }

  iter = c_regex_iterator(regex);
  if (iter == NULL) {
    fprintf(stderr, "Syntax Error:\n%s\n", c_rexgen_get_last_error());
    retval = 1;
    goto cleanup_and_exit;
  }

  /*  to test restore state, simply put the restore string here, AND use exactly the same regex input string */
  /* c_iterator_set_state(iter, "RXS1.1,b,0,3,1,1,2,0,9,0,0,a,1,1,0"); */
  /* */
#ifdef DEBUG_STATE
  c_iterator_get_state(iter, &state);
  printf ("initial state = %s\n", state);
  c_iterator_delete_state_buffer(state);
#endif /* DEBUG_STATE */

	buffer = c_simplestring_new();
  while (c_iterator_next(iter)) {
    c_iterator_value(iter, buffer);
    encoder(buffer, binary_string, sizeof(binary_string));
    printf("%s\n", binary_string);

#ifdef DEBUG_STATE
    /* These show how to save-restore state */
    c_iterator_get_state(iter, &state);
    printf ("state         = %s\n", state);
    c_iterator_set_state(iter, state);
    c_iterator_delete_state_buffer(state);
#endif /* DEBUG_STATE */
    c_simplestring_clear(buffer);
  }

#ifdef DEBUG_STATE
  c_iterator_get_state(iter, &state);
  printf ("final state   = %s\n", state);
  c_iterator_delete_state_buffer(state);
#endif /* DEBUG_STATE */

cleanup_and_exit:
  c_simplestring_delete(buffer);
  c_iterator_delete(iter);
  c_regex_delete(regex);

#if defined(_WIN32) && defined(_DEBUG)
  getchar();
#endif
  return retval;
}
Exemple #3
0
int do_regex_crack_as_rules(const char *regex, const char *base_word, int regex_case, const char *regex_alpha) {
	c_simplestring_ptr buffer = c_simplestring_new();
	c_iterator_ptr iter = NULL;
	charset encoding = CHARSET_UTF8;
	char word[WORDSIZE];
	static int bFirst=1;
	static int bALPHA=0;

	if (bFirst) {
		bFirst = 0;
		rexgen_setlocale();
		if (regex_alpha && !strncmp(regex_alpha, "alpha", 5)) {
			bALPHA = 1;
			SetupAlpha(regex_alpha);
		}
	}

	if (bALPHA) {
		// Ok, we do our own elete of the word,
		static char Buf[4096];
		char *cp = Buf;
		const char *cpi = base_word;
		while (*cpi) {
			cp += strnzcpyn (cp, rexgen_alphabets[(unsigned char)(*cpi)], 100);
			++cpi;
			if (cp - Buf > sizeof(Buf)-101)
				break;
		}
		*cp = 0;
		printf ("buf=%s\n", Buf);
		if (*regex == 0)
			regex = Buf;
		else {
			static char final_Buf[16384];
			int len = strlen(Buf)+1;
			cpi = regex;
			cp = final_Buf;
			while (*cpi) {
				if (*cpi == '\\' && cpi[1] == '0') {
					cp += strnzcpyn (cp, Buf, len);
					cpi += 2;
				} else
					*cp++ = *cpi++;

			}
			regex = final_Buf;
		}
	}

	strcpy(BaseWord, base_word);
	if (!regex[0]) {
		if (ext_filter("")) {
			if (crk_process_key(""))
				return 1;
		}
		return 0;
	}
	iter = c_regex_iterator_cb(regex, regex_case, encoding, callback);
	if (!iter) {
		fprintf(stderr, "Error, invalid regex expression.  John exiting now  base_word=%s  Regex= %s\n", base_word, regex);
		exit(1);
	}
	while (c_iterator_next(iter)) {
		c_iterator_value(iter, buffer);
		c_simplestring_to_binary_string(buffer, &word[0], sizeof(word));
		c_simplestring_clear(buffer);
		if (ext_filter((char*)word)) {
			if (crk_process_key((char*)word)) {
				c_simplestring_delete(buffer);
				c_iterator_delete(iter);
				return 1;
			}
		}
	}
	c_simplestring_delete(buffer);
	c_iterator_delete(iter);
	return 0;
}