forked from ytisf/theZoo
/
malware-db.py
138 lines (111 loc) · 4.01 KB
/
malware-db.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
#Malware DB - the most awesome free malware database on the air
#Copyright (C) 2014, Yuval Nativ, Lahad Ludar, 5Fingers
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
from imports import muchmuchstrings
__version__ = "0.4.2 Arthur"
__appname__ = "Malware DB"
__authors__ = ["Yuval Nativ","Lahad Ludar","5Fingers"]
__licensev__ = "GPL v3.0"
__maintainer = "Yuval Nativ"
__status__ = "Development"
import sys
import getopt
import csv
import os
from imports.updatehandler import Updater
from imports.eula_handler import EULA
from imports.globals import vars
from imports.terminal_handler import Controller
def main():
# Much much imports :)
updateHandler = Updater
eulaHandler = EULA()
bannerHandler = muchmuchstrings.banners()
terminalHandler = Controller()
def checkresults(array):
if len(array) == 0:
print "No results found\n\n"
sys.exit(1)
def checkargs():
print "Type: " + type_of_mal
print "Lang: " + pl
print "Search: " + search
def filter_array(array, colum, value):
ret_array = [row for row in array if value in row[colum]]
return ret_array
def print_results(array):
# print_results will suprisingly print the results...
answer = array[vars.column_for_uid] + "\t" + array[vars.column_for_name]+ "\t" + array[vars.column_for_version] + "\t\t"
answer += array[vars.column_for_location] + "\t\t" + array[vars.colomn_for_time]
print answer
# Here actually starts Main()
options, remainder = getopt.getopt(sys.argv[1:], 'hwuvs:p:t:', ['type=', 'language=', 'search=', 'help', 'update', 'version', 'dbv' ])
# Zeroing everything
type_of_mal = ""
pl = ""
search = ""
new =""
update=0
m=[];
f = ""
# Checking for EULA Agreement
a = eulaHandler.check_eula_file()
if a == 0:
eulaHandler.prompt_eula()
# Get arguments
for opt, arg in options:
if opt in ('-h', '--help'):
print vars.fulllicense
print vars.useage
sys.exit(1)
elif opt in ('-u', '--update'):
updateHandler.update_db()
sys.exit(1)
elif opt in ('-v', '--version'):
bannerHandler.versionbanner()
sys.exit(1)
elif opt in '-w':
bannerHandler.print_license()
sys.exit(1)
elif opt in ('-t', '--type'):
type_of_mal = arg
elif opt in ('-p', '--language'):
pl = arg
elif opt in ('-s', '--search'):
search = arg
elif opt in '--dbv':
# Getting version of malware-DB's database
a = updateHandler.get_maldb_ver()
if a == 0:
sys.exit(0)
elif len(a) > 0:
print ''
print "Malware-DB Database's version is: " + a
sys.exit()
# Take index.csv and convert into array m
csvReader = csv.reader(open(vars.main_csv_file, 'rb'), delimiter=',')
for row in csvReader:
m.append(row)
# Filter by type
if len(type_of_mal) > 0:
m = filter_array(m, vars.column_for_type, type_of_mal)
# Filter by programming language
if len(pl) > 0:
m = filter_array(m, vars.column_for_pl, pl)
os.system('clear')
print vars.maldb_banner
while 1:
terminalHandler.MainMenu()
sys.exit(1)
if __name__ == "__main__":
main()