Markopy
Utilizing Markov Models for brute forcing attacks
markovPasswords.h
Go to the documentation of this file.
1
/** @file markovPasswords.h
2
* @brief Wrapper for Markov::Model to use with char represented models.
3
* @authors Ata Hakçıl, Osman Ömer Yıldıztugay
4
*
5
* This file contains the declerations for Markov::API::MarkovPasswords class.
6
*
7
* @copydoc Markov::API::MarkovPasswords
8
*/
9
10
#
pragma
once
11
#
include
"threadSharedListHandler.h"
12
#
include
"MarkovModel/src/model.h"
13
14
15
/** @brief Namespace for the MarkovPasswords API
16
*/
17
namespace
Markov
::
API
{
18
19
/** @brief Markov::Model with char represented nodes.
20
*
21
* Includes wrappers for Markov::Model and additional helper functions to handle file I/O
22
*
23
* This class is an extension of Markov::Model<char>, with higher level abstractions such as train and generate.
24
*
25
*/
26
class
MarkovPasswords
:
public
Markov
::
Model
<
char
>{
27
public
:
28
29
/** @brief Initialize the markov model from MarkovModel::Markov::Model.
30
*
31
* Parent constructor. Has no extra functionality.
32
*/
33
MarkovPasswords
();
34
35
/** @brief Initialize the markov model from MarkovModel::Markov::Model, with an import file.
36
*
37
* This function calls the Markov::Model::Import on the filename to construct the model.
38
* Same thing as creating and empty model, and calling MarkovPasswords::Import on the filename.
39
*
40
* @param filename - Filename to import
41
*
42
*
43
* @b Example @b Use: Construction via filename
44
* @code{.cpp}
45
* MarkovPasswords mp("test.mdl");
46
* @endcode
47
*/
48
MarkovPasswords
(
const
char
* filename);
49
50
/** @brief Open dataset file and return the ifstream pointer
51
* @param filename - Filename to open
52
* @return ifstream* to the the dataset file
53
*/
54
std::ifstream*
OpenDatasetFile
(
const
char
* filename);
55
56
57
/** @brief Train the model with the dataset file.
58
* @param datasetFileName - Ifstream* to the dataset. If null, use class member
59
* @param delimiter - a character, same as the delimiter in dataset content
60
* @param threads - number of OS threads to spawn
61
*
62
* @code{.cpp}
63
* Markov::API::MarkovPasswords mp;
64
* mp.Import("models/2gram.mdl");
65
* mp.Train("password.corpus");
66
* @endcode
67
*/
68
void
Train
(
const
char
* datasetFileName,
char
delimiter,
int
threads);
69
70
71
72
/** @brief Export model to file.
73
* @param filename - Export filename.
74
* @return std::ofstream* of the exported file.
75
*/
76
std::ofstream*
Save
(
const
char
* filename);
77
78
/** @brief Call Markov::Model::RandomWalk n times, and collect output.
79
*
80
* Generate from model and write results to a file.
81
* a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
82
*
83
* @deprecated See Markov::API::MatrixModel::FastRandomWalk for more information.
84
* @param n - Number of passwords to generate.
85
* @param wordlistFileName - Filename to write to
86
* @param minLen - Minimum password length to generate
87
* @param maxLen - Maximum password length to generate
88
* @param threads - number of OS threads to spawn
89
*/
90
void
Generate
(
unsigned
long
int
n,
const
char
* wordlistFileName,
int
minLen=6,
int
maxLen=12,
int
threads=20);
91
92
/** @brief Buff expression of some characters in the model
93
* @param str A string containing all the characters to be buffed
94
* @param multiplier A constant value to buff the nodes with.
95
* @param bDontAdjustSelfEdges Do not adjust weights if target node is same as source node
96
* @param bDontAdjustExtendedLoops Do not adjust if both source and target nodes are in first parameter
97
*/
98
void
Buff
(
const
char
* str,
double
multiplier,
bool
bDontAdjustSelfLoops=
true
,
bool
bDontAdjustExtendedLoops=
false
);
99
100
101
private
:
102
103
/** @brief A single thread invoked by the Train function.
104
* @param listhandler - Listhandler class to read corpus from
105
* @param delimiter - a character, same as the delimiter in dataset content
106
*
107
*/
108
void
TrainThread
(
Markov
::
API
::
Concurrency
::
ThreadSharedListHandler
*listhandler,
char
delimiter);
109
110
/** @brief A single thread invoked by the Generate function.
111
*
112
* @b DEPRECATED: See Markov::API::MatrixModel::FastRandomWalkThread for more information. This has been replaced with
113
* a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
114
*
115
* @param outputLock - shared mutex lock to lock during output operation. Prevents race condition on write.
116
* @param n number of lines to be generated by this thread
117
* @param wordlist wordlistfile
118
* @param minLen - Minimum password length to generate
119
* @param maxLen - Maximum password length to generate
120
*
121
*/
122
void
GenerateThread
(std::mutex *outputLock,
unsigned
long
int
n, std::ofstream *wordlist,
int
minLen,
int
maxLen);
123
std::ifstream*
datasetFile
;
/** @brief Dataset file input of our system */
124
std::ofstream*
modelSavefile
;
/** @brief File to save model of our system */
125
std::ofstream*
outputFile
;
/** @brief Generated output file of our system */
126
};
127
128
129
130
};
Markopy
MarkovAPI
src
markovPasswords.h
Generated by
1.9.0