Advertisement
Guest User

Machete

a guest
Dec 6th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.38 KB | None | 0 0
  1. # Title: Machete
  2. # Purpose: Hash cracking
  3. # Version: 0.0.2
  4. # Author: Brandon Hammond
  5.  
  6. # Import modules
  7. import os
  8. import sys
  9. import time
  10. import itertools
  11. import getopt
  12. import hashlib
  13.  
  14. # Define main() function
  15. def main(argv):
  16.     # Function: main()
  17.     # Purpose: Parse user input
  18.     # Version: 0.2
  19.    
  20.     # Parse user input
  21.     try:
  22.         # Attempt to parse user input
  23.         print("[I] Parsing input")
  24.         opts, args = getopt.getopt(sys.argv, "ha:t:w:", ["help", "alg=", "hash=", "wordlist="])
  25.     except getopt.GetoptError:
  26.         # Alert user to getopt() error and exit
  27.         print("[E] Error parsing user input")
  28.         sys.exit(2)
  29.        
  30.     # Process user input
  31.     for opt, arg in opts:
  32.         if opt == "-h" or opt == "--help":
  33.             # Display help message and exit
  34.             print("USAGE: machete [-h|-a {algorithm}|-t {hash}|-w {wordlist}]")
  35.             sys.exit(0)
  36.         elif opt == "-a" or opt == "--alg":
  37.             # Set hash algorithm to use
  38.             # Supported algorithms:
  39.             # MD5, MD6, SHA-1, SHA-256, SHA-512, Whirlpool
  40.            
  41.             # Make sure something was entered
  42.             if arg == None:
  43.                 print("[E] No algorithm was specified")
  44.                 sys.exit(2)
  45.            
  46.             # Convert arg to lowercase
  47.             user_input = arg.lower()
  48.            
  49.             # Define hash_type as global variable
  50.             global hash_type
  51.            
  52.             # Check that user_input matches a supported hash type
  53.             if user_input == "md5":
  54.                 # Set hash_type to MD5
  55.                 hash_type = hashlib.md5
  56.             elif user_input == "md6":
  57.                 # Set hash_type to MD6
  58.                 hash_type = hashlib.md6
  59.             elif user_input == "sha1":
  60.                 # Set hash_type to SHA-1
  61.                 hash_type = hashlib.sha1
  62.             elif user_input == "sha256":
  63.                 # Set hash_type to SHA-256
  64.                 hash_type = hashlib.sha256
  65.             elif user_input == "sha512":
  66.                 # Set hash_type to SHA-512
  67.                 hash_type = hashlib.sha512
  68.             elif user_input == "whirlpool":
  69.                 # Set hash_type tp Whirlpool
  70.                 hash_type = hashlib.whirlpool
  71.             else:
  72.                 # If user specified hash is not supported
  73.                 # Print error message and exit
  74.                 print("[E] Specified hash type is not supported")
  75.                 sys.exit(2)
  76.         elif opt == "-t" or opt == "--hash":
  77.             # Set target_hash
  78.            
  79.             # Make sure hash was entered
  80.             if arg == None:
  81.                 print("[E] No hash was specified")
  82.                 sys.exit(2)
  83.            
  84.             global target_hash
  85.             target_hash = arg
  86.         elif opt == "-w" or opt == "--wordlist":
  87.             # Set wordlist to use
  88.            
  89.             # Make sure wordlist was specified
  90.             if arg == None:
  91.                 print("[E] No wordlist was specified")
  92.                 sys.exit(2)
  93.            
  94.             global wordlist
  95.             wordlist = arg
  96.         else:
  97.             # If invalid option entered
  98.             print("[E] Invalid option")
  99.             sys.exit(2)
  100.  
  101.     # Start brute force attack
  102.     machete_attack(target_hash, hash_type, wordlist)
  103.  
  104.  
  105.  
  106. def machete_attack(target_hash, hash_type, wordlist):
  107.     # Function: machete_attack()
  108.     # Purpose: Dictionary attack
  109.     # Version: 0.1
  110.    
  111.     # Open the wordlist
  112.     print("[I] Opening wordlist")
  113.     f = open(wordlist, "w")
  114.    
  115.     # Write contents to a list
  116.     # Lists are accessed faster than files
  117.     print("[I] Optimizing Machete")
  118.     flist = f.readlines()
  119.    
  120.     # Get length of list
  121.     listlen = len(flist)
  122.    
  123.     # Initiate attack
  124.     testhash = hash_type()
  125.     for i in range(0, listlen):
  126.         # Hash word
  127.         testhash.update(flist[i])
  128.        
  129.         # Check if hashes match
  130.         if testhash == target_hash:
  131.             print("[F] Plaintext Found:")
  132.             print(flist[i])
  133.             sys.exit(0)
  134.     # If plaintext not found
  135.     print("[F] Plaintext not found")
  136.        
  137. # Call main()      
  138. if __name__ == "__main__":
  139.     main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement