etc~ scripts and random things |
| git clone https://github.com/djnnvx/etc.git |
| log | files | refs | archive |
gitea2hashcat.py (2389B)
1 #!/usr/bin/python3 2 # Converts gitea PBKDF2-HMAC-SHA256 hashes into a format hashcat can use 3 # written by unix-ninja 4 5 import argparse 6 import base64 7 import sys 8 9 def convert_hash(hash_string): 10 """Converts a SALT+HASH string to a hashcat compatible format, 11 ensuring the smaller input is treated as the salt. 12 Use : or | as delimeters. 13 """ 14 hash_string = hash_string.replace('|', ':') 15 try: 16 part1, part2 = hash_string.split(":") 17 except ValueError: 18 print(f"[-] Invalid input format: {hash_string}") 19 return None 20 21 try: 22 bytes1 = bytes.fromhex(part1) 23 bytes2 = bytes.fromhex(part2) 24 except ValueError: 25 print(f"[-] Invalid hex input: {hash_string}") 26 return None 27 28 # If lengths are equal, we will maintain the original order 29 if len(bytes1) > len(bytes2): 30 salt_bytes = bytes2 31 hash_bytes = bytes1 32 else: 33 salt_bytes = bytes1 34 hash_bytes = bytes2 35 36 37 salt_b64 = base64.b64encode(salt_bytes).decode('utf-8') 38 hash_b64 = base64.b64encode(hash_bytes).decode('utf-8') 39 40 return f"sha256:50000:{salt_b64}:{hash_b64}" 41 42 43 def main(): 44 parser = argparse.ArgumentParser(description="Convert Gitea SALT+HASH strings to a hashcat-compatible format.", 45 formatter_class=argparse.RawTextHelpFormatter, 46 epilog="""Example: 47 gitea2hashcat.py <salt1>:<hash1> <hash2>|<salt2> ... or pipe input from stdin. 48 49 You can also dump output straight from sqlite into this script: 50 sqlite3 gitea.db 'select salt,passwd from user;' | gitea2hashcat.py""") 51 parser.add_argument('hashes', nargs='*', help='SALT+HASH strings to convert') 52 args = parser.parse_args() 53 54 # ... (rest of the main function remains the same) 55 print("[+] Run the output hashes through hashcat mode 10900 (PBKDF2-HMAC-SHA256)") 56 print() 57 58 if args.hashes: 59 # Process command-line arguments 60 for hash_string in args.hashes: 61 converted_hash = convert_hash(hash_string) 62 if converted_hash: 63 print(converted_hash) 64 65 else: 66 # Process input from stdin 67 for line in sys.stdin: 68 hash_string = line.strip() # Remove leading/trailing whitespace 69 converted_hash = convert_hash(hash_string) 70 if converted_hash: 71 print(converted_hash) 72 73 74 if __name__ == "__main__": 75 main()