diff -Naur john-1.8.0/src/formats.c john-1.8.0-regex/src/formats.c --- john-1.8.0/src/formats.c 2013-05-13 10:40:23.000000000 +0200 +++ john-1.8.0-regex/src/formats.c 2013-06-27 21:40:31.134673050 +0200 @@ -15,7 +15,7 @@ void fmt_register(struct fmt_main *format) { - format->private.initialized = 0; + format->_private.initialized = 0; format->next = NULL; *fmt_tail = format; fmt_tail = &format->next; @@ -23,17 +23,17 @@ void fmt_init(struct fmt_main *format) { - if (!format->private.initialized) { + if (!format->_private.initialized) { format->methods.init(format); - format->private.initialized = 1; + format->_private.initialized = 1; } } void fmt_done(struct fmt_main *format) { - if (format->private.initialized) { + if (format->_private.initialized) { format->methods.done(); - format->private.initialized = 0; + format->_private.initialized = 0; } } @@ -61,7 +61,7 @@ * Test each format just once unless we're debugging. */ #ifndef DEBUG - if (format->private.initialized == 2) + if (format->_private.initialized == 2) return NULL; #endif @@ -191,7 +191,7 @@ } } while (done != 3); - format->private.initialized = 2; + format->_private.initialized = 2; return NULL; } diff -Naur john-1.8.0/src/formats.h john-1.8.0-regex/src/formats.h --- john-1.8.0/src/formats.h 2013-05-13 10:40:14.000000000 +0200 +++ john-1.8.0-regex/src/formats.h 2013-06-27 21:40:02.466530892 +0200 @@ -233,7 +233,7 @@ struct fmt_main { struct fmt_params params; struct fmt_methods methods; - struct fmt_private private; + struct fmt_private _private; struct fmt_main *next; }; diff -Naur john-1.8.0/src/john.c john-1.8.0-regex/src/john.c --- john-1.8.0/src/john.c 2013-05-30 01:27:25.000000000 +0200 +++ john-1.8.0-regex/src/john.c 2013-06-27 19:48:53.097459277 +0200 @@ -59,6 +59,9 @@ #include "inc.h" #include "external.h" #include "batch.h" +#if HAVE_REXGEN +#include "regex.h" +#endif /* HAVE_REXGEN */ #if CPU_DETECT extern int CPU_detect(void); @@ -588,6 +591,11 @@ if (options.flags & FLG_WORDLIST_CHK) do_wordlist_crack(&database, options.wordlist, (options.flags & FLG_RULES) != 0); +#if HAVE_REXGEN + else + if (options.flags & FLG_REGEX_CHK) + do_regex_crack(&database, options.regex); +#endif /* HAVE_REXGEN */ else if (options.flags & FLG_INC_CHK) do_incremental_crack(&database, options.charset); diff -Naur john-1.8.0/src/Makefile john-1.8.0-regex/src/Makefile --- john-1.8.0/src/Makefile 2013-05-30 01:21:25.000000000 +0200 +++ john-1.8.0-regex/src/Makefile 2013-06-27 21:52:35.398264479 +0200 @@ -8,10 +8,10 @@ # There's ABSOLUTELY NO WARRANTY, express or implied. # -CC = gcc +CC = cc AS = $(CC) -LD = $(CC) -CPP = $(CC) +LD = c++ +CPP = c++ CP = cp LN = ln -sf RM = rm -f @@ -28,11 +28,12 @@ #OMPFLAGS = -fopenmp -D_FORTIFY_SOURCE=0 # Sun Studio with OpenMP (set the OMP_NUM_THREADS env var at runtime) #OMPFLAGS = -xopenmp -CFLAGS = -c -Wall -Wdeclaration-after-statement -O2 -fomit-frame-pointer $(OMPFLAGS) +CFLAGS = -c -Wall -Wdeclaration-after-statement -O2 -fomit-frame-pointer \ +$(OMPFLAGS) -DHAVE_REXGEN=1 # CFLAGS for use on the main john.c file only CFLAGS_MAIN = $(CFLAGS) ASFLAGS = -c $(OMPFLAGS) -LDFLAGS = -s $(OMPFLAGS) +LDFLAGS = -s $(OMPFLAGS) -lrexgen-0.1.0 OPT_NORMAL = -funroll-loops # Remove the "-Os" if you're using an ancient version of gcc OPT_INLINE = -Os -funroll-loops -finline-functions @@ -52,7 +53,8 @@ recovery.o rpp.o rules.o signals.o single.o status.o tty.o wordlist.o \ unshadow.o \ unafs.o \ - unique.o + unique.o \ + regex.o BENCH_DES_OBJS_ORIG = \ DES_fmt.o DES_std.o @@ -895,6 +897,9 @@ .c.o: $(CC) $(CFLAGS) $(OPT_NORMAL) $*.c +.cpp.o: + $(CPP) $(CFLAGS) $(OPT_NORMAL) -std=c++0x $*.cpp + .S.o: $(AS) $(ASFLAGS) $*.S diff -Naur john-1.8.0/src/options.c john-1.8.0-regex/src/options.c --- john-1.8.0/src/options.c 2013-05-30 01:31:53.000000000 +0200 +++ john-1.8.0-regex/src/options.c 2013-06-27 19:32:59.168729000 +0200 @@ -42,6 +42,10 @@ 0, 0, OPT_FMT_STR_ALLOC, &options.charset}, {"external", FLG_EXTERNAL_SET, FLG_EXTERNAL_CHK, 0, OPT_REQ_PARAM, OPT_FMT_STR_ALLOC, &options.external}, +#if HAVE_REXGEN + {"regex", FLG_REGEX_SET, FLG_REGEX_CHK, + 0, OPT_REQ_PARAM, OPT_FMT_STR_ALLOC, &options.regex}, +#endif {"stdout", FLG_STDOUT, FLG_STDOUT, FLG_CRACKING_SUP, FLG_SINGLE_CHK | FLG_BATCH_CHK, "%u", &options.length}, @@ -94,6 +98,13 @@ #define JOHN_USAGE_FORK "" #endif +#if HAVE_REXGEN +#define JOHN_USAGE_REGEX \ +"--regex=REGEX regular expression mode\n" +#else +#define JOHN_USAGE_REGEX "" +#endif + #define JOHN_USAGE \ "John the Ripper password cracker, version " JOHN_VERSION "\n" \ "Copyright (c) 1996-2013 by " JOHN_COPYRIGHT "\n" \ @@ -105,6 +116,7 @@ "--rules enable word mangling rules for wordlist mode\n" \ "--incremental[=MODE] \"incremental\" mode [using section MODE]\n" \ "--external=MODE external mode or word filter\n" \ +JOHN_USAGE_REGEX \ "--stdout[=LENGTH] just output candidate passwords [cut at LENGTH]\n" \ "--restore[=NAME] restore an interrupted session [called NAME]\n" \ "--session=NAME give a new session the NAME\n" \ diff -Naur john-1.8.0/src/options.h john-1.8.0-regex/src/options.h --- john-1.8.0/src/options.h 2013-05-30 01:31:55.000000000 +0200 +++ john-1.8.0-regex/src/options.h 2013-06-27 19:30:11.659898368 +0200 @@ -56,6 +56,12 @@ #define FLG_EXTERNAL_CHK 0x00001000 #define FLG_EXTERNAL_SET \ (FLG_EXTERNAL_CHK | FLG_ACTION | FLG_CRACKING_SUP | FLG_PWD_SUP) + +#if HAVE_REXGEN +#define FLG_REGEX_CHK 0x00002000 +#define FLG_REGEX_SET (FLG_REGEX_CHK | FLG_CRACKING_SET) +#endif /* HAVE_REXGEN */ + /* Batch cracker */ #define FLG_BATCH_CHK 0x00004000 #define FLG_BATCH_SET (FLG_BATCH_CHK | FLG_CRACKING_SET) @@ -128,6 +134,11 @@ /* Parallel processing options */ char *node_str; unsigned int node_min, node_max, node_count, fork; + +#if HAVE_REXGEN +/* regular expression */ + char *regex; +#endif /* HAVE_REXGEN */ }; extern struct options_main options; diff -Naur john-1.8.0/src/regex.cpp john-1.8.0-regex/src/regex.cpp --- john-1.8.0/src/regex.cpp 1970-01-01 01:00:00.000000000 +0100 +++ john-1.8.0-regex/src/regex.cpp 2013-06-27 21:56:16.307359908 +0200 @@ -0,0 +1,66 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 1996-99,2003,2004,2006,2009,2013 by Solar Designer + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * Author if this file is Jan Starke + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + #include "loader.h" + #include "logger.h" + #include "status.h" + #include "recovery.h" + #include "options.h" + #include "cracker.h" + #include "john.h" + #include "external.h" +#ifdef __cplusplus +} +#endif + +#include +#include +#include +#include +#include +#include +#include + + +static void fix_state(void) { +} + +extern "C" +void do_regex_crack(struct db_main *db, char *regex) { + SimpleString buffer; + RexgenOptions rexgen_options; + Iterator* iter = nullptr; + char* word; + + rexgen_options.encoding = CHARSET_UTF8; + rexgen_options.ignore_case = false; + rexgen_options.randomize = false; + + crk_init(db, fix_state, NULL); + + iter = regex_iterator(regex, rexgen_options); + while (iter->next()) { + buffer.clear(); + iter->value(buffer); + buffer.terminate(); + word = (char*) buffer.__get_buffer_address(); + if (ext_filter(word)) { + crk_process_key(word); + } + } + + delete iter; + crk_done(); +} diff -Naur john-1.8.0/src/regex.h john-1.8.0-regex/src/regex.h --- john-1.8.0/src/regex.h 1970-01-01 01:00:00.000000000 +0100 +++ john-1.8.0-regex/src/regex.h 2013-06-27 21:53:40.170585667 +0200 @@ -0,0 +1,26 @@ +/* + * This file is part of John the Ripper password cracker, + * Copyright (c) 1996-98 by Solar Designer + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + */ + +/* + * Regular expression cracker. + */ + +#ifndef _JOHN_REGEX_H +#define _JOHN_REGEX_H + +#include "loader.h" + +/* + * Runs the Regular expression cracker + */ +extern "C" +void do_regex_crack(struct db_main *db, char *regex); + +#endif