Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashcat now works #94

Merged
merged 12 commits into from
Mar 27, 2021
Merged
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ Search-That-Hash searches the most popular hash cracking sites and automatically

Couldn't find it in any API? 😢 STH automatically pipes your input into Hashcat 🥳

Make sure to specify a wordlist if you want STH to use HashCat with `-w /path/to/wordlist`. If you are on Windows you must specify the path to your HashCat binary with the arg `-hashcat_binary /path/to/hashcat/exe` as shown above. 😊

Make sure to specify a wordlist if you want STH to use HashCat with `-w /path/to/wordlist`. If you are on Windows you must specify the path to your HashCat binary and folder in config.json 🙂
# 🔨 Installation

Install Search-That-Hash as fast as you can read this README. No, seriously -- it's that easy 😎
Expand Down
2 changes: 0 additions & 2 deletions config.toml

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "search-that-hash"
version = "0.2.2"
version = "0.2.5"
description = "Search hashes quickly before cracking them"
authors = ["brandon <brandon@skerritt.blog>","jayy <jayy2004@gmx.co.uk>"]
license = "GPL-3.0-or-later"
Expand Down
2 changes: 2 additions & 0 deletions search_that_hash/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import logging
import coloredlogs

from appdirs import *


@click.command()
@click.option("--text", "-t", type=str, help="Crack a single hash.")
Expand Down
31 changes: 29 additions & 2 deletions search_that_hash/config_object.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import toml
from appdirs import *
import json
from loguru import logger
Expand All @@ -8,6 +7,7 @@

import logging
import coloredlogs
import os.path


def cli_config(kwargs):
Expand Down Expand Up @@ -40,7 +40,7 @@ def api_config(hashes: str, sth_api: str = None):


def default_config():
return {
config = {
"api_keys": {"STH": "rGFbPbSXMF5ldzid2eyA81i6aCa497Z25MNgi8sa"},
"hashcat": False,
"api": False,
Expand All @@ -52,6 +52,33 @@ def default_config():
"offline": False,
}

defults = {

"hashes_dot_org":"test",
"sth_api":"rGFbPbSXMF5ldzid2eyA81i6aCa497Z25MNgi8sa",
"hashcat_exe_name":"hashcat",
"hashcat_folder":""

}

appname = "Search-That-Hash"
appauthor = "HashPals"

config_json = user_data_dir(appname, appauthor) + "\\config.json"

if not os.path.isfile(config_json):
os.makedirs(user_data_dir(appname, appauthor))
with open(config_json, "w+") as file:
file.write(json.dumps(defults))
file.close()

with open(config_json) as json_file:
json_contents = json.load(json_file)
json_file.close()

config.update(json_contents)

return config

def create_hash_config(hashes):
# Gets the results from name-that-hash
Expand Down
125 changes: 27 additions & 98 deletions search_that_hash/cracker/offline_mod/hashcat.py
Original file line number Diff line number Diff line change
@@ -1,111 +1,40 @@
import subprocess as sp


class Hashcat:
def crack(self, config):

hashcat_dict = str.maketrans({"$": "\\$"})

hash_formatted = config["chash"].translate(hashcat_dict)

for possible_type in config["hashcat_types"]:

# If its greppable then silence.

command = f"cd {config['hashcat_folder']} && {config['hashcat_exe_name']} -a 0 -m {possible_type} {hash_formatted} {config['wordlist']}"

if config["greppable"]:
if config["hashcat_binary"]: # If on windows run from binary folder
command = f".\\hashcat64.exe -a 0 -m {possible_type} {hash_formatted} {config['wordlist']}"
try:
sp.check_call(
command,
shell="True",
cwd=config["hashcat_binary"],
stdout=sp.DEVNULL,
stderr=sp.STDOUT,
)
except Exception as e:
if "returned non-zero exit status 1." in e:
continue
else:
return "Failed"

possible_output = str(
sp.check_output(
f"{command} --show",
shell=True,
cwd=config["hashcat_binary"],
).strip()
).strip("'")

if not "No hashes loaded." in possible_output:
return possible_output.split(":")[1]

else:
command = f"hashcat -a 0 -m {possible_type} {hash_formatted} {config['wordlist']}"
try:
sp.check_call(
command, shell="True", stdout=sp.DEVNULL, stderr=sp.STDOUT
)
except Exception as e:
if "returned non-zero exit status 1." in e:
continue
else:
return "Failed"

possible_output = str(
sp.check_output(
f"{command} --show",
shell=True,
cwd=config["hashcat_binary"],
).strip()
).strip("'")

if not "No hashes loaded." in possible_output:
return possible_output.split(":")[1]

config["greppable"] = sp.DEVNULL
else:
if config["hashcat_binary"]: # On windows? Run from binary folder
command = f"./hashcat64.exe -a 0 -m {possible_type} {hash_formatted} {config['wordlist']}"
try:
sp.check_call(
command,
shell="True",
cwd=config["hashcat_binary"],
)
except Exception as e:
if "returned non-zero exit status 1." in e:
continue
else:
return "Failed"

possible_output = str(
sp.check_output(
f"{command} --show",
shell=True,
cwd=config["hashcat_binary"],
).strip()
).strip("'")

if not "No hashes loaded." in possible_output:
return possible_output.split(":")[1]

config["greppable"] = None
try:
sp.check_call(
command,
shell="True",
cwd=config["hashcat_binary"],
stdout=config["greppable"],
stderr=config["greppable"],
)
except Exception as e:
if "returned non-zero exit status 1." in e:
continue
else:
command = f"hashcat -a 0 -m {possible_type} {hash_formatted} {config['wordlist']}"
try:
sp.check_call(
command,
shell="True",
)
except Exception as e:
if "returned non-zero exit status 1." in e:
continue
else:
return "Failed"

possible_output = str(
sp.check_output(f"{command} --show", shell=True).strip()
).strip("'")

if not "No hashes loaded." in possible_output:
return possible_output.split(":")[1]
return "Failed"
possible_output = str(
sp.check_output(
f"{command} --show",
shell=True,
cwd=config["hashcat_binary"],
).strip()
).strip("'")
if not "No hashes loaded." in possible_output:
return possible_output.split(":")[1]

return "Failed"
5 changes: 4 additions & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from click.testing import CliRunner

from search_that_hash.__main__ import main

import os.path

def test_it_works():

Expand Down Expand Up @@ -150,3 +150,6 @@ def test_cli_fail_on_grep(): # Fixes #63 issue
["-t", "jadjsjhd9239uh80dahjdah8isdh90wq90hj0j9fj9023j0-12j-j-0fasj0a", "-g"],
)
assert result.exit_code == 0

def test_if_config_file():
assert os.path.isfile(config_json) == True