Skip to main content

A custom hash package including SHA256 and SHA1

Project description

MALHasher

malhasher is a custom Python package that provides SHA256 and SHA1 hashing functions, and a feature to match generated hash values against a dataset of hash values stored in a CSV file within the package.

Installation

To install the package, run the following command:

pip install malhasher

Features

  • SHA256 Hashing: Generate SHA256 hash values for strings and files.
  • SHA1 Hashing: Generate SHA1 hash values for strings and files.
  • Hash Matching: Match generated hash values against a precomputed dataset of hash values stored in a CSV file.

SHA256 Hashing

Generate SHA256 hash for a given string. Generate SHA256 hash for a file.

SHA1 Hashing

Generate SHA1 hash for a given string. Generate SHA1 hash for a file.

Hash Matching

Load a dataset of hash values from a CSV file. Match generated hash values against the dataset of hash values.

Importing the Package

from malhasher import sha256, sha1, sha256_file, sha1_file, load_hash_dataset_from_csv, load_hash_dataset_from_package, match_hash

Generate SHA256 Hash for a File

from malhasher import sha256_file

file_path = "path/to/your/file"
file_hash_value = sha256_file(file_path)
print(f"SHA256 file: {file_hash_value}")

Generate SHA256 Hash for a String

from malhasher import sha256

data = b"example data"
hash_value = sha256(data)
print(f"SHA256: {hash_value}")

Generate SHA1 Hash for a File

from malhasher import sha1_file

file_path = "path/to/your/file"
file_hash_value = sha1_file(file_path)
print(f"SHA1 file: {file_hash_value}")

Generate SHA1 Hash for a String

from malhasher import sha1

data = b"example data"
hash_value = sha1(data)
print(f"SHA1: {hash_value}")

Malware Hash Cheaking Using Defoult Dataset

import os
from malhasher import sha256_file, sha1_file, load_hash_dataset_from_package, match_hash

def check_file_for_malware(file_path):
    # Generate SHA256 and SHA1 hashes for the file
    sha256_hash = sha256_file(file_path)
    sha1_hash = sha1_file(file_path)

    # Load hash datasets from the package
    sha256_set, sha1_set = load_hash_dataset_from_package()

    # Check if the generated hashes match any in the datasets
    is_malware_sha256 = match_hash(sha256_hash, sha256_set)
    is_malware_sha1 = match_hash(sha1_hash, sha1_set)

    # Determine if the file is malware
    if is_malware_sha256 or is_malware_sha1:
        print(f"The file '{file_path}' is identified as malware.")
    else:
        print(f"The file '{file_path}' is not identified as malware.")

if __name__ == "__main__":
    # Specify the path to the file you want to check
    file_path = 'Your File Path'  # Replace with the actual file path

    if not os.path.isfile(file_path):
        print(f"File '{file_path}' does not exist.")
    else:
        check_file_for_malware(file_path)

Malware Hash Cheaking From External Dataset

import pandas as pd
import os
from malhasher import sha256_file, sha1_file

def check_file_for_malware(file_path, dataset_path):
    # Read the dataset
    dataset = pd.read_csv(dataset_path)
    
    # Generate SHA256 and SHA1 hashes for the file
    sha256_hash = sha256_file(file_path)
    sha1_hash = sha1_file(file_path)
    
    # Check if the generated hashes match any in the dataset
    match = dataset[(dataset['SHA256'] == sha256_hash) | (dataset['SHA1'] == sha1_hash)]
    
    if not match.empty:
        print(f"The file '{file_path}' is identified as malware.")
        for _, row in match.iterrows():
            print(f"Malware Type: {row['Type']}")
            print(f"Malware Family: {row['Family']}")
            print(f"Malware Size: {row['Size']} bytes")
            print(f"Malware Detections: {row['Detections']}")
            print(f"Malware Sandbox Behavior: {row['Sandbox Behavior']}")
    else:
        print(f"The file '{file_path}' is not identified as malware. Status: Undetectable")

# Example usage
file_path = 'Your File Path'  # Replace with the actual file path
dataset_path = 'YourDataset.csv'  # Replace with the actual dataset path

if os.path.isfile(file_path) and os.path.isfile(dataset_path):
    check_file_for_malware(file_path, dataset_path)
else:
    print("Invalid file path or dataset path.")

Thank Your For Use This Library

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

MALHasher-1.2.tar.gz (48.2 MB view details)

Uploaded Source

Built Distribution

MALHasher-1.2-py3-none-any.whl (48.2 MB view details)

Uploaded Python 3

File details

Details for the file MALHasher-1.2.tar.gz.

File metadata

  • Download URL: MALHasher-1.2.tar.gz
  • Upload date:
  • Size: 48.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for MALHasher-1.2.tar.gz
Algorithm Hash digest
SHA256 53a5594c9da13ac566b9a710feb6a1010a9d8ebbb5fc44b61ba57594a8bc313f
MD5 41c4d9f761beb4d5a1c4fb83a3a0806b
BLAKE2b-256 0a3115280bc942bd0cfab03773513458f30558677ad32cc6d92f1aab8610881b

See more details on using hashes here.

File details

Details for the file MALHasher-1.2-py3-none-any.whl.

File metadata

  • Download URL: MALHasher-1.2-py3-none-any.whl
  • Upload date:
  • Size: 48.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for MALHasher-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb2315a7592cb2417051939081100a962311d1c58368facbb703869e6fa8def5
MD5 d07c1c8f4ba4041ce9d9242f8ac9057f
BLAKE2b-256 577ec91e4ce18bd8798ed466de0bc1c7fc13cfb7d10af37d6abb78dc2de36855

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