Rich5 / pyhashcat

Python bindings for hashcat
56 stars 37 forks source link

Benchmark #22

Closed matlink closed 7 years ago

matlink commented 7 years ago

How is it possible to benchmark using pyHashcat? I tried with:

from pyhashcat import Hashcat
from time import sleep

hc = Hashcat()
hc.benchmark = True
hc.hash_mode = 0
hc.hashcat_session_execute()
sleep(5)

except that I got

$ python benchmark.py 
Traceback (most recent call last):
  File "benchmark.py", line 8, in <module>
    sleep(5)
RuntimeError: Hash source not set
matlink commented 7 years ago

Tried something home-made:

import sys 
import time
from pyhashcat import Hashcat

hc = Hashcat()
hc.hash = '8743b52063cd84097a65d1633f5c74f5'
hc.mask = '?d?d?d?d?d?d?d?d?d?d'
hc.quiet = True
hc.potfile_disable = True
hc.outfile = '/dev/null'
hc.workload_profile = 3 
hc.attack_mode = 3 
hc.hash_mode = 0 
hc.benchmark = False
print '[+] Running benchmark ...'
if hc.hashcat_session_execute() >= 0:
    ps = '-\\|/'
    i = 0 
    while True:
        i += 1
        sys.stdout.write("%s\r" % ps[i%4])
        sys.stdout.flush()
        time.sleep(1)
        if i == 5: break;
print(hc.status_get_hashes_msec_dev_benchmark(0))
print(hc.status_get_hashes_msec_dev_benchmark(1))

Works well, prints (per ms)

3096696.15181
4846983.19942

However, settings hc.benchmark = True doubles the output, is that normal? Looking for a better solution for benchmarking (i.e calling hashcat benchmark).

Rich5 commented 7 years ago

You know I haven't tried to benchmark yet. I'll have to dig into it more, but I agree this is something that should just work similar to how hashcat does.

Rich5 commented 7 years ago

So this is where your original error is coming from https://github.com/Rich5/pyHashcat/blob/6f5d565cf5b5c15e90efe564d6773bb20da2d8ce/pyhashcat/pyhashcat.c#L457

Which is an issue with my implementation. I need to account for calling benchmark as a special case.

Rich5 commented 7 years ago

Fixed. See test.py for simple example.