Skip to content

Commit

Permalink
rules: now multiple rulesets can be specified on command line
Browse files Browse the repository at this point in the history
  • Loading branch information
jfoug committed Sep 22, 2016
1 parent 512db2e commit ca9db18
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
5 changes: 3 additions & 2 deletions doc/OPTIONS
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ argument (if supported for a given option).
The supported options are as follows, square brackets denote optional
arguments:

--single[=(SECTION|:rule)] "single crack" mode
--single[=(SECTION[,SECTION2,....,SECTIONn]|:rule)] "single crack" mode

Enables the "single crack" mode, using rules from the configuration
file section [List.Rules:Single]. If --single=Single_2 then the rules
Expand Down Expand Up @@ -61,7 +61,8 @@ attacked. Note that by default, some rules are applied too (see john.conf
Input data in a character encoding other than the default 'raw'. See also
doc/ENCODINGS. --list=encodings gives a list of all handled encodings.

--rules[=(SECTION|:rule)] enable word mangling rules for wordlist mode
--rules[=(SECTION[,SECTION2,....,SECTIONn]|:rule)] enable word mangling rules
(available in wordlist and prince modes)

Enables word mangling rules that are read from the specified section, which
defaults to [List.Rules:Wordlist] if not given.
Expand Down
5 changes: 3 additions & 2 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,16 @@ static struct opt_entry opt_list[] = {
"Homepage: http://www.openwall.com/john/\n" \
"\n" \
"Usage: %s [OPTIONS] [PASSWORD-FILES]\n" \
"--single[=(SECTION|:rule)] \"single crack\" mode\n" \
"--single[=(SECTION[,S2,..,Sn]|:rule)] \"single crack\" mode\n" \
"--wordlist[=FILE] --stdin wordlist mode, read words from FILE or stdin\n" \
" --pipe like --stdin, but bulk reads, and allows rules\n" \
"--loopback[=FILE] like --wordlist, but extract words from a .pot file\n" \
"--dupe-suppression suppress all dupes in wordlist (and force preload)\n" \
PRINCE_USAGE \
"--encoding=NAME input encoding (eg. UTF-8, ISO-8859-1). See also\n" \
" doc/ENCODING and --list=hidden-options.\n" \
"--rules[=(SECTION|:rule)] enable word mangling rules for wordlist or PRINCE\n" \
"--rules[=(SECTION[,S2,..,Sn]|:rule)] enable word mangling rules for\n" \
" wordlist or PRINCE modes\n" \
"--incremental[=MODE] \"incremental\" mode [using section MODE]\n" \
"--mask[=MASK] mask mode using MASK (or default from john.conf)\n" \
"--markov[=OPTIONS] \"Markov\" mode (see doc/MARKOV)\n" \
Expand Down
35 changes: 32 additions & 3 deletions src/rpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "rpp.h"
#include "logger.h"
#include "common.h" /* for atoi16 */
#include "misc.h" /* for strtokm */
#include "memdbg.h"

int rpp_real_run = 0;
Expand All @@ -22,8 +23,8 @@ int rpp_init(struct rpp_context *ctx, char *subsection)
ctx->refs_count = 0;
if (*subsection == ':') {
char *p, *buf;
const int sz = sizeof(struct cfg_line);
struct cfg_line *cfg_cur = mem_calloc_tiny(sz, 8);
const int sz = sizeof(struct cfg_line), al = sizeof(struct cfg_line *);
struct cfg_line *cfg_cur = mem_calloc_tiny(sz, al);

buf = str_alloc_copy(subsection+1);
cfg_cur->cfg_name = "Command Line Rule";
Expand All @@ -35,7 +36,7 @@ int rpp_init(struct rpp_context *ctx, char *subsection)
while (p && *p) {
*p++ = 0;
if (!p[0]) continue;
cfg_cur->next = mem_calloc_tiny(sz, 8);
cfg_cur->next = mem_calloc_tiny(sz, al);
cfg_cur = cfg_cur->next;
cfg_cur->cfg_name = "Command Line Rule";
cfg_cur->data = p;
Expand All @@ -45,6 +46,34 @@ int rpp_init(struct rpp_context *ctx, char *subsection)
}
ctx->count = -1;
return 0;
} else if (strchr(subsection, ',')) {
char *buf = str_alloc_copy(subsection), *cp;
const int sz = sizeof(struct cfg_line), al = sizeof(struct cfg_line *);
struct cfg_line *cfg_cur = mem_calloc_tiny(sz, al);
int first = 1;

ctx->input = cfg_cur;
cp = strtokm(buf, ",");
while (cp) {
struct cfg_line *lp;
if ((list = cfg_get_list(SECTION_RULES, cp))==NULL)
return 1;
lp = list->head;
while (lp) {
if (!first) {
cfg_cur->next = mem_calloc_tiny(sz, al);
cfg_cur = cfg_cur->next;
}
first = 0;
cfg_cur->cfg_name = cp;
cfg_cur->data = lp->data;
cfg_cur->number = lp->number;
lp = lp->next;
}
cp = strtokm(NULL, ",");
}
ctx->count = -1;
return 0;
} else
if ((list = cfg_get_list(SECTION_RULES, subsection)))
if ((ctx->input = list->head)) {
Expand Down

0 comments on commit ca9db18

Please sign in to comment.