Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Title: Machete
- # Purpose: Hash cracking
- # Version: 0.0.2
- # Author: Brandon Hammond
- # Import modules
- import os
- import sys
- import time
- import itertools
- import getopt
- import hashlib
- # Define main() function
- def main(argv):
- # Function: main()
- # Purpose: Parse user input
- # Version: 0.2
- # Parse user input
- try:
- # Attempt to parse user input
- print("[I] Parsing input")
- opts, args = getopt.getopt(sys.argv, "ha:t:w:", ["help", "alg=", "hash=", "wordlist="])
- except getopt.GetoptError:
- # Alert user to getopt() error and exit
- print("[E] Error parsing user input")
- sys.exit(2)
- # Process user input
- for opt, arg in opts:
- if opt == "-h" or opt == "--help":
- # Display help message and exit
- print("USAGE: machete [-h|-a {algorithm}|-t {hash}|-w {wordlist}]")
- sys.exit(0)
- elif opt == "-a" or opt == "--alg":
- # Set hash algorithm to use
- # Supported algorithms:
- # MD5, MD6, SHA-1, SHA-256, SHA-512, Whirlpool
- # Make sure something was entered
- if arg == None:
- print("[E] No algorithm was specified")
- sys.exit(2)
- # Convert arg to lowercase
- user_input = arg.lower()
- # Define hash_type as global variable
- global hash_type
- # Check that user_input matches a supported hash type
- if user_input == "md5":
- # Set hash_type to MD5
- hash_type = hashlib.md5
- elif user_input == "md6":
- # Set hash_type to MD6
- hash_type = hashlib.md6
- elif user_input == "sha1":
- # Set hash_type to SHA-1
- hash_type = hashlib.sha1
- elif user_input == "sha256":
- # Set hash_type to SHA-256
- hash_type = hashlib.sha256
- elif user_input == "sha512":
- # Set hash_type to SHA-512
- hash_type = hashlib.sha512
- elif user_input == "whirlpool":
- # Set hash_type tp Whirlpool
- hash_type = hashlib.whirlpool
- else:
- # If user specified hash is not supported
- # Print error message and exit
- print("[E] Specified hash type is not supported")
- sys.exit(2)
- elif opt == "-t" or opt == "--hash":
- # Set target_hash
- # Make sure hash was entered
- if arg == None:
- print("[E] No hash was specified")
- sys.exit(2)
- global target_hash
- target_hash = arg
- elif opt == "-w" or opt == "--wordlist":
- # Set wordlist to use
- # Make sure wordlist was specified
- if arg == None:
- print("[E] No wordlist was specified")
- sys.exit(2)
- global wordlist
- wordlist = arg
- else:
- # If invalid option entered
- print("[E] Invalid option")
- sys.exit(2)
- # Start brute force attack
- machete_attack(target_hash, hash_type, wordlist)
- def machete_attack(target_hash, hash_type, wordlist):
- # Function: machete_attack()
- # Purpose: Dictionary attack
- # Version: 0.1
- # Open the wordlist
- print("[I] Opening wordlist")
- f = open(wordlist, "w")
- # Write contents to a list
- # Lists are accessed faster than files
- print("[I] Optimizing Machete")
- flist = f.readlines()
- # Get length of list
- listlen = len(flist)
- # Initiate attack
- testhash = hash_type()
- for i in range(0, listlen):
- # Hash word
- testhash.update(flist[i])
- # Check if hashes match
- if testhash == target_hash:
- print("[F] Plaintext Found:")
- print(flist[i])
- sys.exit(0)
- # If plaintext not found
- print("[F] Plaintext not found")
- # Call main()
- if __name__ == "__main__":
- main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement