-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.py
170 lines (124 loc) · 4.61 KB
/
preprocess.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
import operator
import random
from data import data
####### WINWEBSEC #######
path = "Malicia-Big3-Opcodes/winwebsec/"
filelist = os.listdir(path)
for x in filelist:
with open(path + x, "r") as y:
read_data_winwebsec = y.read()
unique_winwebsec = []
dist_winwebsec = {}
unique_count_winwebsec = 0
ranked_dist_winwebsec = {}
ranked_dist_winwebsec["A"] = []
ranked_dist_winwebsec["B"] = []
ranked_dist_winwebsec["C"] = []
list_winwebsec = read_data_winwebsec.split()
for item in list_winwebsec:
if item not in unique_winwebsec:
unique_count_winwebsec += 1
unique_winwebsec.append(item)
for unique in unique_winwebsec:
x = data.counter(list_winwebsec, unique)
dist_winwebsec[unique]= x
sorted_dist_winwebsec = dict(sorted(dist_winwebsec.items(), key=operator.itemgetter(1), reverse=True))
for key in sorted_dist_winwebsec:
if sorted_dist_winwebsec[key] >= 100:
ranked_dist_winwebsec["A"].append(key)
if 10 <= sorted_dist_winwebsec[key] <= 99:
ranked_dist_winwebsec["B"].append(key)
if sorted_dist_winwebsec[key] <= 9:
ranked_dist_winwebsec["C"].append(key)
for item in list_winwebsec:
if item in ranked_dist_winwebsec["A"]:
list_winwebsec[list_winwebsec.index(item)] = 0
if item in ranked_dist_winwebsec["B"]:
list_winwebsec[list_winwebsec.index(item)] = 1
if item in ranked_dist_winwebsec["C"]:
list_winwebsec[list_winwebsec.index(item)] = 2
trainingset_winwebsec = open("training-data/trainingset_winwebsec.txt", "w")
for element in list_winwebsec:
trainingset_winwebsec.write(f'{element} \n')
trainingset_winwebsec.close()
####### ZBOT #######
path = "Malicia-Big3-Opcodes/zbot/"
filelist = os.listdir(path)
for x in filelist:
with open(path + x, "r") as y:
read_data_zbot = y.read()
unique_zbot = []
dist_zbot = {}
unique_count_zbot = 0
ranked_dist_zbot = {}
ranked_dist_zbot["A"] = []
ranked_dist_zbot["B"] = []
ranked_dist_zbot["C"] = []
list_zbot = read_data_zbot.split()
for item in list_zbot:
if item not in unique_zbot:
unique_count_zbot += 1
unique_zbot.append(item)
for unique in unique_zbot:
x = data.counter(list_zbot, unique)
dist_zbot[unique]= x
sorted_dist_zbot = dict(sorted(dist_zbot.items(), key=operator.itemgetter(1), reverse=True))
for key in sorted_dist_zbot:
if sorted_dist_zbot[key] >= 100:
ranked_dist_zbot["A"].append(key)
if 10 <= sorted_dist_zbot[key] <= 99:
ranked_dist_zbot["B"].append(key)
if sorted_dist_zbot[key] <= 9:
ranked_dist_zbot["C"].append(key)
for item in list_zbot:
if item in ranked_dist_zbot["A"]:
list_zbot[list_zbot.index(item)] = 0
if item in ranked_dist_zbot["B"]:
list_zbot[list_zbot.index(item)] = 1
if item in ranked_dist_zbot["C"]:
list_zbot[list_zbot.index(item)] = 2
trainingset_zbot = open("training-data/trainingset_zbot.txt", "w")
for element in list_zbot:
trainingset_zbot.write(f'{element} \n')
trainingset_zbot.close()
####### ZEROACCESS #######
path = "Malicia-Big3-Opcodes/zeroaccess/"
filelist = os.listdir(path)
for x in filelist:
with open(path + x, "r") as y:
read_data_zeroaccess = y.read()
unique_zeroaccess = []
dist_zeroaccess = {}
unique_count_zeroaccess = 0
ranked_dist_zeroaccess = {}
ranked_dist_zeroaccess["A"] = []
ranked_dist_zeroaccess["B"] = []
ranked_dist_zeroaccess["C"] = []
list_zeroaccess = read_data_zeroaccess.split()
for item in list_zeroaccess:
if item not in unique_zeroaccess:
unique_count_zeroaccess += 1
unique_zeroaccess.append(item)
for unique in unique_zeroaccess:
x = data.counter(list_zeroaccess, unique)
dist_zeroaccess[unique]= x
sorted_dist_zeroaccess = dict(sorted(dist_zeroaccess.items(), key=operator.itemgetter(1), reverse=True))
for key in sorted_dist_zeroaccess:
if sorted_dist_zeroaccess[key] >= 100:
ranked_dist_zeroaccess["A"].append(key)
if 10 <= sorted_dist_zeroaccess[key] <= 99:
ranked_dist_zeroaccess["B"].append(key)
if sorted_dist_zeroaccess[key] <= 9:
ranked_dist_zeroaccess["C"].append(key)
for item in list_zeroaccess:
if item in ranked_dist_zeroaccess["A"]:
list_zeroaccess[list_zeroaccess.index(item)] = 0
if item in ranked_dist_zeroaccess["B"]:
list_zeroaccess[list_zeroaccess.index(item)] = 1
if item in ranked_dist_zeroaccess["C"]:
list_zeroaccess[list_zeroaccess.index(item)] = 2
trainingset_zeroaccess = open("training-data/trainingset_zeroaccess.txt", "w")
for element in list_zeroaccess:
trainingset_zeroaccess.write(f'{element} \n')
trainingset_zeroaccess.close()