diff --git a/README.md b/README.md index 35e0a53..2b13cdb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - Supports multiple transformations and operations with a template file. ``` -Usage of Password Transformation Tool (ptt) version (0.2.3): +Usage of Password Transformation Tool (ptt) version (0.2.4): ptt [options] [...] Accepts standard input and/or additonal arguments. @@ -36,7 +36,7 @@ Options: -r value Only keep items not in a file. -rm string - Replacement mask for transformations if applicable. (default "uldsb") + Replacement mask for transformations if applicable. (default "uldsbt") -t string Transformation to apply to input. -tf value @@ -53,7 +53,7 @@ Options: -w int Number of words to generate for passphrases if applicable. -The -f, -k, -r, -tf, -tp, and -u flags can be used multiple times and together. +The -f, -k, -r, -tf, -tp, and -u flags can be used multiple times, together, and with files or directories. Transformation Modes: -t append @@ -84,7 +84,7 @@ Transformation Modes: Transforms input into overwrite rules starting at index. -t passphrase -w [words] -tf [file] Transforms input by randomly generating passphrases with a given number of words and separators from a file. - -t pop -rm [uldsb] + -t pop -rm [uldsbt] Transforms input by generating tokens from popping strings at character boundaries. -t prepend Transforms input into prepend rules. @@ -104,7 +104,7 @@ Transformation Modes: ## Getting Started: -Documentation on usage and examples can be found in the `/docs` directory or on the repository here: [link](https://github.com/JakeWnuk/ptt/tree/main/docs) +Documentation on usage and examples can be found in the `/docs/USAGE.md` directory or on the repository here: [link](https://github.com/JakeWnuk/ptt/tree/main/docs/USAGE.md) ### Install: diff --git a/docs/MASKS.md b/docs/MASKS.md deleted file mode 100644 index 88b543c..0000000 --- a/docs/MASKS.md +++ /dev/null @@ -1,72 +0,0 @@ -# Password Transformation Tool (PTT) Mask Creation Guide -## Version 0.1.0 - -### Table of Contents -1. [Introduction](#introduction) -2. [Mask Creation](#mask-creation) -3. [Mask Matching](#mask-matching) -4. [Removing Characters by Mask](#removing-characters-by-mask) -5. [Creating Retain/Partial Masks](#creating-retainpartial-masks) - -### Introduction -This document describes the ways to use PTT to create `Hashcat` compatible -masks. There are several ways to use masks in PTT: - -- `Mask Creation`: Create a mask from a given string. -- `Mask Matching`: Match a mask to a given string. -- `Removing Characters by Mask`: Remove characters from a given string by a mask. -- `Creating Retain/Partial Masks`: Create a mask that retains only certain keywords. - -All modes support multibyte characters and can properly convert them. One -transformation can be used at a time. - -> [!CAUTION] -> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. - -### Mask Creation -Masks replace characters in a string with a common character. The syntax to -create a mask is as follows: -``` -ptt -f -t mask -rm -v -``` -Where `` can be any of the following: -- `u`: Uppercase characters -- `l`: Lowercase characters -- `d`: Digits -- `s`: Special characters -- `b`: Byte characters -- Multiple characters can be combined to create a mask. - -The default value is `uldsb` for all characters. The `-v` flag is optional and -if provided, will print the length of the original string and its character -complexity. The format will be `:length:complexity` appended to the end of the -output. - -### Mask Matching -Masks can be matched to a given string to determine if the string matches the -mask. The syntax to match a mask is as follows: -``` -ptt -f -t match -tf -``` -Where `` is the file containing the mask to match. The mask file -should only contain valid masks. The output will be all of the strings that -match the masks. - -### Removing Characters by Mask -Characters can be removed from a string by a mask. The syntax to remove -characters by mask is as follows: -``` -ptt -f -t remove -rm -``` -Where `` is the mask to remove from the string. The output will -be the string with the characters removed. - -### Creating Retain/Partial Masks -Retain masks can be created to retain only certain keywords in a string. The -syntax to create a retain mask is as follows: -``` -ptt -f -t retain -rm -tf -``` -Where `` is the mask to retain and `` is the file -containing the keywords to retain. The output will be the mask with only the -keywords retained. diff --git a/docs/MISC.md b/docs/MISC.md deleted file mode 100644 index e379f11..0000000 --- a/docs/MISC.md +++ /dev/null @@ -1,73 +0,0 @@ -# Password Transformation Tool (PTT) Misc Creation Guide -## Version 0.1.0 - -### Table of Contents -1. [Introduction](#introduction) -2. [Encoding and Decoding](#encoding-and-decoding) -3. [Hex and Dehex](#hex-and-dehex) -4. [Substrings](#substrings) - -### Introduction -This document describes the ways to use PTT to create miscellaneous transformations. -There are several types that can be created using PTT: - -- `Encoding and Decoding`: This transforms input to and from URL, HTML, and Unicode escaped strings. -- `Hex and Dehex`: This transforms input to and from `$HEX[....]` strings. - -All modes support multibyte characters and can properly convert them. One -transformation can be used at a time. - -> [!CAUTION] -> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. - -### Encoding and Decoding -This mode allows encoding and decoding of input to and from URL, HTML, and Unicode escaped strings. -The syntax is as follows: -``` -ptt -f -t encode -``` -or -``` -ptt -f -t decode -``` -The following table shows the supported transformations: - -| Transformation | Description | Input Example | Output Example | -| --- | --- | --- | --- | -| `url` | URL encoding | `https://www.example.com` | `https%3A%2F%2Fwww.example.com` | -| `html` | HTML encoding | `` | `<html>` | -| `unicode` | Unicode encoding | `Hello😎` | `Hello\u1f60e` | - -### Hex and Dehex -This mode allows encoding and decoding of input to and from `$HEX[....]` strings. -The syntax is as follows: -``` -ptt -f -t hex -``` -or -``` -ptt -f -t dehex -``` -The following table shows the supported transformations: - -| Transformation | Description | Input Example | Output Example | -| --- | --- | --- | --- | -| `hex` | Hex encoding | `Hello` | `$HEX[48656c6c6f]` | -| `dehex` | Hex decoding | `$HEX[48656c6c6f]` | `Hello` | - -### Substrings -This mode allows extracting substrings from the input based on position. The syntax is as follows: -``` -ptt -f -t substring -i -``` -or -``` -ptt -f -t substring -i - -``` - -This transformation extracts the substring from the input based on the provided -index. If the end index is greater than the length of the input, it will be -changed to the length of the input. - -This transformation can be used to extract specific parts of the input for -further processing. diff --git a/docs/RULES.md b/docs/RULES.md deleted file mode 100644 index 5652413..0000000 --- a/docs/RULES.md +++ /dev/null @@ -1,101 +0,0 @@ -# Password Transformation Tool (PTT) Rules Creation Guide -## Version 0.1.0 - -### Table of Contents -1. [Introduction](#introduction) -2. [Append Rules](#append-rules) -3. [Prepend Rules](#prepend-rules) -4. [Toggle Rules](#toggle-rules) -5. [Insert Rules](#insert-rules) -6. [Overwrite Rules](#overwrite-rules) - -### Introduction -This document describes the ways to use PTT to create `Hashcat` compatible -rules. There are several types of rules that can be created using PTT: - -- `Append Rules`: Append a string to the end of the password. -- `Append Remove Rules`: Remove characters from the end of the password before appending a string. -- `Append Shift Rules`: Shift the characters of the password to the right before appending a string. -- `Prepend Rules`: Prepend a string to the beginning of the password. -- `Prepend Remove Rules`: Remove characters from the beginning of the password before prepending a string. -- `Prepend Shift Rules`: Shift the characters of the password to the left before prepending a string. -- `Toggle Rules`: Toggle the case of the password. -- `Insert Rules`: Insert a string at a specific position in the password. -- `Overwrite Rules`: Overwrite a string at a specific position in the password. - -All modes support multibyte characters and can properly convert them. One -transformation can be used at a time. - -> [!CAUTION] -> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. - -### Append Rules -Append rules are used to append a string to the end of the password. The syntax for an append rule is as follows: -``` -ptt -f -t append -``` - -The append mode also has two additional options: -- `append-remove`: Remove characters from the end of the password before appending a string. -- `append-shift`: Shift the characters of the password to the right before appending a string. - -The syntax for an append-remove rule is as follows: -``` -ptt -f -t append-remove -``` - -The syntax for an append-shift rule is as follows: -``` -ptt -f -t append-shift -``` - -### Prepend Rules -Prepend rules are used to prepend a string to the beginning of the password. The syntax for a prepend rule is as follows: -``` -ptt -f -t prepend -``` - -The prepend mode also has two additional options: -- `prepend-remove`: Remove characters from the beginning of the password before prepending a string. -- `prepend-shift`: Shift the characters of the password to the left before prepending a string. - -The syntax for a prepend-remove rule is as follows: -``` -ptt -f -t prepend-remove -``` - -The syntax for a prepend-shift rule is as follows: -``` -ptt -f -t prepend-shift -``` - -### Toggle Rules -Toggle rules are used to toggle the case of the password. The syntax for a toggle rule is as follows: -``` -ptt -f -t toggle -i -``` -Where `` is the starting index of the toggle pattern. If no index is provided, -the toggle pattern will start at the beginning of the password. The `` -can also accept range values in the format of `start-end`. For example, `1-5` will -print output for the toggle transformation starting from index 1 to 5. - -### Insert Rules -Insert rules are used to insert a string at a specific position in the password. The syntax for an insert rule is as follows: -``` -ptt -f -t insert -i -``` -Where `` is the position where the string will be inserted. If no index is provided, -the string will be inserted at the beginning of the password. The `` -can also accept range values in the format of `start-end`. For example, `1-5` will -print output for the insert transformation starting from index 1 to 5. - -### Overwrite Rules -Overwrite rules are used to overwrite a string at a specific position in the password. The syntax for an overwrite rule is as follows: -``` -ptt -f -t overwrite -i -``` -Where `` is the position where the string will be overwritten. If no index is provided, -the string will be overwritten at the beginning of the password. The `` -can also accept range values in the format of `start-end`. For example, `1-5` will -print output for the overwrite transformation starting from index 1 to 5. - diff --git a/docs/USAGE.md b/docs/USAGE.md index 820e041..7f2f261 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -1,7 +1,8 @@ # Password Transformation Tool (PTT) Usage Guide -## Version 0.2.2 +## Version 0.2.4 ### Table of Contents +#### Getting Started 1. [Introduction](#introduction) 2. [Installation](#installation) 3. [Usage](#usage) @@ -9,6 +10,36 @@ 5. [Contributing](#contributing) 6. [License](#license) +#### Mask Creation Guide +1. [Mask Creation Introduction](#mask-creation-introduction) +2. [Mask Creation](#mask-creation) +3. [Mask Matching](#mask-matching) +4. [Removing Characters by Mask](#removing-characters-by-mask) +5. [Creating Retain/Partial Masks](#creating-retainpartial-masks) + +### Rule Creation Guide +1. [Rule Creation Introduction](#rule-creation-introduction) +2. [Append Rules](#append-rules) +3. [Prepend Rules](#prepend-rules) +4. [Toggle Rules](#toggle-rules) +5. [Insert Rules](#insert-rules) +6. [Overwrite Rules](#overwrite-rules) + +### Wordlist Creation Guide +1. [Wordlist Creation Introduction](#wordlist-creation-introduction) +2. [Direct Swapping](#direct-swapping) +3. [Token Popping](#token-popping) +4. [Token Swapping](#token-swapping) +5. [Passphrases](#passphrases) + +### Misc Creation Guide +1. [Misc Creation Introduction](#misc-creation-introduction) +2. [Encoding and Decoding](#encoding-and-decoding) +3. [Hex and Dehex](#hex-and-dehex) +4. [Substrings](#substrings) + +## Getting Started + ### Introduction The Password Transformation Tool (PTT) is a command-line utility that allows users to transform passwords using a variety of methods. This guide will @@ -79,6 +110,7 @@ There are some additional notes when importing data: The `-f`, `-k`, `-r`, `-tf`, `-tp`, and `-u` flags can be used multiple times and have their collective values combined. The rest of the flags can only be used once. +These flags work with files and directories. #### Options: - `-b`: Bypass map creation and use stdout as primary output. @@ -301,3 +333,310 @@ when contributing to this project. ### License This project is licensed under the MIT License - see the LICENSE file for details. +## Mask Creation Guide + +### Mask Creation Introduction +This document describes the ways to use PTT to create `Hashcat` compatible +masks. There are several ways to use masks in PTT: + +- `Mask Creation`: Create a mask from a given string. +- `Mask Matching`: Match a mask to a given string. +- `Removing Characters by Mask`: Remove characters from a given string by a mask. +- `Creating Retain/Partial Masks`: Create a mask that retains only certain keywords. + +All modes support multibyte characters and can properly convert them. One +transformation can be used at a time. + +> [!CAUTION] +> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. + +### Mask Creation +Masks replace characters in a string with a common character. The syntax to +create a mask is as follows: +``` +ptt -f -t mask -rm -v +``` +Where `` can be any of the following: +- `u`: Uppercase characters +- `l`: Lowercase characters +- `d`: Digits +- `s`: Special characters +- `b`: Byte characters +- Multiple characters can be combined to create a mask. + +The default value is `uldsb` for all characters. The `-v` flag is optional and +if provided, will print the length of the original string and its character +complexity. The format will be `:length:complexity` appended to the end of the +output. + +### Mask Matching +Masks can be matched to a given string to determine if the string matches the +mask. The syntax to match a mask is as follows: +``` +ptt -f -t match -tf +``` +Where `` is the file containing the mask to match. The mask file +should only contain valid masks. The output will be all of the strings that +match the masks. + +### Removing Characters by Mask +Characters can be removed from a string by a mask. The syntax to remove +characters by mask is as follows: +``` +ptt -f -t remove -rm +``` +Where `` is the mask to remove from the string. The output will +be the string with the characters removed. + +### Creating Retain/Partial Masks +Retain masks can be created to retain only certain keywords in a string. The +syntax to create a retain mask is as follows: +``` +ptt -f -t retain -rm -tf +``` +Where `` is the mask to retain and `` is the file +containing the keywords to retain. The output will be the mask with only the +keywords retained. + +## Rules Creation Guide + +### Rule Creation Introduction +This document describes the ways to use PTT to create `Hashcat` compatible +rules. There are several types of rules that can be created using PTT: + +- `Append Rules`: Append a string to the end of the password. +- `Append Remove Rules`: Remove characters from the end of the password before appending a string. +- `Append Shift Rules`: Shift the characters of the password to the right before appending a string. +- `Prepend Rules`: Prepend a string to the beginning of the password. +- `Prepend Remove Rules`: Remove characters from the beginning of the password before prepending a string. +- `Prepend Shift Rules`: Shift the characters of the password to the left before prepending a string. +- `Toggle Rules`: Toggle the case of the password. +- `Insert Rules`: Insert a string at a specific position in the password. +- `Overwrite Rules`: Overwrite a string at a specific position in the password. + +All modes support multibyte characters and can properly convert them. One +transformation can be used at a time. + +> [!CAUTION] +> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. + +### Append Rules +Append rules are used to append a string to the end of the password. The syntax for an append rule is as follows: +``` +ptt -f -t append +``` + +The append mode also has two additional options: +- `append-remove`: Remove characters from the end of the password before appending a string. +- `append-shift`: Shift the characters of the password to the right before appending a string. + +The syntax for an append-remove rule is as follows: +``` +ptt -f -t append-remove +``` + +The syntax for an append-shift rule is as follows: +``` +ptt -f -t append-shift +``` + +### Prepend Rules +Prepend rules are used to prepend a string to the beginning of the password. The syntax for a prepend rule is as follows: +``` +ptt -f -t prepend +``` + +The prepend mode also has two additional options: +- `prepend-remove`: Remove characters from the beginning of the password before prepending a string. +- `prepend-shift`: Shift the characters of the password to the left before prepending a string. + +The syntax for a prepend-remove rule is as follows: +``` +ptt -f -t prepend-remove +``` + +The syntax for a prepend-shift rule is as follows: +``` +ptt -f -t prepend-shift +``` + +### Toggle Rules +Toggle rules are used to toggle the case of the password. The syntax for a toggle rule is as follows: +``` +ptt -f -t toggle -i +``` +Where `` is the starting index of the toggle pattern. If no index is provided, +the toggle pattern will start at the beginning of the password. The `` +can also accept range values in the format of `start-end`. For example, `1-5` will +print output for the toggle transformation starting from index 1 to 5. + +### Insert Rules +Insert rules are used to insert a string at a specific position in the password. The syntax for an insert rule is as follows: +``` +ptt -f -t insert -i +``` +Where `` is the position where the string will be inserted. If no index is provided, +the string will be inserted at the beginning of the password. The `` +can also accept range values in the format of `start-end`. For example, `1-5` will +print output for the insert transformation starting from index 1 to 5. + +### Overwrite Rules +Overwrite rules are used to overwrite a string at a specific position in the password. The syntax for an overwrite rule is as follows: +``` +ptt -f -t overwrite -i +``` +Where `` is the position where the string will be overwritten. If no index is provided, +the string will be overwritten at the beginning of the password. The `` +can also accept range values in the format of `start-end`. For example, `1-5` will +print output for the overwrite transformation starting from index 1 to 5. + +## Wordlist Creation Guide + +### Wordlist Creation Introduction +This document describes the ways to use PTT to create password cracking +wordlists. There are several ways to generate wordlists using PTT: + +- `direct-swapping`: Swapping characters directly with a `:` separated file. + This is implemented in the `swap` module. +- `token-popping`: Generates tokens by popping strings at character boundaries. + This is implemented in the `pop` module. +- `token-swapping`: Generates tokens by swapping characters in a string. This is + implemented in the `mask-swap` module. +- `passphrases`: Generates passphrases by combining words from a wordlist. This + is implemented in the `passphrase` module. + +All modes support multibyte characters and can properly convert them. One +transformation can be used at a time. + +> [!CAUTION] +> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. + +### Direct Swapping +The `swap` module swaps characters directly with a `:` separated file. The +syntax is as follows: +``` +ptt -f -t swap -tf +``` +The replacement file should contain the strings to be transformed as `PRIOR:POST` +pairs. The replacements will be applied to the first instance in each line. + +### Token Popping +The `pop` module generates tokens by popping strings at character boundaries. +The syntax is as follows: +``` +ptt -f -t pop -rm +``` +Where `` can be any of the following: +- `u`: Uppercase characters +- `l`: Lowercase characters +- `d`: Digits +- `s`: Special characters +- `b`: Byte characters +- `t`: Title case words (requires `u` and `l`) +- Multiple characters can be combined to create a mask. + +The default value is `uldsbt` for all characters. This mode will create tokens +by popping characters from the input string then aggregating the results. + +### Token Swapping +The `mask-swap` module generates tokens by swapping characters in a string. The +syntax is as follows: +``` +ptt -f -t mask-swap -tf +``` +> [!NOTE] +> The input for `mask-swap` is partial masks from `retain`! This is different from most other modes. + +The replacement file does not need to be in any specific format. The +replacements will be applied to the first instance in each line. The +`mask-swap` mode is unique in that it uses partial masks from the `retain` +module to generate new candidates. This mode also uses its own replacer +module (different from the other modes) to generate new candidates by +extracting the masks and then matching them to the replacement file. + +This mode is most similar to token-swapping in that it generates new +candidates by using masks. However, it is unique in that it uses partial +masks to limit the swap positions from prior applications. + +### Passphrases +The `passphrase` module generates passphrases by combining words from a wordlist. +The `-w` flag can be used to specify the number of words to use in the passphrase. +The `-tf` flag is optional and can be used to specify a file containing separators +to use between words. The syntax is as follows: +``` +ptt -f -t passphrase -w -tf +``` + +The passphrases are generated randomly by selecting words and separators from the input. +If no separator file is provided, no separators will be used. The default word count is 0. +The number of passphrases generated is equal to the number of lines in the input file +*including* duplicates. This means that the item count is also used to determine the number +of passphrases generated. + +## Misc Creation Guide + +### Misc Creation Introduction +This document describes the ways to use PTT to create miscellaneous transformations. +There are several types that can be created using PTT: + +- `Encoding and Decoding`: This transforms input to and from URL, HTML, and Unicode escaped strings. +- `Hex and Dehex`: This transforms input to and from `$HEX[....]` strings. + +All modes support multibyte characters and can properly convert them. One +transformation can be used at a time. + +> [!CAUTION] +> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. + +### Encoding and Decoding +This mode allows encoding and decoding of input to and from URL, HTML, and Unicode escaped strings. +The syntax is as follows: +``` +ptt -f -t encode +``` +or +``` +ptt -f -t decode +``` +The following table shows the supported transformations: + +| Transformation | Description | Input Example | Output Example | +| --- | --- | --- | --- | +| `url` | URL encoding | `https://www.example.com` | `https%3A%2F%2Fwww.example.com` | +| `html` | HTML encoding | `` | `<html>` | +| `unicode` | Unicode encoding | `Hello😎` | `Hello\u1f60e` | + +### Hex and Dehex +This mode allows encoding and decoding of input to and from `$HEX[....]` strings. +The syntax is as follows: +``` +ptt -f -t hex +``` +or +``` +ptt -f -t dehex +``` +The following table shows the supported transformations: + +| Transformation | Description | Input Example | Output Example | +| --- | --- | --- | --- | +| `hex` | Hex encoding | `Hello` | `$HEX[48656c6c6f]` | +| `dehex` | Hex decoding | `$HEX[48656c6c6f]` | `Hello` | + +### Substrings +This mode allows extracting substrings from the input based on position. The syntax is as follows: +``` +ptt -f -t substring -i +``` +or +``` +ptt -f -t substring -i - +``` + +This transformation extracts the substring from the input based on the provided +index. If the end index is greater than the length of the input, it will be +changed to the length of the input. + +This transformation can be used to extract specific parts of the input for +further processing. + diff --git a/docs/WORDLISTS.md b/docs/WORDLISTS.md deleted file mode 100644 index d3e44b5..0000000 --- a/docs/WORDLISTS.md +++ /dev/null @@ -1,90 +0,0 @@ -# Password Transformation Tool (PTT) Wordlist Creation Guide -## Version 0.1.0 - -### Table of Contents -1. [Introduction](#introduction) -2. [Direct Swapping](#direct-swapping) -3. [Token Popping](#token-popping) -4. [Token Swapping](#token-swapping) -5. [Passphrases](#passphrases) - -### Introduction -This document describes the ways to use PTT to create password cracking -wordlists. There are several ways to generate wordlists using PTT: - -- `direct-swapping`: Swapping characters directly with a `:` separated file. - This is implemented in the `swap` module. -- `token-popping`: Generates tokens by popping strings at character boundaries. - This is implemented in the `pop` module. -- `token-swapping`: Generates tokens by swapping characters in a string. This is - implemented in the `mask-swap` module. -- `passphrases`: Generates passphrases by combining words from a wordlist. This - is implemented in the `passphrase` module. - -All modes support multibyte characters and can properly convert them. One -transformation can be used at a time. - -> [!CAUTION] -> Ensure input is provided in the correct format and does not contain hidden characters. `Dos2Unix` can be used to convert the file to proper format if needed. - -### Direct Swapping -The `swap` module swaps characters directly with a `:` separated file. The -syntax is as follows: -``` -ptt -f -t swap -tf -``` -The replacement file should contain the strings to be transformed as `PRIOR:POST` -pairs. The replacements will be applied to the first instance in each line. - -### Token Popping -The `pop` module generates tokens by popping strings at character boundaries. -The syntax is as follows: -``` -ptt -f -t pop -rm -``` -Where `` can be any of the following: -- `u`: Uppercase characters -- `l`: Lowercase characters -- `d`: Digits -- `s`: Special characters -- `b`: Byte characters -- `t`: Title case words (requires `u` and `l`) -- Multiple characters can be combined to create a mask. - -The default value is `uldsbt` for all characters. This mode will create tokens -by popping characters from the input string then aggregating the results. - -### Token Swapping -The `mask-swap` module generates tokens by swapping characters in a string. The -syntax is as follows: -``` -ptt -f -t mask-swap -tf -``` -> [!NOTE] -> The input for `mask-swap` is partial masks from `retain`! This is different from most other modes. - -The replacement file does not need to be in any specific format. The -replacements will be applied to the first instance in each line. The -`mask-swap` mode is unique in that it uses partial masks from the `retain` -module to generate new candidates. This mode also uses its own replacer -module (different from the other modes) to generate new candidates by -extracting the masks and then matching them to the replacement file. - -This mode is most similar to token-swapping in that it generates new -candidates by using masks. However, it is unique in that it uses partial -masks to limit the swap positions from prior applications. - -### Passphrases -The `passphrase` module generates passphrases by combining words from a wordlist. -The `-w` flag can be used to specify the number of words to use in the passphrase. -The `-tf` flag is optional and can be used to specify a file containing separators -to use between words. The syntax is as follows: -``` -ptt -f -t passphrase -w -tf -``` - -The passphrases are generated randomly by selecting words and separators from the input. -If no separator file is provided, no separators will be used. The default word count is 0. -The number of passphrases generated is equal to the number of lines in the input file -*including* duplicates. This means that the item count is also used to determine the number -of passphrases generated. diff --git a/main.go b/main.go index e8acfa2..e2ddd4d 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( "github.com/jakewnuk/ptt/pkg/utils" ) -var version = "0.2.3" +var version = "0.2.4" var wg sync.WaitGroup var mutex = &sync.Mutex{} var retain models.FileArgumentFlag @@ -36,7 +36,7 @@ func main() { fmt.Fprintf(os.Stderr, "ptt [options] [...]\nAccepts standard input and/or additonal arguments.\n\n") fmt.Fprintf(os.Stderr, "Options:\n") flag.PrintDefaults() - fmt.Fprintf(os.Stderr, "\nThe -f, -k, -r, -tf, -tp, and -u flags can be used multiple times and together.\n") + fmt.Fprintf(os.Stderr, "\nThe -f, -k, -r, -tf, -tp, and -u flags can be used multiple times, together, and with files or directories.\n") fmt.Fprintln(os.Stderr, "\nTransformation Modes:") modes := map[string]string{ "append": "Transforms input into append rules.", diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 431bce5..6422b90 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "os" + "path/filepath" "regexp" "sort" "strconv" @@ -37,24 +38,42 @@ import ( func ReadFilesToMap(fs models.FileSystem, filenames []string) map[string]int { wordMap := make(map[string]int) - // Read the contents of the files and add the words to the map - for _, filename := range filenames { - data, err := fs.ReadFile(filename) - if err != nil { - fmt.Fprintf(os.Stderr, "[!] Error reading file %s\n", filename) - os.Exit(1) - } + i := 0 + for i < len(filenames) { + filename := filenames[i] + if IsFileSystemDirectory(filename) { + err := filepath.Walk(filename, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() { + filenames = append(filenames, path) + } + return nil + }) + if err != nil { + fmt.Fprintf(os.Stderr, "[!] Error walking the path %v: %v\n", filename, err) + os.Exit(1) + } + } else { + data, err := fs.ReadFile(filename) + if err != nil { + fmt.Fprintf(os.Stderr, "[!] Error reading file %s\n", filename) + os.Exit(1) + } - err = json.Unmarshal(data, &wordMap) - if err == nil { - fmt.Fprintf(os.Stderr, "[*] Detected ptt JSON output. Importing...\n") - continue - } + err = json.Unmarshal(data, &wordMap) + if err == nil { + fmt.Fprintf(os.Stderr, "[*] Detected ptt JSON output. Importing...\n") + continue + } - fileWords := strings.Split(string(data), "\n") - for _, word := range fileWords { - wordMap[word]++ + fileWords := strings.Split(string(data), "\n") + for _, word := range fileWords { + wordMap[word]++ + } } + i++ } // Remove empty strings from the map @@ -288,57 +307,83 @@ func ProcessURL(url string, ch chan<- string, wg *sync.WaitGroup) { // // templates ([]models.TemplateFileOperation): The slice of template structs func ReadJSONToArray(fs models.FileSystem, filenames []string) []models.TemplateFileOperation { - var templates []models.TemplateFileOperation - for _, filename := range filenames { - data, err := fs.ReadFile(filename) - if err != nil { - fmt.Fprintf(os.Stderr, "[!] Error reading file %s\n", filename) - os.Exit(1) - } - - err = json.Unmarshal(data, &templates) - if err != nil { - fmt.Fprintf(os.Stderr, "[!] Error unmarshalling JSON file %s\n", filename) - os.Exit(1) - } - - alphaRe := regexp.MustCompile(`[a-zA-Z]`) - numRe := regexp.MustCompile(`[0-9]`) - - for _, template := range templates { - if !numRe.MatchString(fmt.Sprintf("%v", template.StartIndex)) || !numRe.MatchString(fmt.Sprintf("%v", template.EndIndex)) { - fmt.Fprintf(os.Stderr, "[!] Error: StartIndex and EndIndex must be integers\n") + var combinedTemplate []models.TemplateFileOperation + var template []models.TemplateFileOperation + + i := 0 + for i < len(filenames) { + filename := filenames[i] + // Check to see if a directory was passed + // If so, read all files in the directory and append them to the filenames + // slice + if IsFileSystemDirectory(filename) { + err := filepath.Walk(filename, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() && strings.HasSuffix(info.Name(), ".json") { + filenames = append(filenames, path) + } + return nil + }) + if err != nil { + fmt.Fprintf(os.Stderr, "[!] Error walking the path %v: %v\n", filename, err) os.Exit(1) } - - if !alphaRe.MatchString(fmt.Sprintf("%v", template.Verbose)) { - fmt.Fprintf(os.Stderr, "[!] Error: Verbose must be a boolean\n") + } else { + data, err := fs.ReadFile(filename) + if err != nil { + fmt.Fprintf(os.Stderr, "[!] Error reading file %s\n", filename) os.Exit(1) } - if !alphaRe.MatchString(fmt.Sprintf("%v", template.ReplacementMask)) { - fmt.Fprintf(os.Stderr, "[!] Error: ReplacementMask must be a string\n") + err = json.Unmarshal(data, &template) + if err != nil { + fmt.Fprintf(os.Stderr, "[!] Error unmarshalling JSON file %s\n", filename) os.Exit(1) } - if !alphaRe.MatchString(fmt.Sprintf("%v", template.Bypass)) { - fmt.Fprintf(os.Stderr, "[!] Error: Bypass must be a boolean\n") - os.Exit(1) - } + combinedTemplate = append(combinedTemplate, template...) + } + i++ + } - if !alphaRe.MatchString(fmt.Sprintf("%v", template.TransformationMode)) { - fmt.Fprintf(os.Stderr, "[!] Error: TransformationMode must be a string\n") - os.Exit(1) - } + alphaRe := regexp.MustCompile(`[a-zA-Z]`) + numRe := regexp.MustCompile(`[0-9]`) - if !numRe.MatchString(fmt.Sprintf("%v", template.PassphraseWords)) { - fmt.Fprintf(os.Stderr, "[!] Error: PassphraseWords must be an integer\n") - os.Exit(1) - } + for _, template := range combinedTemplate { + if !numRe.MatchString(fmt.Sprintf("%v", template.StartIndex)) || !numRe.MatchString(fmt.Sprintf("%v", template.EndIndex)) { + fmt.Fprintf(os.Stderr, "[!] Error: StartIndex and EndIndex must be integers\n") + os.Exit(1) + } + + if !alphaRe.MatchString(fmt.Sprintf("%v", template.Verbose)) { + fmt.Fprintf(os.Stderr, "[!] Error: Verbose must be a boolean\n") + os.Exit(1) + } + + if !alphaRe.MatchString(fmt.Sprintf("%v", template.ReplacementMask)) { + fmt.Fprintf(os.Stderr, "[!] Error: ReplacementMask must be a string\n") + os.Exit(1) + } + + if !alphaRe.MatchString(fmt.Sprintf("%v", template.Bypass)) { + fmt.Fprintf(os.Stderr, "[!] Error: Bypass must be a boolean\n") + os.Exit(1) + } + + if !alphaRe.MatchString(fmt.Sprintf("%v", template.TransformationMode)) { + fmt.Fprintf(os.Stderr, "[!] Error: TransformationMode must be a string\n") + os.Exit(1) + } + + if !numRe.MatchString(fmt.Sprintf("%v", template.PassphraseWords)) { + fmt.Fprintf(os.Stderr, "[!] Error: PassphraseWords must be an integer\n") + os.Exit(1) } } - return templates + return combinedTemplate } // ---------------------------------------------------------------------------- @@ -657,3 +702,21 @@ func CheckAreArraysEqual(a, b []string) bool { } return true } + +// IsFileSystemDirectory checks to see if a string is a valid file system +// directory by checking if the path exists and if it is a directory +// +// Args: +// +// path (string): The path to check +// +// Returns: +// +// bool: True if the path is a directory, false otherwise +func IsFileSystemDirectory(path string) bool { + fileInfo, err := os.Stat(path) + if os.IsNotExist(err) { + return false + } + return fileInfo.IsDir() +} diff --git a/templates/mask.json b/templates/masks/mask.json similarity index 100% rename from templates/mask.json rename to templates/masks/mask.json diff --git a/templates/swap-encode.json b/templates/misc/swap-encode.json similarity index 100% rename from templates/swap-encode.json rename to templates/misc/swap-encode.json diff --git a/templates/append.json b/templates/rules/append.json similarity index 100% rename from templates/append.json rename to templates/rules/append.json diff --git a/templates/inov1-6.json b/templates/rules/insert1-6.json similarity index 100% rename from templates/inov1-6.json rename to templates/rules/insert1-6.json diff --git a/templates/prepend.json b/templates/rules/prepend.json similarity index 100% rename from templates/prepend.json rename to templates/rules/prepend.json