f0cker / crackq

CrackQ: A Python Hashcat cracking queue system
MIT License
922 stars 101 forks source link

Rule setting not saved to template #36

Open hkelley opened 1 year ago

hkelley commented 1 year ago

Describe the bug Rule setting is not preseved when job is saved as a Template

To Reproduce Steps to reproduce the behavior:

  1. Save a job as a template image

  2. Review the settings in the template

    {
        "Name":  "XXXXXX",
        "ID":  "1d4d3454-569b-44f3-b80c-8ec4156ec321",
        "Details":  {
                        "attack_mode":  0,
                        "increment":  null,
                        "increment_max":  null,
                        "increment_min":  null,
                        "mask":  "?a?a?a?a?a?a",
                        "rules":  null,
                        "wordlist":  "rockyou2021",
                        "wordlist2":  null,
                        "timeout":  32400,
                        "stats":  ""
                    }
    },

Expected behavior The rules property of the template should not be null No logs written to crackq.log

hkelley commented 1 year ago

I'm speculating a bit, but could this be the result of https://github.com/f0cker/crackq/blob/ec84c6a162f379febc3f2f21ea8832f32b316de1/crackq/cq_api.py#L1928 where the data to write into the template is taken from the job file:

                with job_file.open('r') as fh_job_file:
                    job_dict = json.loads(fh_job_file.read())
                    job_keys = job_dict.keys()
                    for key in save_keys:
                        # temporary handling of stats field until that functionarlity is used
                        if key == 'stats':
                            template_dict[key] = []
                        elif key in job_keys:
                            template_dict[key] = job_dict[key]
                        else:
                            template_dict[key] = None

but the job file doesn't have the rule:

sudo cat  /var/crackq/logs/37e42dca6da14651842b0c91c697d864.json
{"hash_mode": 1000, "attack_mode": 0, "mask": "?a?a?a?a?a?a", "wordlist": "rockyou2021", "brain_check": null, "timeout": 32400, "name": "template creator", "restore": 0, "Cracked Hashes": 2, "Total Hashes": 2}
hkelley commented 1 year ago

This may be another case where a job that is 100% potfile behaves different (has different data written to disk).

f0cker commented 1 year ago

Yeah it's because the job fails before it initialises properly. It saves a temporary job file while the speed check runs and your job failed during the speed check. I wouldn't recommend creating templates from failed jobs, in case you create a broken template. I might just add a check/warning when doing so.

hkelley commented 1 year ago

Yes, a warning would help (at least me). When I run a job directly in hashcat, I don't think of it as "failed" simply because it was able to work exclusively from the potfile. I carried that mindset/assumption to CrackQ.

f0cker commented 1 year ago

Makes sense - the job actually goes into a redis queue and then they get executed by hashcat in turn. It runs a speed check initially (as soon as a new job is added to the queue), which runs hashcat to get the estimated speed for the hashes with the submitted settings. It pauses the current running job to do the speed check, which is used to judge whether or not to use the brain for the submitted hashes. While it does this it will also pull out any cracked hashes from the potfile so you get those immediately without having to wait for that job to get to the front of the queue.

hkelley commented 1 year ago

Thanks for that context.

Is there any way to directly create or edit a template? I have had a few times where I wanted to make a small adjustment to an existing template and having to run a full job (that bypasses all of the stuff in the pot file ) is a bit cumbersome. Are the templates in files on disk or are they in the database?

f0cker commented 1 year ago

No there isn't, can you create a separate issue/feature request and I will add a Templates tab?

For now, you can disable brain which skips those steps mentioned above. You can also delete templates via the 'Q Task' dialogue and then re-add the job.

You should also be able to modify the json file for the template stored on the filesystem.

hkelley commented 1 year ago

Thanks. Found the file under /var/crackq/logs/templates/

hkelley commented 1 year ago

Should the template timeouts be in seconds? I haven't tested this exhaustively, but I think the timeout setting from the job may not be saved to the template.