Skip to main content

A python module and script to execute functions inside a custom pool that distribute workers between threads and processes

Project description

bftool

Pypi PyPI version License: MIT Downloads

Logo

Index

Description

bftool is a python module and script, with a custom worker pool for the distribution of function execution into processes and threads based on a initial input, so you only need to focus on the functionality and not in the distribution of its execution.

Concepts

Time consuming functions

In the context of bftool the weight of a function is based on the time spent from when it was called to its finish.

Based on that we can conclude that this operations are most of the time heavy, since usually require more time to finish:

  • File I/O.
  • Networking I/O.
  • N Cycles (FOR, WHILE, ...).
  • Force waits (like sleep).

And this operations are usually light

  • Math.
  • Variable assign to a known value.
  • Some hash calculations.

Quick example

As a module

bftool auto detects if the function requires or not parallelism and based on that spawn the workers.

import hashlib
import string

import bftool

secret = "zz"
target = hashlib.sha3_512(secret.encode()).hexdigest()


def calc_hashes(salt: str, raw_password: str) -> tuple[str, str, str, str]:
    salt_password = (salt + raw_password).encode()
    return salt, raw_password, hashlib.blake2b(salt_password).hexdigest(), hashlib.sha3_512(
        salt_password).hexdigest()


def cracked(hashes: tuple[str, str, str, str]) -> bool:
    return target in hashes[2:]


def success(result: tuple[str, str, str, str]):
    print(f"[+] \"{result}\n", end="")


def main():
    arguments = bftool.Arguments(
        calc_hashes,
        bruteforce_rules={
            "raw_password": {
                "minlength": 1,
                "maxlength": 1,
                "elements": string.ascii_letters,
                "string-join": True
            },
            "salt": {
                "minlength": 1,
                "maxlength": 1,
                "elements": string.ascii_letters,
                "string-join": True
            }
        }
    )
    pool = bftool.Pool(
        calc_hashes,
        arguments,
        cracked,
        success,
        max_processes=3,
        max_threads=3
    )
    print("Fuzzing time:", pool.run())


if __name__ == "__main__":
    main()

As a script

python -m bftool --help
usage: bftool [-h] [-mt MAX_THREADS] [-mp MAX_PROCESSES] [-w WORDLIST] [-b BRUTEFORCE] [-sf SUCCESS_FUNCTION] [-cf CHECK_FUNCTION] [-sp SCRIPT_PATH] expression

positional arguments:
  expression            expression that will result in a callable

optional arguments:
  -h, --help            show this help message and exit
  -mt MAX_THREADS, --max-threads MAX_THREADS
                        Maximum number of threads per process
  -mp MAX_PROCESSES, --max-processes MAX_PROCESSES
                        Maximum number of process to have active at the same time
  -w WORDLIST, --wordlist WORDLIST
                        File wordlist to use based on "{'argument_1': FILE_PATH, ...}"
  -b BRUTEFORCE, --bruteforce BRUTEFORCE
                        Generate a virtual wordlist based on rules "{'argument_1': {'elements': [element_1, ...], 'minlength': INT, 'maxlength': INT, 'string-join': BOOL}, ...}"
  -sf SUCCESS_FUNCTION, --success-function SUCCESS_FUNCTION
                        Function to pass the success result to (default is custom 'print')
  -cf CHECK_FUNCTION, --check-function CHECK_FUNCTION
                        Function useful to check the output (default is 'lambda output: output')
  -sp SCRIPT_PATH, --script_path SCRIPT_PATH
                        Python script to import

Installation

Using pip

pip install bftool-pkg-sulcud

Manual

git clone https://github.com/shoriwe/bftool
cd bftool
python setup.py install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bftool-pkg-sulcud-2.0.1.tar.gz (10.6 kB view details)

Uploaded Source

File details

Details for the file bftool-pkg-sulcud-2.0.1.tar.gz.

File metadata

  • Download URL: bftool-pkg-sulcud-2.0.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.0

File hashes

Hashes for bftool-pkg-sulcud-2.0.1.tar.gz
Algorithm Hash digest
SHA256 2f7f3aca9bef55a6c1a5ada712c2b9ba416cfed0427b889be1f32e545244eea4
MD5 2ade08ed974ed18975b4a2fb099c167f
BLAKE2b-256 7bf222edcf245bb55a7eefb2fd56853013bcc5ee3469e667505f44938a355261

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page