Skip to content

Commit 553b051

Browse files
author
Hack Hunt
committed
v1
1 parent bb75d68 commit 553b051

File tree

7 files changed

+258
-2
lines changed

7 files changed

+258
-2
lines changed

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
# verify-hash
2-
Verify Hash can be use to generate hash of a file or to verify the integrity of the file.
1+
# Verify Hash
2+
3+
Verify Hash can be use to generate hash of a file or to verify the integrity of the file.
4+
5+
### Supports Platform: Cross Platform
6+
7+
### Programming Language: Python 3 and above
8+
9+
### How to use:
10+
1. If you have *Python3* installed. You can use the `.py` file.
11+
- If you are using *Python with Windows*, use [verify_hash_no_color.py][1] file.
12+
- 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.
13+
14+
2. You can use **binaries/executable** version as well.
15+
- Binaries are in [executables][6] folder.
16+
- For ***Windows*** -> [Download][3]
17+
- For ***Linux*** -> [Download][4]
18+
- For ***macOS*** -> [Download][5]
19+
- After downloading, paste the file in `Documents` folder and open **Terminal/Command Prompt**.
20+
- Enter the command, `cd Documents`.
21+
- Run the file by typing `./` followed by file name. For eg., `./verify_hash.exe` (for Windows) and `./verify_hash` (for Linux/macOS).
22+
23+
**Note:** On *Linux/macOS*, before running the file, you might need to run `chmod 755 verify_hash` to make it *executable*.
24+
25+
### Available Arguments:
26+
- **-h or --help:** *Displays all the available options.*
27+
- **-f or --file:** *This option needs to be used as to define for which file you need the program to calculate hash value.*
28+
- **-t or --type:** *This options needs to be used as to define which type of hashing algorithm to support.*
29+
- **-v or --verify-hash:** *Optional. Can be used to specify a MAC Address.*
30+
31+
**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**.
32+
33+
### Color Significance:
34+
- **Green:** Successful.
35+
- **Blue:** In process.
36+
- **Red:** Unsuccessful or Errors.
37+
38+
### Licensed: GNU General Public License, version 3
39+
40+
### Developer Information:
41+
- **Website:** https://www.hackhunt.in/
42+
- **Contact:** hh.hackunt@gmail.com
43+
- **LinkedIn:** https://www.linkedin.com/company/hackhunt
44+
- **Youtube:** [@hackhunt](https://youtube.com/hackhunt)
45+
- **Instagram:** [@hh.hackhunt](https://www.instagram.com/hh.hackhunt/)
46+
- **Facebook:** [@hh.hackhunt](https://www.facebook.com/hh.hackhunt/)
47+
- **Twitter:** [hh_hackhunt](https://twitter.com/hh_hackhunt/)
48+
- **Patreon:** [@hackhunt](https://www.patreon.com/hackhunt)
49+
50+
[1]: ./verify_hash_no_color.py
51+
[2]: ./verify_hash.py
52+
[3]: ./executables/windows/
53+
[4]: ./executables/linux/
54+
[5]: ./executables/mac/
55+
[6]: ./executables/

executables/linux/verify_hash

6.54 MB
Binary file not shown.

executables/mac/verify_hash

6.2 MB
Binary file not shown.

executables/windows/verify_hash.exe

5.83 MB
Binary file not shown.

verify_hash.ico

187 KB
Binary file not shown.

verify_hash.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#! /usr/bin/env python3
2+
3+
import argparse
4+
import hashlib
5+
import os
6+
import sys
7+
from termcolor import colored
8+
9+
10+
BUFFER_SIZE = 3145728 # 3MB
11+
12+
13+
def get_hash(type_of_hash, filename):
14+
15+
try:
16+
hash_obj = hashlib.new(type_of_hash)
17+
except ValueError:
18+
sys.exit("Not supported or invalid HASH type.")
19+
20+
print(colored("\n[*] Calculating HASH value...", 'blue'))
21+
22+
with open(filename, 'rb') as f:
23+
while True:
24+
data = f.read(BUFFER_SIZE)
25+
if not data:
26+
break
27+
hash_obj.update(data)
28+
29+
return hash_obj.hexdigest()
30+
31+
32+
def get_arguments():
33+
parser = argparse.ArgumentParser(prog="Verify Hash",
34+
usage="%(prog)s [options]\n\t[-f | --file] [location|name]_of_file\n\t[-t | "
35+
"--type] type_of_hash",
36+
formatter_class=argparse.RawDescriptionHelpFormatter,
37+
description=""">>> | Verify Hash v1.0 by Hack Hunt | <<<
38+
---------------------------------""")
39+
40+
parser._optionals.title = "Optional Argument"
41+
42+
parser.add_argument('-v', '--verify-hash',
43+
dest='hash',
44+
metavar='',
45+
help='Specify the HASH to check with')
46+
47+
required_arguments = parser.add_argument_group("Required Arguments")
48+
required_arguments.add_argument('-f', '--file',
49+
dest='name',
50+
metavar="",
51+
help="Specify the name and location of the file",
52+
required=True)
53+
54+
required_arguments.add_argument('-t', '--type',
55+
dest='type',
56+
metavar='',
57+
help='Specify the HASH type, (SHA256/MD5)',
58+
required=True)
59+
60+
args = parser.parse_args()
61+
check_input(args.name)
62+
return args
63+
64+
65+
def check_input(file_path):
66+
67+
if not os.path.isfile(file_path):
68+
sys.exit("Invalid location of the file!")
69+
70+
71+
def main():
72+
73+
args = get_arguments()
74+
75+
try:
76+
type_of_hash = args.type
77+
file_name = args.name
78+
hash_of_file = args.hash
79+
80+
check_input(file_name)
81+
82+
calc_hash = get_hash(type_of_hash, file_name)
83+
print(colored("\n{0}: {1}".format(type_of_hash.upper(), calc_hash), 'yellow'))
84+
85+
if hash_of_file is not None:
86+
if calc_hash == hash_of_file:
87+
print(colored("[+] File is safe to use!", 'green'))
88+
else:
89+
print(colored("[-] File is not safe to use!", 'red'))
90+
91+
except KeyboardInterrupt:
92+
print(colored("\n[+] Exiting...", "green"))
93+
sys.exit(0)
94+
95+
except BaseException as e:
96+
print(colored("\n[-] Error: {0}".format(e), 'red'))
97+
sys.exit(1)
98+
99+
100+
##############################################
101+
if __name__ == '__main__':
102+
main()

verify_hash_no_color.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#! /usr/bin/env python3
2+
3+
import argparse
4+
import hashlib
5+
import os
6+
import sys
7+
8+
9+
BUFFER_SIZE = 3145728 # 3MB
10+
11+
12+
def get_hash(type_of_hash, filename):
13+
14+
try:
15+
hash_obj = hashlib.new(type_of_hash)
16+
except ValueError:
17+
sys.exit("Not supported or invalid HASH type.")
18+
19+
print("\n[*] Calculating HASH value...")
20+
21+
with open(filename, 'rb') as f:
22+
while True:
23+
data = f.read(BUFFER_SIZE)
24+
if not data:
25+
break
26+
hash_obj.update(data)
27+
28+
return hash_obj.hexdigest()
29+
30+
31+
def get_arguments():
32+
parser = argparse.ArgumentParser(prog="Verify Hash",
33+
usage="%(prog)s [options]\n\t[-f | --file] [location|name]_of_file\n\t[-t | "
34+
"--type] type_of_hash",
35+
formatter_class=argparse.RawDescriptionHelpFormatter,
36+
description=""">>> | Verify Hash v1.0 by Hack Hunt | <<<
37+
---------------------------------""")
38+
39+
parser._optionals.title = "Optional Argument"
40+
41+
parser.add_argument('-v', '--verify-hash',
42+
dest='hash',
43+
metavar='',
44+
help='Specify the HASH to check with')
45+
46+
required_arguments = parser.add_argument_group("Required Arguments")
47+
required_arguments.add_argument('-f', '--file',
48+
dest='name',
49+
metavar="",
50+
help="Specify the name and location of the file",
51+
required=True)
52+
53+
required_arguments.add_argument('-t', '--type',
54+
dest='type',
55+
metavar='',
56+
help='Specify the HASH type, (SHA256/MD5)',
57+
required=True)
58+
59+
args = parser.parse_args()
60+
check_input(args.name)
61+
return args
62+
63+
64+
def check_input(file_path):
65+
66+
if not os.path.isfile(file_path):
67+
sys.exit("Invalid location of the file!")
68+
69+
70+
def main():
71+
72+
args = get_arguments()
73+
74+
try:
75+
type_of_hash = args.type
76+
file_name = args.name
77+
hash_of_file = args.hash
78+
79+
check_input(file_name)
80+
81+
calc_hash = get_hash(type_of_hash, file_name)
82+
print("\n{0}: {1}".format(type_of_hash.upper(), calc_hash))
83+
84+
if hash_of_file is not None:
85+
if calc_hash == hash_of_file:
86+
print("[+] File is safe to use!")
87+
else:
88+
print("[-] File is not safe to use!")
89+
90+
except KeyboardInterrupt:
91+
print("\n[+] Exiting...")
92+
sys.exit(0)
93+
94+
except BaseException as e:
95+
print("\n[-] Error: {0}".format(e))
96+
sys.exit(1)
97+
98+
99+
##############################################
100+
if __name__ == '__main__':
101+
main()

0 commit comments

Comments
 (0)