-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhashdumpdownload.py
103 lines (82 loc) · 2.96 KB
/
hashdumpdownload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from os import remove as rmfile
from urllib.request import urlretrieve
from urllib.error import URLError, HTTPError
from socket import create_connection
from os.path import isfile
import sqlite3
from sqlite3 import Error
def dbConnect():
conn = sqlite3.connect('History_Data.db')
return conn
print("Connected Successfully")
def dbCreate():
conn=dbConnect()
conn.execute(''' CREATE TABLE if not exists Bad_Hash (id INTEGER PRIMARY KEY AUTOINCREMENT ,md5 STRING);''')
#print("Table Created Successfully")
def dbInsert(d):
conn=dbConnect()
c=conn.cursor()
c.execute('INSERT INTO Bad_Hash(id,md5) values(NULL,"'+d+'");')
conn.commit()
conn.close()
print("Inserted TO DB : "+d)
# Check for internet connection
print("Checking for an internet connection...")
try:
create_connection(("www.google.com", 443))
print("Internet connection established!")
except OSError:
print("Please connect to the internet!")
exitexec(1)
# Clear Temporary File
if isfile("newhashes.txt"):
print("Removing temporary hashes file...")
print("Action completed!", end="\n")
dbCreate()
# Find all possible files
for i in range(0, 350):
print("Trying https://virusshare.com/hashes/VirusShare_{0}.md5...".format(
str(i).zfill(5)))
try:
# Try to download file
urlretrieve(
"https://virusshare.com/hashes/VirusShare_{0}.md5".format(
str(i).zfill(5)), "newhashes.txt")
print("Download success!")
print("Appending...")
with open("newhashes.txt", "r") as ff:
for ii in enumerate(ff.readlines()):
if not str(ii[1]).startswith("#"):
dbInsert(str(ii[1]))
print("DB load Complete!")
print("Removing temporary file...")
# Remove temporary file
rmfile("newhashes.txt")
print("Operation for file " + str(i).zfill(5) + " complete.", end="\n")
# Catch HTTP response code
except HTTPError as e:
# Check if code is 404
if e.code == 404:
print("File " + str(i).zfill(5) + " not found.")
print("Stopping...")
break
# Otherwise raise an error
else:
print("An error has occured: Recieved URL response code " + e.code)
# Exit the execution with a value of 1
exitexc(1)
# Catch server error
except URLError as e:
# Raise an error
print("Unable to reach the server: Reason provided is " + str(e.reason))
# Exit the execution with a value of 1
exitexc(1)
# Catch any other exception
except Exception as exc:
# Raise an error
print("ERROR: An error of type {0} occured because {1}".format(
type(exc).__name__, str(exc.args[0])))
# Exit the execution with a value of 1
exitexc(1)
# Notify user of completion
print("Hashes file creation complete.")