[GH-ISSUE #2282] Run several rule-sets sequentially #1528

Closed
opened 2026-10-15 04:19:27 +07:00 by bsakaguchi · 16 comments
Owner

Originally created by @magnumripper on GitHub (Sep 19, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2282

Originally assigned to: @magnumripper, @jfoug on GitHub.

Just an idea. --rules=SECTION,SECTION[,SECTION...]

For example, using --rules=wordlist,single should be the exact same as creating a new section:

[List.Rules:ws]
.include [List.Rules:Wordlist]
.include [List.Rules:Single]

...and then running --rules=ws. I would think we can implement this KISS at some clever level (ie. only touching rules.c and/or pp.c, not eg. wordlist.c) and it would be a pretty sweet option.

Note that this is in no way the same as eg. #2122 or #745, which would run a word through multiple rules. This one is just a way to run two or more rule-sets sequentially, in one session.

Originally created by @magnumripper on GitHub (Sep 19, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2282 Originally assigned to: @magnumripper, @jfoug on GitHub. Just an idea. `--rules=SECTION,SECTION[,SECTION...]` For example, using `--rules=wordlist,single` should be the _exact same_ as creating a new section: ``` [List.Rules:ws] .include [List.Rules:Wordlist] .include [List.Rules:Single] ``` ...and then running `--rules=ws`. I would think we can implement this KISS at some clever level (ie. only touching rules.c and/or pp.c, not eg. wordlist.c) and it would be a pretty sweet option. Note that this is in no way the same as eg. #2122 or #745, which would run a word through multiple rules. This one is just a way to run two or more rule-sets sequentially, in one session.
bsakaguchi 2026-10-15 04:19:27 +07:00
Author
Owner

@jfoug commented on GitHub (Sep 19, 2016):

I like this idea a lot. Again, we need to get into rules 'duplicate-reductions' if possible.

<!-- gh-comment-id:248117486 --> @jfoug commented on GitHub (Sep 19, 2016): I like this idea a lot. Again, we need to get into rules 'duplicate-reductions' if possible.
Author
Owner

@jfoug commented on GitHub (Sep 21, 2016):

the KISS method is simply to make a quick change in rpp_init() I can get this done in just a few minutes. Do you want me to make a branch for this, or just check it in? We might expand this a LOT. This might be a good way to handle the rule on rule stacking also. Turning rpp_init into a simple 'expression' parser.

So we could handle:

r              (normal rule, current method)
:r             (inline rule)
r1,r2,r3    (3 concatentated rule sets)
r1,:r2       (a ruleset and an inline rule)
r1*r2       (This would be 'cross' multiplied.  I.e.  each rules r2 appended to each rule from r1)
:r1*r2      (the inline rule r1 where each rule from r2 is appended)

@magnumripper can you chime in on any of these additional ideas ( @frank-dittrich your usage insight is greatly wanted also).

NOTE, for a start, I will do the ',' addition only, and we can see how it goes.

<!-- gh-comment-id:248665331 --> @jfoug commented on GitHub (Sep 21, 2016): the KISS method is simply to make a quick change in rpp_init() I can get this done in just a few minutes. Do you want me to make a branch for this, or just check it in? We might expand this a LOT. This might be a good way to handle the rule on rule stacking also. Turning rpp_init into a simple 'expression' parser. So we could handle: ``` r (normal rule, current method) :r (inline rule) r1,r2,r3 (3 concatentated rule sets) r1,:r2 (a ruleset and an inline rule) r1*r2 (This would be 'cross' multiplied. I.e. each rules r2 appended to each rule from r1) :r1*r2 (the inline rule r1 where each rule from r2 is appended) ``` @magnumripper can you chime in on any of these additional ideas ( @frank-dittrich your usage insight is greatly wanted also). NOTE, for a start, I will do the ',' addition only, and we can see how it goes.
Author
Owner

@jfoug commented on GitHub (Sep 21, 2016):

NOTE, if we are going to allow 'mixing' of : and , * in the command arg, then there will have to be some form of delimiter for starting and ending the : inline rules. It may be better to not allow 'mixing' of the inline and .conf sections. But mixing , and * should be easy but may require using () grouping. But with this KISS patch, rules command line arg now handles:

-rules    (alias for -rules=Wordlist)
-rules=section
-rules=:inline_rule
-rules=section1,section2,.....sectionN
$ git diff rpp.c
diff --git a/src/rpp.c b/src/rpp.c
index db40971..a083c1a 100644
--- a/src/rpp.c
+++ b/src/rpp.c
@@ -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;
@@ -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";
@@ -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;
@@ -45,6 +46,35 @@ 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;
+
+               cfg_cur->cfg_name = subsection;
+               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)) {

<!-- gh-comment-id:248684372 --> @jfoug commented on GitHub (Sep 21, 2016): NOTE, if we are going to allow 'mixing' of : and , \* in the command arg, then there will have to be some form of delimiter for starting and ending the : inline rules. It may be better to not allow 'mixing' of the inline and .conf sections. But mixing , and \* should be easy but may require using () grouping. But with this KISS patch, rules command line arg now handles: ``` -rules (alias for -rules=Wordlist) -rules=section -rules=:inline_rule -rules=section1,section2,.....sectionN ``` ``` diff $ git diff rpp.c diff --git a/src/rpp.c b/src/rpp.c index db40971..a083c1a 100644 --- a/src/rpp.c +++ b/src/rpp.c @@ -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; @@ -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"; @@ -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; @@ -45,6 +46,35 @@ 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; + + cfg_cur->cfg_name = subsection; + 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)) { ```
Author
Owner

@magnumripper commented on GitHub (Sep 21, 2016):

Wow, yeah the additional ideas are way cool as long as it doesn't get messy in terms of ambiguity. Can an inline rule contain a ,? I don't think so, can't find it right now even in Hashcat rules.

If you are pretty sure everything is solid, just push it to the main branch. But there's no harm in making a topic branch if you have any doubt at all. I'm not sure what "could" go very wrong but resuming comes to mind... How about we did --rules=setA,setB,setC and then stopped the job during setB. Will resuming be correct?

<!-- gh-comment-id:248692378 --> @magnumripper commented on GitHub (Sep 21, 2016): Wow, yeah the additional ideas are way cool as long as it doesn't get messy in terms of ambiguity. Can an inline rule contain a `,`? I don't think so, can't find it right now even in Hashcat rules. If you are pretty sure everything is solid, just push it to the main branch. But there's no harm in making a topic branch if you have any doubt at all. I'm not sure what "could" go very wrong but resuming comes to mind... How about we did `--rules=setA,setB,setC` and then stopped the job during setB. Will resuming be correct?
Author
Owner

@jfoug commented on GitHub (Sep 21, 2016):

Can an inline rule contain a ,? I don't think so

Yup. ,N is a newer addition, it is a HC rule, but is now part of jumbo even without specifying HC.

+-------+------------------+-------+------------+------------------------+-----+
|  ,N   | replace char N   |  ,2   | P@sS       |   P@@S                 |  1  |
|       | with prior char  |       |            |                        |     |
+-------+------------------+-------+------------+------------------------+-----+
<!-- gh-comment-id:248695575 --> @jfoug commented on GitHub (Sep 21, 2016): > Can an inline rule contain a ,? I don't think so Yup. ,N is a newer addition, it is a HC rule, but is now part of jumbo even without specifying HC. ``` +-------+------------------+-------+------------+------------------------+-----+ | ,N | replace char N | ,2 | P@sS | P@@S | 1 | | | with prior char | | | | | +-------+------------------+-------+------------+------------------------+-----+ ```
Author
Owner

@jfoug commented on GitHub (Sep 21, 2016):

How about we did --rules=setA,setB,setC and then stopped the job during setB. Will resuming be correct?

I 'assume' there will be zero impact on resuming. The ---rules=setA,setB,setC switch is stored in the .rec file. When we 'run', we are not using any config section, but BUILDING our own simulated section (name 'changes' in the rules so error messages make sense), and then wordlist/pp runs this special built . Upon resume, the rpp_init will still load the same data from set[ABC] in the same order, so there should be no issue resuming.

If you are pretty sure everything is solid

I am pretty sure this is AS solid as the inline rules code, which has caused no problems, and the first push is still the way the code stands today. Yes, I did make a change to that original 'inline' rule code in this change (the sizeof value used for alignment), but it is still the same code. I will validate that resuming IS working (I would be absolutely shocked if it had problems). Also I will get it put into documentation, and then pushed.

NOTE, This code handles --rules=setA and --rules=setA,setB and --rules=setA,setB,setC,setD.... all just fine. The Rules X Rules code is not part of what is done here. However, I think this is the right place to do that when the time comes to do it.

<!-- gh-comment-id:248709865 --> @jfoug commented on GitHub (Sep 21, 2016): > How about we did --rules=setA,setB,setC and then stopped the job during setB. Will resuming be correct? I 'assume' there will be zero impact on resuming. The `---rules=setA,setB,setC` switch is stored in the .rec file. When we 'run', we are not using any config section, but BUILDING our own simulated section (name 'changes' in the rules so error messages make sense), and then wordlist/pp runs this special built . Upon resume, the rpp_init will still load the same data from set[ABC] in the same order, so there should be no issue resuming. > If you are pretty sure everything is solid I am pretty sure this is AS solid as the inline rules code, which has caused no problems, and the first push is still the way the code stands today. Yes, I did make a change to that original 'inline' rule code in this change (the sizeof value used for alignment), but it is still the same code. I will validate that resuming IS working (I would be absolutely shocked if it had problems). Also I will get it put into documentation, and then pushed. NOTE, This code handles `--rules=setA` and `--rules=setA,setB` and `--rules=setA,setB,setC,setD....` all just fine. The Rules X Rules code is not part of what is done here. However, I think this is the right place to do that when the time comes to do it.
Author
Owner

@magnumripper commented on GitHub (Sep 21, 2016):

Upon resume, the rpp_init will still load the same data

This makes sense. The rec file stores the rule number of the expanded rule-set. We are just adding a way to expand it.

<!-- gh-comment-id:248726964 --> @magnumripper commented on GitHub (Sep 21, 2016): > Upon resume, the rpp_init will still load the same data This makes sense. The rec file stores the rule number of the _expanded_ rule-set. We are just adding a way to expand it.
Author
Owner

@magnumripper commented on GitHub (Sep 21, 2016):

That code you posted is friggin' beautiful! Like I said, I would think we can implement this KISS at some clever level 😎

<!-- gh-comment-id:248728082 --> @magnumripper commented on GitHub (Sep 21, 2016): That code you posted is friggin' beautiful! Like I said, _I would think we can implement this KISS at some clever level_ 😎
Author
Owner

@magnumripper commented on GitHub (Sep 25, 2016):

I haven't made any real regression tests, just tried this out in various ways. This feature rocks! No more temporary john.conf sections just to run a one-off of some particular rule-sets in some particular order.

<!-- gh-comment-id:249420712 --> @magnumripper commented on GitHub (Sep 25, 2016): I haven't made any real regression tests, just tried this out in various ways. This feature rocks! No more temporary john.conf sections just to run a one-off of some particular rule-sets in some particular order.
Author
Owner

@jfoug commented on GitHub (Sep 25, 2016):

Im gonna close this. With ca9cb18 the code is there for a serial set of rules. If there are regression bugs, we can open new issues. Also, this issue was not for rulesA X rulesB work. This code insertion location is probably the right place, but that logic does need to be thought out a lot better than this.

NOTE, this will generate duplicate rules (word results), and does not contain any code to remove those dupes.

<!-- gh-comment-id:249425186 --> @jfoug commented on GitHub (Sep 25, 2016): Im gonna close this. With ca9cb18 the code is there for a serial set of rules. If there are regression bugs, we can open new issues. Also, this issue was not for rulesA X rulesB work. This code insertion location is probably the right place, but that logic does need to be thought out a lot better than this. NOTE, this will generate duplicate rules (word results), and does not contain any code to remove those dupes.
Author
Owner

@magnumripper commented on GitHub (Sep 25, 2016):

NOTE, this will generate duplicate rules (word results), and does not contain any code to remove those dupes.

But the code we already have for that should work... and it almost does:

$ ../run/john -stdout -rules=wordlist,single -pipe -log-stderr -v=1 <<< magnum
0:00:00:00 Command line: ../run/john --stdout --rules=wordlist,single --pipe --log-stderr --verbosity=1 
0:00:00:00 - UTF-8 input encoding enabled
0:00:00:00 - Passwords will be stored UTF-8 encoded in .pot file
0:00:00:00 Proceeding with wordlist mode
0:00:00:00 - Rules: wordlist,single
0:00:00:00 - duplicate rule removed at line 699: :
0:00:00:00 - 1186 preprocessed word mangling rules were reduced by dropping 0 rules
0:00:00:00 - 1186 preprocessed word mangling rules
897p 0:00:00:00 0.00% 89700p/s magnum1900

It says it removes the dupe : rule, but then it doesn't (it actually doesn't, I checked). I'll see if I can make the normal dupe reduction gears to work with us.

<!-- gh-comment-id:249444705 --> @magnumripper commented on GitHub (Sep 25, 2016): > NOTE, this will generate duplicate rules (word results), and does not contain any code to remove those dupes. But the code we already have for that should work... and it almost does: ``` $ ../run/john -stdout -rules=wordlist,single -pipe -log-stderr -v=1 <<< magnum 0:00:00:00 Command line: ../run/john --stdout --rules=wordlist,single --pipe --log-stderr --verbosity=1 0:00:00:00 - UTF-8 input encoding enabled 0:00:00:00 - Passwords will be stored UTF-8 encoded in .pot file 0:00:00:00 Proceeding with wordlist mode 0:00:00:00 - Rules: wordlist,single 0:00:00:00 - duplicate rule removed at line 699: : 0:00:00:00 - 1186 preprocessed word mangling rules were reduced by dropping 0 rules 0:00:00:00 - 1186 preprocessed word mangling rules 897p 0:00:00:00 0.00% 89700p/s magnum1900 ``` It says it removes the dupe `:` rule, but then it doesn't (it actually doesn't, I checked). I'll see if I can make the normal dupe reduction gears to work with us.
Author
Owner

@jfoug commented on GitHub (Oct 6, 2016):

Did some debugging, and the id was always 0. This should fix things.

f1d1b09

<!-- gh-comment-id:252097664 --> @jfoug commented on GitHub (Oct 6, 2016): Did some debugging, and the id was always 0. This should fix things. f1d1b09
Author
Owner

@magnumripper commented on GitHub (Oct 6, 2016):

Great! Indeed it does.

<!-- gh-comment-id:252110509 --> @magnumripper commented on GitHub (Oct 6, 2016): Great! Indeed it does.
Author
Owner

@jfoug commented on GitHub (Oct 6, 2016):

I might still add the r1*r2 This would be r1.1+r2.1 , r1.1+r2.2 , r1.1+r2.3 ... r1.n+r2.m

i.e. each of rule set 1 with each of rule set 2 appended.

Note, this could very easily be something that allows a user to crash the system, since it is exponential growth. There would need to be some form of checking added for max size. BUT it should be pretty easy to do this in nearly the same manner as for the rule + rule (i.e. with the comma) that was just added.

<!-- gh-comment-id:252113142 --> @jfoug commented on GitHub (Oct 6, 2016): I might still add the r1*r2 This would be r1.1+r2.1 , r1.1+r2.2 , r1.1+r2.3 ... r1.n+r2.m i.e. each of rule set 1 with each of rule set 2 appended. Note, this could very easily be something that allows a user to crash the system, since it is exponential growth. There would need to be some form of checking added for max size. BUT it should be pretty easy to do this in nearly the same manner as for the rule + rule (i.e. with the comma) that was just added.
Author
Owner

@magnumripper commented on GitHub (Oct 6, 2016):

We can tax the system already using PP things like [a-z][a-z][a-z][a-z](...) so I don't think that's much of a problem - as long as we fail with some relevant message like "out of memory".

<!-- gh-comment-id:252114258 --> @magnumripper commented on GitHub (Oct 6, 2016): We can tax the system already using PP things like `[a-z][a-z][a-z][a-z](...)` so I don't think that's much of a problem - as long as we fail with some relevant message like "out of memory".
Author
Owner

@magnumripper commented on GitHub (Oct 6, 2016):

Things get tricky though, with implicit M, reject rules and other things.

<!-- gh-comment-id:252114372 --> @magnumripper commented on GitHub (Oct 6, 2016): Things get tricky though, with implicit M, reject rules and other things.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1528
No description provided.