Skip to content

Commit

Permalink
Merge pull request #58 from HashPals/bee-fix-ci
Browse files Browse the repository at this point in the history
Added more tests, increased code coverage, fixed bugs & changed license to GPLv3
  • Loading branch information
SkeletalDemise authored Feb 27, 2021
2 parents ff79c8d + 74b9179 commit 45167da
Show file tree
Hide file tree
Showing 20 changed files with 833 additions and 377 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
source = search_that_hash
omit = *migrations*, *tests*
12 changes: 7 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ name: Tests
on: push
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9']
name: Python ${{ matrix.python-version }}
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: pip install nox==2019.11.9
- run: pip install poetry==1.0.5
- run: nox
- run: python -m pip install flake8==3.8.4 nox==2020.12.31 poetry==1.1.4
- run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- run: python -m nox

876 changes: 674 additions & 202 deletions LICENSE

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ignore:
- "search_that_hash/cracker/offline_mod"

ignore:
- "search_that_hash/cracker/"
49 changes: 18 additions & 31 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> Non
args: Command-line arguments for pip.
kwargs: Additional keyword arguments for Session.install.
"""
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
"--without-hashes",
"--dev",
"--format=requirements.txt",
f"--output={requirements.name}",
external=True,
)
session.install(f"--constraint={requirements.name}", *args, **kwargs)
session.run(
"poetry",
"export",
"--without-hashes",
"--dev",
"--format=requirements.txt",
"--output=requirements.txt",
external=True,
)
session.install("--constraint=requirements.txt", *args, **kwargs)


@nox.session(python="3.8")
Expand All @@ -47,29 +46,16 @@ def black(session: Session) -> None:

@nox.session(python=["3.8", "3.7"])
def lint(session: Session) -> None:
"""Lint using flake8."""
args = session.posargs or locations
install_with_constraints(
session,
"flake8",
"flake8-annotations",
"flake8-bandit",
"flake8-black",
"flake8-bugbear",
"flake8-docstrings",
"flake8-import-order",
"darglint",
)
session.run("flake8", *args)
pass



@nox.session(python=["3.8", "3.7"])
def tests(session: Session) -> None:
"""Run the test suite."""
args = session.posargs or ["--cov", "-m", "not e2e"]
args = session.posargs or ["--cov", "--cov-fail-under=50", "-m", "not e2e"]
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(
session, "coverage[toml]", "pytest", "pytest-cov"
)
install_with_constraints(session, "coverage[toml]", "pytest", "pytest-cov")
session.run("pytest", *args)


Expand All @@ -81,9 +67,10 @@ def typeguard(session: Session) -> None:
install_with_constraints(session, "pytest", "pytest-mock", "typeguard")
session.run("pytest", f"--typeguard-packages={package}", *args)


@nox.session(python="3.8")
def coverage(session: Session) -> None:
"""Upload coverage data."""
install_with_constraints(session, "coverage[toml]", "codecov")
session.run("coverage", "xml", "--fail-under=0")
session.run("codecov", *session.posargs)
session.run("coverage", "xml", "--fail-under=50")
session.run("codecov", *session.posargs)
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[tool.poetry]
name = "search-that-hash"
version = "0.1.7"
version = "0.2.0"
description = "Search hashes quickly before cracking them"
authors = ["Jayy", "bee"]
authors = ["brandon <[email protected]>"]
license = "GPL-3.0-or-later"

[tool.poetry.dependencies]
python = "^3.7"
click = "^7.1.2"
appdirs = "^1.4.4"
toml = "^0.10.1"
loguru = "^0.5.2"
name-that-hash = "^1.1.5"
toml = "^0.10.2"
loguru = "^0.5.3"
name-that-hash = "^1.1.6"
requests = "^2.25.1"
rich = "^9.10.0"
rich = "^9.12.2"
coloredlogs = "^15.0"


Expand Down
2 changes: 1 addition & 1 deletion search_that_hash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
import __main__ as main

if __name__ == "__main__":
main.main() # pragma: no cover
main.main() # pragma: no cover
27 changes: 17 additions & 10 deletions search_that_hash/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,45 @@


@click.command()
@click.option("--text", "-t", type=str, help="Crack a single hash")
@click.option("--text", "-t", type=str, help="Crack a single hash.")
@click.option(
"-f",
"--file",
type=click.File("r"),
required=False,
help="The file of hashes, seperated by newlines.",
)
@click.option("-w", "--wordlist", type=str, required=False, help="The wordlist.")
@click.option("--timeout", type=int, help="Choose timeout time in second", default=2)
@click.option("--hashcat", is_flag=True, help="Runs Hashcat instead of John")
@click.option("-g", "--greppable", is_flag=True, help="Used to grep")
@click.option(
"-w",
"--wordlist",
type=str,
required=False,
help="The wordlist you want to use for Hashcat.",
)
@click.option("--timeout", type=int, help="Choose timeout in seconds.", default=3)
@click.option(
"-g", "--greppable", is_flag=True, help="Prints as JSON, use this to grep."
)
@click.option(
"--hashcat_binary",
type=str,
required=False,
help="Location of hashcat / john folder (if using windows)",
help="Location of hashcat folder (if using windows).",
)
@click.option(
"--offline",
"-o",
is_flag=True,
default=False,
type=bool,
help="Use offline mode. Does not search for hashes.",
help="Use offline mode. Does not search for hashes in APIs.",
)
@click.option(
"-v",
"--verbose",
count=True,
type=int,
help="Turn on debugging logs. -vv for max",
help="Turn on debugging logs. -vv for max.",
)
@click.option("--accessible", is_flag=True, help="Makes the output accessible.")
@click.option("--no-banner", is_flag=True, help="Doesn't print banner.")
Expand All @@ -61,7 +68,7 @@ def main(**kwargs):
\n
sth --text "5f4dcc3b5aa765d61d8327deb882cf99"
"""

levels = {1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG}

if kwargs["verbose"] and kwargs["verbose"] <= 3:
Expand All @@ -86,4 +93,4 @@ def main(**kwargs):


if __name__ == "__main__":
main() # pragma: no cover
main() # pragma: no cover
8 changes: 4 additions & 4 deletions search_that_hash/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import json


def return_as_json(hashes):
def return_as_json(hashes, api_key=None):

config = config_object.api_config(hashes)
config = config_object.api_config(hashes, api_key)
config["greppable"] = True
cracking_handler = handler.Handler(config)

Expand All @@ -15,9 +15,9 @@ def return_as_json(hashes):
return json_result


def return_as_fast_json(hashes):
def return_as_fast_json(hashes, api_key=None):

config = config_object.api_config(hashes)
config = config_object.api_config(hashes, api_key)
cracking_handler = handler.Handler(config)

json_result = cracking_handler.start()
Expand Down
6 changes: 4 additions & 2 deletions search_that_hash/config_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from appdirs import *
import json
from loguru import logger

logger.remove()
from name_that_hash import runner as nth

import logging
import coloredlogs


def cli_config(kwargs):

config = default_config()
Expand All @@ -32,7 +34,7 @@ def api_config(hashes: str, sth_api: str = None):
config = default_config()
config["hashes"] = create_hash_config(hashes)
config["api"] = True
if not sth_api:
if sth_api:
config["api_keys"]["STH"] = sth_api
return config

Expand All @@ -55,4 +57,4 @@ def create_hash_config(hashes):
# Gets the results from name-that-hash
logging.debug("Called NTH to get hash types")
nth_result_types = json.loads(nth.api_return_hashes_as_json(hashes))
return nth_result_types
return nth_result_types
9 changes: 4 additions & 5 deletions search_that_hash/cracker/cracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ def __init__(self, config):
self.searchers_offline = [hashcat.Hashcat()]
self.searchers_online = [
online.md5crypt(),
online.rainbow_tabels(),
online.hashdecryption(),
online.nitrxgen(),
online.cmd5(),
online.LmRainbowTabels(),
online.LmRainbowTables(),
online.md5_addr(),
online.md5_grom(),
online.sha1_grom(),
online.hashsorg(),
]

def main(self, chash, types) -> dict:
Expand All @@ -41,7 +40,7 @@ def perform_search(self, config, chash, types):

config["chash"] = chash
keys = [type["name"].lower() for type in types]
hashcat_types = [type["hashcat"] for type in types]
self.config["hashcat_types"] = [type["hashcat"] for type in types]
config["supported_searchers"] = []
config["supported_types"] = []

Expand Down Expand Up @@ -102,6 +101,6 @@ def threaded_search(self, config):
def call_searcher(self, search, future):
try:
return {type(search).__name__: search.crack(future)}
except Exception as e:
except:
logging.warning(f"{type(search).__name__} Failed")
return {type(search).__name__: "Failed"}
4 changes: 2 additions & 2 deletions search_that_hash/cracker/fast_mode_mod/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, config, sth_results):
def fast_crack(self):

results = self.sth.sth_output()

if results:
self.results.extend(results)

Expand Down Expand Up @@ -54,4 +54,4 @@ def fast_crack(self):

printing.Prettifier.one_print(chash, result)

return self.results
return self.results
6 changes: 5 additions & 1 deletion search_that_hash/cracker/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def __init__(self, config):
if config["api"]:
coloredlogs.install(level=logging.CRITICAL)

self.sth_results, self.config = sth.Sth_api.crack(config)
if not config["offline"]:
self.sth_results, self.config = sth.Sth_api.crack(self, config)
else:
self.config = config
self.sth_results = []

self.greppable = greppable.GreppableClass(self.config, self.sth_results)
self.fast = fast.FastClass(self.config, self.sth_results)
Expand Down
Loading

0 comments on commit 45167da

Please sign in to comment.