#!/bin/bash python312import sys3import struct4import hashlib5import hcshared6import hcsp78ST_HASH = "33522b0fd9812aa68586f66dba7c17a8ce64344137f9c7d8b11f32a6921c22de*9348746780603343"9ST_PASS = "hashcat"1011# In theory, you only have to implement this function...12def calc_hash(password: bytes, salt: dict) -> str:13salt_buf = hcshared.get_salt_buf(salt)14hash = hashlib.sha256(salt_buf + password) # the salt is prepended to the password as is (not as hex-bytes but as ASCII)15for i in range(10000):16hash = hashlib.sha256(hash.digest())17return hash.hexdigest()1819# ...except when using an esalt. The esalt void* structure is both dynamic and specific to a hash mode.20# If you use an esalt, you must convert its contents into Python datatypes.21# If you don't use esalt, just return []22# For this example hash-mode, we kept it very general and pushed all salt data in a generic format of generic sizes23# As such, it has to go into esalt24def extract_esalts(esalts_buf):25esalts=[]26for hash_buf, hash_len, salt_buf, salt_len in struct.iter_unpack("1024s I 1024s I", esalts_buf):27hash_buf = hash_buf[0:hash_len]28salt_buf = salt_buf[0:salt_len]29esalts.append({ "hash_buf": hash_buf, "salt_buf": salt_buf })30return esalts3132# From here you really can leave things as they are33# The init function is good for converting the hashcat data type because it is only called once34def kernel_loop(ctx,passwords,salt_id,is_selftest):35return hcsp.handle_queue(ctx,passwords,salt_id,is_selftest)3637def init(ctx):38# Uncomment this line below to dump the hashcat ctx for your salted hash39# hcshared.dump_hashcat_ctx(ctx, source=__name__) #enable this to dump the ctx from hashcat40hcsp.init(ctx,extract_esalts)4142def term(ctx):43hcsp.term(ctx)444546if __name__ == '__main__':47# Main is only run when debugging this python script and never when -m 72000 is called directly from hashcat cli4849hcshared.add_hashcat_path_to_environment()50# Load hashcat ctx from a file dumped when running -m 73000 . Optional argument is a Path() object to ctx file.51ctx = hcshared.load_ctx(ST_HASH)5253init(ctx)54hashcat_passwords = 25655passwords = []56for line in sys.stdin:57passwords.append(bytes(line.rstrip(), 'utf-8'))58if len(passwords) == hashcat_passwords:59hashes = kernel_loop(ctx,passwords,0,False)60passwords.clear()61hashes = kernel_loop(ctx,passwords,0,False) # remaining entries62if hashes:63print(hashes[-1])64term(ctx)656667