-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hack Hunt
committed
Apr 14, 2021
1 parent
bb75d68
commit 553b051
Showing
7 changed files
with
258 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,55 @@ | ||
# verify-hash | ||
Verify Hash can be use to generate hash of a file or to verify the integrity of the file. | ||
# Verify Hash | ||
|
||
Verify Hash can be use to generate hash of a file or to verify the integrity of the file. | ||
|
||
### Supports Platform: Cross Platform | ||
|
||
### Programming Language: Python 3 and above | ||
|
||
### How to use: | ||
1. If you have *Python3* installed. You can use the `.py` file. | ||
- If you are using *Python with Windows*, use [verify_hash_no_color.py][1] file. | ||
- If you are using *Linux/macOS*, you can use any `.py` file. But if you are using colored version i.e., [verify_hash.py][2] make sure you install, *termcolor* package in Python. | ||
|
||
2. You can use **binaries/executable** version as well. | ||
- Binaries are in [executables][6] folder. | ||
- For ***Windows*** -> [Download][3] | ||
- For ***Linux*** -> [Download][4] | ||
- For ***macOS*** -> [Download][5] | ||
- After downloading, paste the file in `Documents` folder and open **Terminal/Command Prompt**. | ||
- Enter the command, `cd Documents`. | ||
- Run the file by typing `./` followed by file name. For eg., `./verify_hash.exe` (for Windows) and `./verify_hash` (for Linux/macOS). | ||
|
||
**Note:** On *Linux/macOS*, before running the file, you might need to run `chmod 755 verify_hash` to make it *executable*. | ||
|
||
### Available Arguments: | ||
- **-h or --help:** *Displays all the available options.* | ||
- **-f or --file:** *This option needs to be used as to define for which file you need the program to calculate hash value.* | ||
- **-t or --type:** *This options needs to be used as to define which type of hashing algorithm to support.* | ||
- **-v or --verify-hash:** *Optional. Can be used to specify a MAC Address.* | ||
|
||
**Note:** Program supports most of the common hashing algorithm, but if you uses an algorithm that is not supported by the program, it will gives back an **error**. | ||
|
||
### Color Significance: | ||
- **Green:** Successful. | ||
- **Blue:** In process. | ||
- **Red:** Unsuccessful or Errors. | ||
|
||
### Licensed: GNU General Public License, version 3 | ||
|
||
### Developer Information: | ||
- **Website:** https://www.hackhunt.in/ | ||
- **Contact:** [email protected] | ||
- **LinkedIn:** https://www.linkedin.com/company/hackhunt | ||
- **Youtube:** [@hackhunt](https://youtube.com/hackhunt) | ||
- **Instagram:** [@hh.hackhunt](https://www.instagram.com/hh.hackhunt/) | ||
- **Facebook:** [@hh.hackhunt](https://www.facebook.com/hh.hackhunt/) | ||
- **Twitter:** [hh_hackhunt](https://twitter.com/hh_hackhunt/) | ||
- **Patreon:** [@hackhunt](https://www.patreon.com/hackhunt) | ||
|
||
[1]: ./verify_hash_no_color.py | ||
[2]: ./verify_hash.py | ||
[3]: ./executables/windows/ | ||
[4]: ./executables/linux/ | ||
[5]: ./executables/mac/ | ||
[6]: ./executables/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import argparse | ||
import hashlib | ||
import os | ||
import sys | ||
from termcolor import colored | ||
|
||
|
||
BUFFER_SIZE = 3145728 # 3MB | ||
|
||
|
||
def get_hash(type_of_hash, filename): | ||
|
||
try: | ||
hash_obj = hashlib.new(type_of_hash) | ||
except ValueError: | ||
sys.exit("Not supported or invalid HASH type.") | ||
|
||
print(colored("\n[*] Calculating HASH value...", 'blue')) | ||
|
||
with open(filename, 'rb') as f: | ||
while True: | ||
data = f.read(BUFFER_SIZE) | ||
if not data: | ||
break | ||
hash_obj.update(data) | ||
|
||
return hash_obj.hexdigest() | ||
|
||
|
||
def get_arguments(): | ||
parser = argparse.ArgumentParser(prog="Verify Hash", | ||
usage="%(prog)s [options]\n\t[-f | --file] [location|name]_of_file\n\t[-t | " | ||
"--type] type_of_hash", | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description=""">>> | Verify Hash v1.0 by Hack Hunt | <<< | ||
---------------------------------""") | ||
|
||
parser._optionals.title = "Optional Argument" | ||
|
||
parser.add_argument('-v', '--verify-hash', | ||
dest='hash', | ||
metavar='', | ||
help='Specify the HASH to check with') | ||
|
||
required_arguments = parser.add_argument_group("Required Arguments") | ||
required_arguments.add_argument('-f', '--file', | ||
dest='name', | ||
metavar="", | ||
help="Specify the name and location of the file", | ||
required=True) | ||
|
||
required_arguments.add_argument('-t', '--type', | ||
dest='type', | ||
metavar='', | ||
help='Specify the HASH type, (SHA256/MD5)', | ||
required=True) | ||
|
||
args = parser.parse_args() | ||
check_input(args.name) | ||
return args | ||
|
||
|
||
def check_input(file_path): | ||
|
||
if not os.path.isfile(file_path): | ||
sys.exit("Invalid location of the file!") | ||
|
||
|
||
def main(): | ||
|
||
args = get_arguments() | ||
|
||
try: | ||
type_of_hash = args.type | ||
file_name = args.name | ||
hash_of_file = args.hash | ||
|
||
check_input(file_name) | ||
|
||
calc_hash = get_hash(type_of_hash, file_name) | ||
print(colored("\n{0}: {1}".format(type_of_hash.upper(), calc_hash), 'yellow')) | ||
|
||
if hash_of_file is not None: | ||
if calc_hash == hash_of_file: | ||
print(colored("[+] File is safe to use!", 'green')) | ||
else: | ||
print(colored("[-] File is not safe to use!", 'red')) | ||
|
||
except KeyboardInterrupt: | ||
print(colored("\n[+] Exiting...", "green")) | ||
sys.exit(0) | ||
|
||
except BaseException as e: | ||
print(colored("\n[-] Error: {0}".format(e), 'red')) | ||
sys.exit(1) | ||
|
||
|
||
############################################## | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import argparse | ||
import hashlib | ||
import os | ||
import sys | ||
|
||
|
||
BUFFER_SIZE = 3145728 # 3MB | ||
|
||
|
||
def get_hash(type_of_hash, filename): | ||
|
||
try: | ||
hash_obj = hashlib.new(type_of_hash) | ||
except ValueError: | ||
sys.exit("Not supported or invalid HASH type.") | ||
|
||
print("\n[*] Calculating HASH value...") | ||
|
||
with open(filename, 'rb') as f: | ||
while True: | ||
data = f.read(BUFFER_SIZE) | ||
if not data: | ||
break | ||
hash_obj.update(data) | ||
|
||
return hash_obj.hexdigest() | ||
|
||
|
||
def get_arguments(): | ||
parser = argparse.ArgumentParser(prog="Verify Hash", | ||
usage="%(prog)s [options]\n\t[-f | --file] [location|name]_of_file\n\t[-t | " | ||
"--type] type_of_hash", | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description=""">>> | Verify Hash v1.0 by Hack Hunt | <<< | ||
---------------------------------""") | ||
|
||
parser._optionals.title = "Optional Argument" | ||
|
||
parser.add_argument('-v', '--verify-hash', | ||
dest='hash', | ||
metavar='', | ||
help='Specify the HASH to check with') | ||
|
||
required_arguments = parser.add_argument_group("Required Arguments") | ||
required_arguments.add_argument('-f', '--file', | ||
dest='name', | ||
metavar="", | ||
help="Specify the name and location of the file", | ||
required=True) | ||
|
||
required_arguments.add_argument('-t', '--type', | ||
dest='type', | ||
metavar='', | ||
help='Specify the HASH type, (SHA256/MD5)', | ||
required=True) | ||
|
||
args = parser.parse_args() | ||
check_input(args.name) | ||
return args | ||
|
||
|
||
def check_input(file_path): | ||
|
||
if not os.path.isfile(file_path): | ||
sys.exit("Invalid location of the file!") | ||
|
||
|
||
def main(): | ||
|
||
args = get_arguments() | ||
|
||
try: | ||
type_of_hash = args.type | ||
file_name = args.name | ||
hash_of_file = args.hash | ||
|
||
check_input(file_name) | ||
|
||
calc_hash = get_hash(type_of_hash, file_name) | ||
print("\n{0}: {1}".format(type_of_hash.upper(), calc_hash)) | ||
|
||
if hash_of_file is not None: | ||
if calc_hash == hash_of_file: | ||
print("[+] File is safe to use!") | ||
else: | ||
print("[-] File is not safe to use!") | ||
|
||
except KeyboardInterrupt: | ||
print("\n[+] Exiting...") | ||
sys.exit(0) | ||
|
||
except BaseException as e: | ||
print("\n[-] Error: {0}".format(e)) | ||
sys.exit(1) | ||
|
||
|
||
############################################## | ||
if __name__ == '__main__': | ||
main() |