Markopy
Utilizing Markov Models for brute forcing attacks
|
Abstract representation of a matrix based model. More...
Public Member Functions | |
def | FastRandomWalk (int count, str wordlist, int minlen, int maxlen) |
bool | ConstructMatrix () |
Construct the related Matrix data for the model. More... | |
void | DumpJSON () |
Debug function to dump the model to a JSON file. More... | |
int | FastRandomWalk (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true) |
Random walk on the Matrix-reduced Markov::Model. More... | |
void | Import (const char *filename) |
Open a file to import with filename, and call bool Model::Import with std::ifstream. More... | |
bool | Import (std::ifstream *) |
Import a file to construct the model. More... | |
void | Train (const char *datasetFileName, char delimiter, int threads) |
Train the model with the dataset file. More... | |
std::ifstream * | OpenDatasetFile (const char *filename) |
Open dataset file and return the ifstream pointer. More... | |
std::ofstream * | Save (const char *filename) |
Export model to file. More... | |
void | Generate (unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20) |
Call Markov::Model::RandomWalk n times, and collect output. More... | |
void | Buff (const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false) |
Buff expression of some characters in the model. More... | |
char * | RandomWalk (Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer) |
Do a random walk on this model. More... | |
void | AdjustEdge (const char *payload, long int occurrence) |
Adjust the model with a single string. More... | |
bool | Export (std::ofstream *) |
Export a file of the model. More... | |
bool | Export (const char *filename) |
Open a file to export with filename, and call bool Model::Export with std::ofstream. More... | |
Node< char > * | StarterNode () |
Return starter Node. More... | |
std::vector< Edge< char > * > * | Edges () |
Return a vector of all the edges in the model. More... | |
std::map< char, Node< char > * > * | Nodes () |
Return starter Node. More... | |
void | OptimizeEdgeOrder () |
Sort edges of all nodes in the model ordered by edge weights. More... | |
Protected Member Functions | |
int | FastRandomWalk (unsigned long int n, std::ofstream *wordlist, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true) |
Random walk on the Matrix-reduced Markov::Model. More... | |
void | FastRandomWalkPartition (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads) |
A single partition of FastRandomWalk event. More... | |
void | FastRandomWalkThread (std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO) |
A single thread of a single partition of FastRandomWalk. More... | |
bool | DeallocateMatrix () |
Deallocate matrix and make it ready for re-construction. More... | |
Protected Attributes | |
char ** | edgeMatrix |
2-D Character array for the edge Matrix (The characters of Nodes) More... | |
long int ** | valueMatrix |
2-d Integer array for the value Matrix (For the weights of Edges) More... | |
int | matrixSize |
to hold Matrix size More... | |
char * | matrixIndex |
to hold the Matrix index (To hold the orders of 2-D arrays') More... | |
long int * | totalEdgeWeights |
Array of the Total Edge Weights. More... | |
bool | ready |
True when matrix is constructed. False if not. More... | |
Private Member Functions | |
void | TrainThread (Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter) |
A single thread invoked by the Train function. More... | |
void | GenerateThread (std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen) |
A single thread invoked by the Generate function. More... | |
Private Attributes | |
std::ifstream * | datasetFile |
std::ofstream * | modelSavefile |
Dataset file input of our system More... | |
std::ofstream * | outputFile |
File to save model of our system More... | |
std::map< char, Node< char > * > | nodes |
Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer. More... | |
Node< char > * | starterNode |
Starter Node of this model. More... | |
std::vector< Edge< char > * > | edges |
A list of all edges in this model. More... | |
Abstract representation of a matrix based model.
To help with the python-cpp gateway documentation.
|
inherited |
Adjust the model with a single string.
Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.
Then, update the edge EdgeWeight from current node, to the terminator node.
This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.
Example Use: Create an empty model and train it with string: "testdata"
string | - String that is passed from the training, and will be used to AdjustEdge the model with |
occurrence | - Occurrence of this string. |
Definition at line 109 of file model.h.
|
inherited |
Buff expression of some characters in the model.
str | A string containing all the characters to be buffed |
multiplier | A constant value to buff the nodes with. |
bDontAdjustSelfEdges | Do not adjust weights if target node is same as source node |
bDontAdjustExtendedLoops | Do not adjust if both source and target nodes are in first parameter |
Definition at line 153 of file markovPasswords.cpp.
References Markov::Edge< NodeStorageType >::AdjustEdge(), Markov::Node< storageType >::Edges(), Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::Model< NodeStorageType >::Nodes(), and Markov::Model< NodeStorageType >::OptimizeEdgeOrder().
Referenced by main().
|
inherited |
Construct the related Matrix data for the model.
This operation can be used after importing/training to allocate and populate the matrix content.
this will initialize: char** edgeMatrix -> a 2D array of mapping left and right connections of each edge. long int **valueMatrix -> a 2D array representing the edge weights. int matrixSize -> Size of the matrix, aka total number of nodes. char* matrixIndex -> order of nodes in the model long int *totalEdgeWeights -> total edge weights of each Node.
Definition at line 31 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), Markov::API::ModelMatrix::ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), Markov::API::ModelMatrix::totalEdgeWeights, Markov::Node< storageType >::TotalEdgeWeights(), and Markov::API::ModelMatrix::valueMatrix.
Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().
|
protectedinherited |
Deallocate matrix and make it ready for re-construction.
Definition at line 81 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::API::ModelMatrix::ready, Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.
Referenced by Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().
|
inherited |
Debug function to dump the model to a JSON file.
Might not work 100%. Not meant for production use.
Definition at line 101 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, and Markov::API::ModelMatrix::valueMatrix.
Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().
|
inlineinherited |
|
inherited |
Open a file to export with filename, and call bool Model::Export with std::ofstream.
Example Use: Export file to filename
Definition at line 166 of file model.h.
|
inherited |
Export a file of the model.
File contains a list of edges. Format is: Left_repr;EdgeWeight;right_repr. For more information on the format, check out the project wiki or github readme.
Iterate over this vertices, and their edges, and write them to file.
Example Use: Export file to ofstream
Definition at line 155 of file model.h.
def Python.Markopy.ModelMatrix.FastRandomWalk | ( | int | count, |
str | wordlist, | ||
int | minlen, | ||
int | maxlen | ||
) |
Definition at line 48 of file mm.py.
Referenced by Python.Markopy.ModelMatrixCLI._generate().
|
inherited |
Random walk on the Matrix-reduced Markov::Model.
This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.
If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.
While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5
This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.
n | - Number of passwords to generate. |
wordlistFileName | - Filename to write to |
minLen | - Minimum password length to generate |
maxLen | - Maximum password length to generate |
threads | - number of OS threads to spawn |
bFileIO | - If false, filename will be ignored and will output to stdout. |
Definition at line 217 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::FastRandomWalk().
Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().
|
protectedinherited |
Random walk on the Matrix-reduced Markov::Model.
This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.
If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.
While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5
This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.
n | - Number of passwords to generate. |
wordlistFileName | - Filename to write to |
minLen | - Minimum password length to generate |
maxLen | - Maximum password length to generate |
threads | - number of OS threads to spawn |
bFileIO | - If false, filename will be ignored and will output to stdout. |
Definition at line 204 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::FastRandomWalkPartition().
Referenced by Markov::API::ModelMatrix::FastRandomWalk().
|
protectedinherited |
A single partition of FastRandomWalk event.
Since FastRandomWalk has to allocate its output buffer before operation starts and writes data in chunks, large n parameters would lead to huge memory allocations. Without Partitioning:
Instead, FastRandomWalk is partitioned per 50M generations to limit the top memory need.
mlock | - mutex lock to distribute to child threads |
wordlist | - Reference to the wordlist file to write to |
n | - Number of passwords to generate. |
wordlistFileName | - Filename to write to |
minLen | - Minimum password length to generate |
maxLen | - Maximum password length to generate |
threads | - number of OS threads to spawn |
bFileIO | - If false, filename will be ignored and will output to stdout. |
Definition at line 225 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::FastRandomWalkThread().
Referenced by Markov::API::ModelMatrix::FastRandomWalk().
|
protectedinherited |
A single thread of a single partition of FastRandomWalk.
A FastRandomWalkPartition will initiate as many of this function as requested.
This function contains the bulk of the generation algorithm.
mlock | - mutex lock to distribute to child threads |
wordlist | - Reference to the wordlist file to write to |
n | - Number of passwords to generate. |
wordlistFileName | - Filename to write to |
minLen | - Minimum password length to generate |
maxLen | - Maximum password length to generate |
id | - DEPRECATED Thread id - No longer used |
bFileIO | - If false, filename will be ignored and will output to stdout. |
Definition at line 153 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Random::Marsaglia::random(), Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.
Referenced by Markov::API::ModelMatrix::FastRandomWalkPartition().
|
inherited |
Call Markov::Model::RandomWalk n times, and collect output.
Generate from model and write results to a file. a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
n | - Number of passwords to generate. |
wordlistFileName | - Filename to write to |
minLen | - Minimum password length to generate |
maxLen | - Maximum password length to generate |
threads | - number of OS threads to spawn |
Definition at line 118 of file markovPasswords.cpp.
References Markov::API::MarkovPasswords::GenerateThread().
Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().
|
privateinherited |
A single thread invoked by the Generate function.
DEPRECATED: See Markov::API::MatrixModel::FastRandomWalkThread for more information. This has been replaced with a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
outputLock | - shared mutex lock to lock during output operation. Prevents race condition on write. |
n | number of lines to be generated by this thread |
wordlist | wordlistfile |
minLen | - Minimum password length to generate |
maxLen | - Maximum password length to generate |
Definition at line 140 of file markovPasswords.cpp.
References Markov::Model< NodeStorageType >::RandomWalk().
Referenced by Markov::API::MarkovPasswords::Generate().
|
inherited |
Open a file to import with filename, and call bool Model::Import with std::ifstream.
Example Use: Import a file with filename
Construct the matrix when done.
Definition at line 19 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().
Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), Markov::Markopy::BOOST_PYTHON_MODULE(), and main().
|
inherited |
Import a file to construct the model.
File contains a list of edges. For more info on the file format, check out the wiki and github readme pages. Format is: Left_repr;EdgeWeight;right_repr
Iterate over this list, and construct nodes and edges accordingly.
Example Use: Import a file from ifstream
Definition at line 126 of file model.h.
|
inlineinherited |
|
inherited |
Open dataset file and return the ifstream pointer.
filename | - Filename to open |
Definition at line 51 of file markovPasswords.cpp.
References Markov::Model< NodeStorageType >::Import().
|
inherited |
|
inherited |
Do a random walk on this model.
Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached. If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext
If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node. This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from
This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.
This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.
Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia
randomEngine | Random Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia |
minSetting | Minimum number of characters to generate |
maxSetting | Maximum number of character to generate |
buffer | buffer to write the result to |
Definition at line 86 of file model.h.
|
inherited |
Export model to file.
filename | - Export filename. |
Definition at line 106 of file markovPasswords.cpp.
References Markov::Model< NodeStorageType >::Export().
|
inlineinherited |
|
inherited |
Train the model with the dataset file.
datasetFileName | - Ifstream* to the dataset. If null, use class member |
delimiter | - a character, same as the delimiter in dataset content |
threads | - number of OS threads to spawn |
Construct the matrix when done.
Definition at line 25 of file modelMatrix.cpp.
References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().
Referenced by Markov::Markopy::CUDA::BOOST_PYTHON_MODULE(), and Markov::Markopy::BOOST_PYTHON_MODULE().
|
privateinherited |
A single thread invoked by the Train function.
listhandler | - Listhandler class to read corpus from |
delimiter | - a character, same as the delimiter in dataset content |
Definition at line 85 of file markovPasswords.cpp.
References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().
Referenced by Markov::API::MarkovPasswords::Train().
|
privateinherited |
Definition at line 123 of file markovPasswords.h.
|
protectedinherited |
2-D Character array for the edge Matrix (The characters of Nodes)
Definition at line 175 of file modelMatrix.h.
Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().
|
privateinherited |
|
protectedinherited |
to hold the Matrix index (To hold the orders of 2-D arrays')
Definition at line 190 of file modelMatrix.h.
Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().
|
protectedinherited |
to hold Matrix size
Definition at line 185 of file modelMatrix.h.
Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), Markov::API::ModelMatrix::FastRandomWalkThread(), and Markov::API::CUDA::CUDAModelMatrix::FlattenMatrix().
|
privateinherited |
Dataset file input of our system
Definition at line 124 of file markovPasswords.h.
|
privateinherited |
|
privateinherited |
File to save model of our system
Definition at line 125 of file markovPasswords.h.
|
protectedinherited |
True when matrix is constructed. False if not.
Definition at line 200 of file modelMatrix.h.
Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().
|
privateinherited |
|
protectedinherited |
Array of the Total Edge Weights.
Definition at line 195 of file modelMatrix.h.
Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::FastRandomWalkThread().
|
protectedinherited |
2-d Integer array for the value Matrix (For the weights of Edges)
Definition at line 180 of file modelMatrix.h.
Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().