Git Product home page Git Product logo

ruleprocessory's Introduction

ruleprocessorY

Main Build CodeQL

Rule Processor Y is a next-gen Rule processor with multibyte character support built for hashcat. It applies rules to wordlists in order to transform them in whichever way the user pleases. The key feature of this ruleprocessor is that it allows a user to quickly do multibyte or multi-character replacements such as replacing the e with é or the other way around for normalization of wordlists.

Requirements

sudo apt-get install build-essential cmake git

Quickstart

If you receive an error regarding your cmake version, edit CMakeLists.txt and lower the cmake_minimum_required to match your version, this will generally not cause an issue.

git clone https://github.com/0xVavaldi/ruleprocessorY
cd ruleprocessorY
cmake .
make
./ruleprocessorY -h
./ruleprocessorY -w rockyou.txt -r example_rules.rule
./ruleprocessorY -w rockyou.txt -r rules/best66.rule --hashcat-input --hashcat-output

If you want to use this with hashcat, you must specify the --hashcat-input flag to accept hashcat-style input files and --hashcat-output if you wish to use the output of the tool in hashcat.

Rule writing

Rules are stored using a tab separated format (TSV), which is CSV, but with tabs. Within each line you can utilize the standard rules you might be familiar with in Hashcat (https://hashcat.net/wiki/doku.php?id=rule_based_attack). An example is shown below:

c
u   $1  $2  $3
l
$1  $2
$2  $0  $0  $0
^a  ^m

Additionally, we support multi-character rules. Allowing the appending, prepending or replacing of multiple characters. To do this we utilize the / delimiter, similar to some unix tools. A known issue is being unable to use the / character. This is a planned feature where we will make use of $HEX[] Below is a sample file with comments explaining the construct in an example.

l   $2022
u   $2000
^prefix     $suffix
s/a/4   sa@     # this is two different formats replacing one character with another, both are supported
s/alpha/beta
o0beta
o/0/beta

Hashcat cross-comptability

Finally, using the --hashcat-input and/or --hashcat-output flag we support hashcat formatted rules (space/no delimiter). This will automatically attempt to parse the rules and convert them into the TSV format. In doing so it will replace tabs with \x09 and spaces with \x20. Hashcat supports this notation and the rules will be cross compatible if you were to replace all tabs in the output file with spaces. (or removing tabs entirely).

Note on duplicate candidates

Candidates matching the original word are never printed unless the : rule is specified. This is done to prevent duplicates. Example: Using l will only print candidates that have an uppercase character and as a result are different from the original plaintext. This can be unfavorable when working with rejection rules. In that case a : must be added as a first rule. An example is shown below where the goal is to reject all candidates containing the word "test". To match case toggled candidates the l rule is added before the match test. To ensure all candidates are printed and not just rules with uppercase the : rule is added, which will force all candidates to be printed.

ruleprocessorY.exe -r rule.txt --optimize-no-op --hashcat-input --hashcat-output > optimized_rule.txt
:
l
!test
$1 $2 $3

Rule Optimizing

Rules generated or used by hashcat can contain contradictions or operations that do not make sense. RuleProcessorY is capable of cleaning up your rules and structuring it out for you. In total we current support 3 forms of optimization. Starting off we can look at some operations that 'do nothing', we refer to this as a no-op (no-operation). Using the --optimize-no-op we remove these.

T0      T0
$1      ]
^1      [

Rules generated or used by hashcat can contain partial contradictions or can be rewritten to be more efficient. This can happen in different ways, but for computational sake we won't entirely rewrite rules. Instead, we will look if the rule can be performed using less operations. The --optimize-same-op will remove these.

ruleprocessorY.exe -r rule.txt --optimize-same-op > optimized_rule.txt
$a      $b      ]
{       }       $b
[       *97     O57
T6      $n      O65
,0      ,6      Y4

The resulting rules could look like this, where operations that don't contribute have been removed:

$a
$b
[   O57
$n  O65
,6  Y4

Finally we will look through all rules and find two rules that perform the same action. This can be a very computational intensive operation and requires 2-3x the size of the wordlist in RAM. A warning is displayed for this. An extra flag has been added to support large rule files, but will take exponentially long to complete. --optimize-similar-op will perform the optimization, and --optimize-slow as an EXTRA flag, will utilize the memory-limited variant. Included is an example of a rule file before and after optimization. It will keep the rule with the least operations it comes across that performs change that has not been seen before. If two rules perform the same operations with the same actions it will take the first occurrence.

Replace rules s that replace one word with another are skipped (s/alpha/beta), s/a/beta is taken into account.

ruleprocessorY.exe -r rule.txt --optimize-similar-op > optimized_rule.txt
ruleprocessorY.exe -r rule.txt --optimize-all > optimized_rule.txt
$a  $b
$ab
$abc
$a  ^a
^a  $a
$$  Z2
$$  $$  $$
D1  $1  $2  $3  D0
$1  D0  $3  D0  $3
[   [   $1  $2  $3
$6  [   $9
[   $6  $9

The optimized version:

$ab
$abc
$a  ^a
$$      Z2
[       [       $1      $2      $3
[       $6      $9

Rule Optimizing / Comparison

Additionally, you can compare one rule against another and optimize rule files against each other. Removing rules from file A that also appear in file B. To do so we can use the --optimize-compare flag. Example command to remove all rules from fordy10k.txt that also appear in best64.rule.

ruleprocessorY.exe --hashcat-input --hashcat-output --optimize-all -r fordy10k.txt --optimize-compare best64.rule

Rule Optimizing with wordlists

Although technically supported - the use is heavily discouraged. Due to the nature of the computing problem, it is nearly impossible to optimize rules for a specific wordlist without spending a significant amount of money or time. The following command will optimize the dive.rule file for the rockyou.txt wordlist. However, expect to use about 350PB of RAM.

ruleprocessorY.exe --hashcat-input --hashcat-output --optimize-all -r dive.rule -w rockyou.txt

Alternatively you can have it be computed on the fly. This uses approximately 7-8GB of RAM, but also takes significantly longer to process. In the end you will gain relatively little extra performance for all the time invested. If you wish to optimize using this, use a very small wordlist.

ruleprocessorY.exe --hashcat-input --hashcat-output --optimize-all -r dive.rule -w rockyou.txt --optimize-slow

Rule Optimizing more

It is possible (alternatively to specifying a wordlist as described above) to optimize a wordlist more. This will use a smaller 'validation dictionary'. Using this method will result in some loss of cracks / founds. In return, you will optimize the rules more. This can be favorable in a few scenarios when working with generated rules that work on edge-cases like @\x02 and do not apply to 'normal passwords' commonly.

Use this with caution.

ruleprocessorY.exe --hashcat-input --hashcat-output --optimize-all -r dive.rule -w rockyou.txt --optimized-words

Optimize debugging

To debug what changes have been made, the --optimize-debug flag can be used. This will display what changes are made to STDERR by default. Adding a file name can force the output to a text-file. --optimize-debug debug.txt. Example output:

Before: $!      o9H     x27
After:  $!      x27
Before: $*      @*      +3
After:  @*      +3
Before: $/      @/      i3k
After:  @/      i3k
Before: $1      +7      D7
After:  $1      D7
Before: $1      D6      *45     '6
After:  $1      *45     '6
Before: $1      DA      @1
After:  DA      @1

Kept:   $$      Z2
Deleted:        $$      $$      $$
Kept:   D1      $1      $2      $3      D0
Deleted:        [       [       $1      $2      $3
Kept:   $6      [       $9
Deleted:        [       $6      $9
Kept:   $1      +0      Z1
Deleted:        +0      $1      $1
Kept:   o2a
Deleted:        $5      o2a     ]
Kept:   $3      $2      $1      D0
Deleted:        [       $3      $2      $1
Kept:   $2      $0      $1      $1      [
Deleted:        [       $2      $0      $1      $1
Kept:   $l      $o      $l
Deleted:        $l      $l      $o      K

The action when a new rule is added is not displayed to not overload the debug output. This can be re-enabled in the code by searching for "Kept new" in main.cpp

ruleprocessory's People

Contributors

0xvavaldi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ruleprocessory's Issues

Unexpected Result with --optimize-no-op

Using Win7 64
ruleprocessorY.exe 1.3
General_Rules.rule Attached

Command used
ruleprocessorY.exe --optimize-no-op --hashcat-input --hashcat-output --optimize-debug Debug.txt -r General_Rules.rule>>General_Rules_optimized.rule

I placed a group of general rules into a file. (General_Rules.rule)

I ran ruleprocessorY.exe with the "optimize-no-op" option.

I also chose to output to a debug file.

When ruleprocessorY.exe started the following was displayed in the command screen (not the debug file).

Unknown rule function [94413]: "0"
Unknown rule function [94414]: "0"
Unknown rule function [233095]: "0"
Unknown rule function [271297]: "0"
Unknown rule function [274805]: "0"
Unknown rule function [325264]: "0"
Unknown rule function [325267]: "0"
Unknown rule function [325268]: "0"

The debug.txt file was empty.

I deleted the original "General_Rules.rule" and I ran ruleprocessorY.exe on the newly created "General_Rules_optimized.rule" expecting there to be no issues found.

However when ruleprocessorY.exe started the following was displayed in the command screen (not the debug file).

Invalid Rule [2879]: "s\x20\    /"
Unknown rule function [4223]: "\"
Unknown rule function [39763]: "\"
Unknown rule function [44280]: "\"
Unknown rule function [90375]: "\"
Unknown rule function [90376]: "\"
Invalid Rule [109822]: "*05     s\x20\  /"
Invalid Rule [110796]: "*13     s\x20\  /"
Invalid Rule [114155]: "*40     s\x20\  /"
Unknown rule function [122559]: "\"
Unknown rule function [146455]: "\"
Unknown rule function [146456]: "\"
Unknown rule function [146457]: "\"
Invalid Rule [185718]: "[       ^C      s\x20\  /"
Invalid Rule [214004]: "K       xB9     s\x20\  /"
Unknown rule function [248536]: "\"
Unknown rule function [263715]: "\"
Unknown rule function [269969]: "\"
Unknown rule function [272078]: "\"
Invalid Rule [273935]: "sF>     Y3      s\x20\  /"
Unknown rule function [298487]: "\"
Unknown rule function [312715]: "\"
Unknown rule function [312716]: "\"
Invalid Rule [315266]: "sS@     sO.     s\x20\  /"

The debug.txt file was empty.

The expected output following the second run with ruleprocessorY.exe would be no unknown or invalid rules displayed within the command screen.

It appears that ruleprocessorY.exe might be creating invalid rules during the "optimize-no-op" process.

No output when using --format-rules

I have tried both of the following commands but ruleprocessorY.exe does not produce an output.

ruleprocessorY.exe --format-rules --delimiter " " -r "rules.rule" >>"formatted_rules.rule"

ruleprocessorY.exe --format-rules --delimiter -r "rules.rule" >>"formatted_rules.rule"

Please can you tell me what I am doing wrong?

Thank you and Request

Hello 0xVavaldi

Firstly thank you very much for ruleprocessorY.exe! Not only is ruleprocessorY.exe a great idea but it also works well.

I wonder if you would please consider two requests?

  1. Please would you enable the user to output Rule:Result to a text file? This would allow the user to experiment with rules and see the result of each in an easy way.

This option would also allow the user to identify problems, undesirable outputs or bad rules.
An example using the new option "--show-rule"

"!ruleprocessorY.exe!" -w passwordlist.txt -r testrule.rule --hashcat-input --show-rule --delimiter : >outputlist.txt

The desired output.txt would be:

$1:password1
$1$2$3:password123
^1:1password
u:PASSWORD
d:passwordpassword
etc...

  1. Please would you enable the user to output the --optimize-debug to a separate file whilst simultaneously cleaning their rule lists?
    An example.

ruleprocessorY.exe --optimize-all --hashcat-input --optimize-debug debugfile.txt -r testrule.rule >>testrule_optimised.rule

The desired output would be:

testrule_optimised.rule (Containing only optimised rules and no debug information)
debugfile.txt (Containing only debug information)

Thank you once again 0xVavaldi for creating ruleprocessorY.exe and especially for sharing it!

Unicode Support

Unicode support for characters seems to be missing. This is a known issue.

Request: Format Rules Only

Format Rules

Please could there be an option to only format the rules? (not carry out any optimizations).

Example. (--format-rules)

ruleprocessorY.exe --format-rules --delimiter " " -r "rules.rule" >>"formatted_rules.rule"

The above would convert:

^x^i^f^e^r^p^^t^s^e^t
to
^x ^i ^f ^e ^r ^p ^
^t ^s ^e ^t

Alternatively:

ruleprocessorY.exe --format-rules --delimiter -r "rules.rule" >>"formatted_rules.rule"

The above would convert:

^x ^i ^f ^e ^r ^p ^_ ^t ^s ^e ^t
to
^x^i^f^e^r^p^_^t^s^e^t

Thank you.

Request: Rule Cleaning for Hashcat.

0xVavaldi would you please consider the following request?

I found ruleprocessorY.exe because I was looking for a rule cleaning tool. I have collected many rules some of which do not work directly with hashcat or produce non-keyboard characters which I would personally never need. Rule lists containing such rules may waste valuable processing/cracking time.

I understand that ruleprocessorY.exe optimizes all rules and not just rules written for hashcat. I had originally assumed that --hashcat-output would remove all rules that hashcat would otherwise reject but this does not seem to be the case.

As ruleprocessorY.exe is awesome for optimizing rules it seems strange that ruleprocessorY.exe does not remove invalid rules, ie remove any rules that hashcat would reject or which produce a non-keyboard character.

I have made various attempts to find and remove such rules but I am not a programmer. However I have managed to find a number of invalid rules, or rules which produce a non-keyboard characters, and remove them myself. However it would be wonderful if ruleprocessorY.exe had an option to do this properly.

Thank you.

Fails to skip invalid rule

read the rule (Sa4) as a valid rule where the valid one should be with lower s (sa4). this invalid rules exists in InsidePro-HashManager.rule file that cames in hashcat rules folder.

this is my command I used to clean my file that contain this and similar rules that start with S:
[ruleprocessorY.exe --optimize-no-op -r ".\input.rule" --hashcat-input --hashcat-output > ruleprocessorY_out.rule]

update error when -r is missing

when the -r value isn't specified correctly as in this example, the error should be updated to be more useful. (Perhaps it's not checking for all required parameters?)

ruleprocessorY.exe hashcat-input --hashcat-output --optimize-compare generated.rule dive.rule > modgen.rule
--optimize-compare has automatically enabled --optimize-similar-op.
--optimize-compare will not check the original file.
Rule file error: "" does not exist.

Help Menu Update

Hi 0xVavaldi

Please could the help menu (ruleprocessorY.exe -h) be updated to show all the new features?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.