yes sure here it is
app.task
def load_regex_patterns(f):
with open(f, 'r', encoding='utf-8') as f:
regex_patterns = json.load(f)
return regex_patterns
@app.task
def parse_hashcat_output(process, regex_patterns):
try:
for line in process.stdout:
output = {}
for pattern_name, pattern in regex_patterns.items():
match = re.search(pattern, line)
if match:
output[pattern_name] = match.group(1)
yield json.dumps(output)
time.sleep(1)
except KeyboardInterrupt:
process.terminate()
process.wait()
raise
finally:
process.wait()
process.stdout.close()
@app.task
def run_hashcat(hash_file, hashtype, wordlist, rule_year):
patterns_dir = r'..\backend\data\hashcat_patterns.json'
os.chdir(r'C:\Program Files (x86)\hashcat-6.2.5')
command = ['hashcat.exe', '-m', hashtype, '-d', '1', hash_file, wordlist, '-r', rule_year]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
regex_patterns = load_regex_patterns.delay(patterns_dir).get()
yield from parse_hashcat_output.delay(process, regex_patterns)```
and this is the patterns.json
```{
"session": "Session\\.*: (.+)",
"status": "Status\\.*: (.+)",
"hash_mode": "Hash\\.Mode\\.*: (.+)",
"hash_target": "Hash\\.Target\\.*: (.+)",
"time_started": "Time\\.Started\\.*: (.+)",
"time_estimated": "Time\\.Estimated\\.*: (.+)",
"kernel_feature": "Kernel\\.Feature\\.*: (.+)",
"guess_base": "Guess\\.Base\\.*: (.+)",
"guess_mod": "Guess\\.Mod\\.*: (.+)",
"guess_queue": "Guess\\.Queue\\.*: (.+)",
"speed": "Speed\\.#1\\.*: (.+)"}
i tried this options too
command = ['hashcat.exe', '-m', '1000', '-d', '1', hash_list, WORDLIST ,'-r', rule_year]
def send_status(proc):
proc.stdin.write("s\n")
proc.stdin.flush()
with open(output_file, "w") as f:
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, universal_newlines=True)
for line in process.stdout:
print(line, end='', flush=True)
f.write(line)
if "[s]tatus [p]ause [b]ypass [c]heckpoint [f]inish [q]uit =>" in line:
send_status(process)
print("Output saved to:", output_file)