Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: Bad4m_cod3 en 23 Agosto 2023, 00:58 am



Título: Crackeador de Hashes MD5, SHA256, SHA512 con Python 3 [codigo fuente]
Publicado por: Bad4m_cod3 en 23 Agosto 2023, 00:58 am
A continuación procedo a presentar un codigo fuente diseñado para "Crackear" usando un Ataque de diccionario online y las librerias "colorama", hashlib, string, urllib. Claramente esta carente de limpieza, orden y comentarios por lo que pido ignorar esos importantes detalles. Pueden leer y utilizar el codigo a su placer...

 
Código
  1. #coding: utf-8
  2. from colorama import init, Fore, Back, Style
  3. import hashlib
  4. import string
  5. from urllib.request import urlopen
  6. #   )\      )  )\       )\())    )      ( /(  
  7. # (((_)  ( /( ((_) (   ((_)\  ( /(  (   )\())
  8. # )\___  )(_)) _   )\   _((_) )(_)) )\ ((_)\  
  9. #((/ __|((_)_ | | ((_) | || |((_)_ ((_)| |(_)
  10. # | (__ / _` || |/ _|  | __ |/ _` |(_-<| ' \  
  11. #  \___|\__,_||_|\__|  |_||_|\__,_|/__/|_||_|
  12.  
  13. #81dc9bdb52d04dc20036dbd8313ed055
  14.  
  15. init()#iniciar el colorama
  16. def art_ascii():
  17.  print(Fore.BLUE+"#-"*50+"#")
  18.  print(Fore.YELLOW+"   )\     )  )\      )\())    )      ( /(  ")                                                                
  19.  print(" (((_)  ( /( ((_) (   ((_)\ ( /(  (   )\()) ")                                                                
  20.  print(" )\___  )(_)) _   )\  _((_) )(_)) )\ ((_)\ ")                                                                
  21.  print("((/ __|((_)_ | | ((_) | || |((_)_ ((_)| |(_) ")                                                                
  22.  print(Fore.RED+"((/ __|((_)_ | | ((_) | || |((_)_ ((_)| |(_) ")                                                                
  23.  print(" | (__ / _` || |/ _|  | __ |/ _` |(_-<| ' \ ")                                                                
  24.  print("  \___|\__,_||_|\__|  |_||_|\__,_|/__/|_||_| ")
  25.  print(Fore.WHITE+"---| "+Fore.GREEN+".$$."+Fore.WHITE+"Bad4m_cod3"+Fore.GREEN+".$$."+Fore.WHITE+"|---")                                                          
  26.  print(Fore.MAGENTA+"\"a28ed83f69647d8f2a1046b9fa0e7c2c\""+Fore.GREEN+" H.P.Lovecraft")                                                          
  27.  print(Fore.BLUE+"#-"*50+"#"+Fore.WHITE)
  28.  
  29. def consol_prin(strdata):
  30.  print(Fore.BLUE+"--["+Fore.WHITE+"+"+Fore.BLUE+"]:"+Fore.WHITE+strdata)
  31.  
  32. def consol_input():
  33.  return str(input(Fore.BLUE+"--["+Fore.GREEN+"$.input.$"+Fore.BLUE+"]:"+Fore.WHITE))
  34.  
  35. def consol_error(errtext):
  36.  print(Fore.WHITE+"--["+Fore.RED+"Error!!"+Fore.WHITE+"]"+Fore.RED+":: "+errtext+Fore.WHITE)
  37.  
  38. def hash_text(strdata,typee):
  39.  if typee==0:
  40.    hashtxt = hashlib.md5(strdata).hexdigest()
  41.  elif typee==1:
  42.    hashtxt = hashlib.sha256(strdata).hexdigest()
  43.  elif typee==2:
  44.    hashtxt = hashlib.sha512(strdata).hexdigest()
  45.  else:
  46.    raise ValueError("Invalid Type Hash")
  47.  return hashtxt
  48.  
  49. def ishash(strhash,typee):
  50.  if all(inxx in string.hexdigits for inxx in strhash):
  51.    if typee==0:#md5
  52.      return len(strhash)==32
  53.    elif typpe==1:#sha256
  54.      return len(strhash)==64
  55.    elif typee==2:#sha512
  56.      return len(strhash)==128
  57.    else:
  58.      raise ValueError("Invalid Type Hash")
  59.  else:
  60.    return False
  61.  
  62. def return_case_hash(tphsh):
  63.  if tphsh=="md5":  return 0
  64.  elif tphsh=="sha256": return 1
  65.  elif tphsh=="sha512": return 2
  66.  else: return 99
  67.  
  68. def download_url(link):
  69.  return urlopen(link).read()
  70.  
  71. def main():
  72.  art_ascii()
  73.  global tp_hash
  74.  global hash_to_crack
  75.  consol_prin("Crackeadora de hashes")
  76.  
  77.  while True:
  78.    consol_prin("Seleccione el tipo de hash {md5,sha256,sha512}")
  79.    tipehash = consol_input()
  80.    tp_hash = return_case_hash(tipehash)
  81.  
  82.    if tp_hash == 99:
  83.      consol_error("Tipo de Hash invalido")
  84.    else:
  85.       break
  86.  
  87.  consol_prin("Tipo de hash selecionado [{}]".format(tipehash))
  88.  
  89.  while True:
  90.    consol_prin("Introduzca el HASH tipo {} que desea Crackear".format((tipehash)))
  91.    hash_to_crack = consol_input()
  92.    if ishash(hash_to_crack,tp_hash):
  93.      consol_prin("Iniciando Cracking de HASH: {} ...".format(hash_to_crack))
  94.      break
  95.    else:
  96.      consol_error("Hash {} invalida".format(hash_to_crack))
  97.  
  98.  consol_prin("Descangando Diccionario")
  99.  dicc = download_url("https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt")
  100.  consol_prin("Diccionario descargado")
  101.  consol_prin("Iniciando Ataque de diccionario "+Fore.RED+"[ATTACK INI]::::"+Fore.WHITE)
  102.  for inxx in dicc.split("\n".encode('utf-8')):
  103.    z = hash_text(inxx,tp_hash)
  104.    consol_prin("HASH:: {}          texto plano:: {}".format(z,inxx))
  105.    if z == hash_to_crack:
  106.      consol_prin("Password: {}         HASH: {}".format(inxx,z))
  107.      break
  108.  
  109. main()