Skip to content

Commit

Permalink
Clean up of interactive rule-editor PR
Browse files Browse the repository at this point in the history
  • Loading branch information
alpatron committed Aug 13, 2024
1 parent b4c6761 commit f0fb507
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion server/sql/10_create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ CREATE TABLE IF NOT EXISTS `fc_settings` (
`ramp_down_coefficient` decimal(5,2) NOT NULL DEFAULT '0.25',
`verify_hash_format` tinyint(1) unsigned NOT NULL DEFAULT '1',
`auto_add_hosts_to_running_jobs` tinyint(1) unsigned NOT NULL DEFAULT '0',
`max_mangled_passwords` int(7) unsigned NOT NULL DEFAULT '50000',
`max_mangled_passwords_in_preview` int(7) unsigned NOT NULL DEFAULT '50000',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

Expand Down
2 changes: 1 addition & 1 deletion server/sql/30_insert_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- Insert default settings row
--

INSERT INTO `fc_settings` (`default_seconds_per_workunit`, `workunit_timeout_factor`, `hwmon_temp_abort`, `bench_all`, `distribution_coefficient_alpha`, `t_pmin`, `ramp_up_workunits`, `ramp_down_coefficient`, `verify_hash_format`, `auto_add_hosts_to_running_jobs`, `max_mangled_passwords`) VALUES
INSERT INTO `fc_settings` (`default_seconds_per_workunit`, `workunit_timeout_factor`, `hwmon_temp_abort`, `bench_all`, `distribution_coefficient_alpha`, `t_pmin`, `ramp_up_workunits`, `ramp_down_coefficient`, `verify_hash_format`, `auto_add_hosts_to_running_jobs`, `max_mangled_passwords_in_preview`) VALUES
(3600, 48, 90, 0, 0.1, 20, 0, 0.25, 1, 0, 50000);


Expand Down
1 change: 1 addition & 0 deletions webadmin/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Adam Horak
David Bolvansky
Radek Hranicky
Viktor Rucky
Jiri Mladek
2 changes: 1 addition & 1 deletion webadmin/fitcrackAPI/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def check_valid_login():


def main():
app.run(host='0.0.0.0', port=5000, threaded=False, debug = True)
app.run(host='0.0.0.0', port=5000, threaded=False)


initialize_app(app)
Expand Down
22 changes: 8 additions & 14 deletions webadmin/fitcrackAPI/src/src/api/fitcrack/endpoints/rule/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def countRules(filePath):
Function which counts rules
'''
ruleCount = 0
with open(os.path.join(RULE_DIR, filePath), encoding='latin-1') as file:
with open(os.path.join(RULE_DIR, filePath), encoding='ascii',errors='surrogateescape') as file:
for line in file:
if re.match('^\s*(\#.*)?$', line) == None:
ruleCount += 1
Expand Down Expand Up @@ -173,14 +173,8 @@ def put(self, id):
'status': True,
'message': returnMessage
}, 200










@ns.route('/<id>/data')
class ruleData(Resource):
@api.expect(rule_parser)
Expand All @@ -203,13 +197,13 @@ def get(self, id):
}

if args.get('search', None):
with open(rule_path, encoding='latin-1') as file:
with open(rule_path, encoding='ascii',errors='surrogateescape') as file:
head = ''
for line in file:
if line.find(args['search']) != -1:
head += line
else:
with open(rule_path, encoding='latin-1') as file:
with open(rule_path, encoding='ascii',errors='surrogateescape') as file:
head = list(islice(file, page * per_page, page * per_page + per_page))

if len(head) == 0:
Expand Down Expand Up @@ -282,7 +276,7 @@ def post(self):
rules = requestData['rules']

RETCODE_COMMENT = -3
maxMangledPasswords = FcSetting.query.first().max_mangled_passwords # get maximum number of mangled passwords from database
maxMangledPasswords = FcSetting.query.first().max_mangled_passwords_in_preview # get maximum number of mangled passwords from database
preview = []
mangledPasswordBuf = ctypes.create_string_buffer(64)

Expand All @@ -302,15 +296,15 @@ def post(self):
continue

# Apply the rule to the password using the C function, returns -1 for rule syntax error, -2 for empty rule or password or new password length if OK
retCode = applyRule(rule.encode('latin-1'), len(rule), password.encode('utf-8'), passwordLength, mangledPasswordBuf)
retCode = applyRule(rule.encode('ascii',errors='surrogateescape'), len(rule), password.encode('ascii',errors='surrogateescape'), passwordLength, mangledPasswordBuf)

if(retCode == -1):
mangledPasswordStr = ""
#if the line in a rule is a comment, specify return code to -3
if(len(rule) > 0 and rule[0] == '#'):
retCode = RETCODE_COMMENT
else:
mangledPasswordStr = mangledPasswordBuf.value.decode('latin-1')
mangledPasswordStr = mangledPasswordBuf.value.decode('ascii',errors='surrogateescape')

#Add element to a preview list
element = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
settings_arguments.add_argument('ramp_down_coefficient', type=float, help='', required=False, location='json')
settings_arguments.add_argument('verify_hash_format', type=bool, help='', required=False, location='json')
settings_arguments.add_argument('auto_add_hosts_to_running_jobs', type=bool, help='', required=False, location='json')
settings_arguments.add_argument('max_mangled_passwords', type=int, help='', required=False, location='json')
settings_arguments.add_argument('max_mangled_passwords_in_preview', type=int, help='', required=False, location='json')
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
'ramp_down_coefficient': fields.Float(),
'verify_hash_format': fields.Boolean(),
'auto_add_hosts_to_running_jobs': fields.Boolean(),
'max_mangled_passwords': fields.Integer()
'max_mangled_passwords_in_preview': fields.Integer()
})
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def post(self):
rdc = args['ramp_down_coefficient']
vhf = args['verify_hash_format']
aahtrj = args['auto_add_hosts_to_running_jobs']
mmp = args['max_mangled_passwords']
mmp = args['max_mangled_passwords_in_preview']

settings = FcSetting.query.first()
if (spw is not None): settings.default_seconds_per_workunit = spw
Expand All @@ -60,7 +60,7 @@ def post(self):
if (rdc is not None): settings.ramp_down_coefficient = rdc
if (vhf is not None): settings.verify_hash_format = vhf
if (aahtrj is not None): settings.auto_add_hosts_to_running_jobs = aahtrj
if (mmp is not None): settings.max_mangled_passwords = mmp
if (mmp is not None): settings.max_mangled_passwords_in_preview = mmp
db.session.commit()

return {
Expand Down
2 changes: 1 addition & 1 deletion webadmin/fitcrackAPI/src/src/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class FcSetting(Base):
ramp_down_coefficient = Column(Numeric(5, 2), nullable=False, server_default=text("'0.25'"))
verify_hash_format = Column(Integer, nullable=False, server_default=text("'1'"))
auto_add_hosts_to_running_jobs = Column(Integer, nullable=False, server_default=text("'0'"))
max_mangled_passwords = Column(Integer, nullable=False, server_default=text("'5000'"))
max_mangled_passwords_in_preview = Column(Integer, nullable=False, server_default=text("'5000'"))

class FcJobGraph(Base):
__tablename__ = 'fc_job_graph'
Expand Down
12 changes: 6 additions & 6 deletions webadmin/fitcrackFE/src/assets/ruleFunctions.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{
"name": "Toggle Case",
"sign": "t",
"description": "Toggle the case of all characters in word.",
"description": "Toggle the case of all characters in word",
"operands": [],
"example": "t",
"input": "p@ssW0rd",
Expand Down Expand Up @@ -111,7 +111,7 @@
{
"name": "Rotate Left",
"sign": "{",
"description": "Rotate the word left.",
"description": "Rotate the word left",
"operands": [],
"example": "{",
"input": "p@ssW0rd",
Expand Down Expand Up @@ -585,9 +585,9 @@
"output": "p@9sW0rd"
},
{
"name": "Ascii increment",
"name": "ASCII increment",
"sign": "+N",
"description": "Increment character @ N by 1 ascii value",
"description": "Increment character @ N by 1 ASCII value",
"operands": [
{
"specification": "Position of character",
Expand All @@ -599,9 +599,9 @@
"output": "p@tsW0rd"
},
{
"name": "Ascii decrement",
"name": "ASCII decrement",
"sign": "-N",
"description": "Decrement character @ N by 1 ascii value",
"description": "Decrement character @ N by 1 ASCII value",
"operands": [
{
"specification": "Position of character",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@
<v-row>
<v-col>
<v-alert tile color="orange" text class="mb-0">
Maximum number of mangled passwords is set to {{ max_mangled_passwords }}. For change go to
Maximum number of mangled passwords is set to {{ max_mangled_passwords_in_preview }}. To change this, go to
<router-link :to="{ name: 'settings' }">
<b>advanced settings</b>.
</router-link>
</router-link><br />
Note: Mangled passwords longer than 64 characters are not outputted in the preview.
</v-alert>
</v-col>
</v-row>
Expand Down Expand Up @@ -121,7 +122,7 @@ export default {
data() {
return {
appendDictPopup: false, // true if append dictionary popup should be shown, false if hidden
max_mangled_passwords: 50000,
max_mangled_passwords_in_preview: 50000,
}
},
methods: {
Expand Down Expand Up @@ -149,7 +150,7 @@ export default {
mounted() {
// get the maximum number of mangled passwords from database
this.axios.get(this.$serverAddr + '/settings').then((response) => {
this.max_mangled_passwords = response.data.max_mangled_passwords;
this.max_mangled_passwords_in_preview = response.data.max_mangled_passwords_in_preview;
});
},
components: {
Expand Down
10 changes: 5 additions & 5 deletions webadmin/fitcrackFE/src/components/settings/settingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@
class="mb-4"
/>
<v-divider class="mb-2"></v-divider>
<span class="text-subtitle-1 font-weight-medium">Rules editor settings (effects only Live preview of mangled passwords)</span>
<span class="text-subtitle-1 font-weight-medium">Rules editor settings (affects only live preview of mangled passwords)</span>
<v-text-field
v-model="settings.max_mangled_passwords"
v-model="settings.max_mangled_passwords_in_preview"
:loading="loading"
outlined
type="number"
label="Maximum number of mangled passwords"
hint="Changing the default value (50000) to a higher number can lead to delays and performance issues when mangling passwords and checking rules. The number can not go beyond 1000000."
hint="Changing the default value (50 000) to a higher number can lead to delays and performance issues when mangling passwords and checking rules. The number cannot go beyond 1 000 000."
persistent-hint
class="my-2"
/>
Expand Down Expand Up @@ -318,8 +318,8 @@
this.$error('Workunit timeout factor cannot be smaller than 5.')
return
}
if(this.settings.max_mangled_passwords > 1000000){ // check the maximum number of mangled passwords
this.$error('Maximum number of mangled passwords can not be more than 1000000.')
if(this.settings.max_mangled_passwords_in_preview > 1000000){ // check the maximum number of mangled passwords
this.$error('Maximum number of mangled passwords cannot be more than 1000000.')
return
}
this.saving = true
Expand Down

0 comments on commit f0fb507

Please sign in to comment.