@@ -25,21 +25,19 @@ import csv
25
25
import sys
26
26
import random
27
27
28
- from vdiscover .Detection import GetArgs , GetFiles , GetCmd
28
+ from vdiscover .Detection import GetArgs , GetFiles , GetCmd
29
29
30
30
# static feature extraction
31
31
32
32
from vdiscover .RandomWalk import RandomWalkElf
33
33
34
34
# dynamic feature extraction
35
35
36
- from vdiscover .Process import Process
37
- from vdiscover .Mutation import NullMutator , RandomByteMutator , RandomExpanderMutator , RandomInputMutator
38
- from vdiscover .Printer import TypePrinter
39
- from vdiscover .Misc import readmodfile
40
- from vdiscover .Input import prepare_inputs
41
-
42
-
36
+ from vdiscover .Process import Process
37
+ from vdiscover .Mutation import NullMutator , RandomByteMutator , RandomExpanderMutator , RandomInputMutator
38
+ from vdiscover .Printer import TypePrinter
39
+ from vdiscover .Misc import readmodfile
40
+ from vdiscover .Input import prepare_inputs
43
41
44
42
45
43
if __name__ == "__main__" :
@@ -48,16 +46,19 @@ if __name__ == "__main__":
48
46
random .seed ()
49
47
50
48
# To help argparse to detect the number of columns correctly
51
- #os.environ['COLUMNS'] = str(os.popen('stty size', 'r').read().split()[1]) #str(shutil.get_terminal_size().columns)
49
+ # os.environ['COLUMNS'] = str(os.popen('stty size',
50
+ # 'r').read().split()[1]) #str(shutil.get_terminal_size().columns)
52
51
53
52
if open ("/proc/sys/kernel/randomize_va_space" ).read ().strip () != "0" :
54
53
print ("Address space layout randomization (ASLR) is enabled, disable it before continue to use the cache" )
55
54
print ("Hint: # echo 0 > /proc/sys/kernel/randomize_va_space" )
56
55
sys .exit (- 1 )
57
56
58
57
# Arguments
59
- parser = argparse .ArgumentParser (description = 'Feature extraction of VDiscover' )
60
- parser .add_argument ("testcase" , help = "Testcase to analyze" , type = str , default = None )
58
+ parser = argparse .ArgumentParser (
59
+ description = 'Feature extraction of VDiscover' )
60
+ parser .add_argument (
61
+ "testcase" , help = "Testcase to analyze" , type = str , default = None )
61
62
62
63
parser .add_argument ("--static" ,
63
64
help = "Extract only static features from an executable" ,
@@ -67,54 +68,80 @@ if __name__ == "__main__":
67
68
help = "Extract only dynamic features from a testcase" ,
68
69
action = "store_true" , default = False )
69
70
70
- parser .add_argument ("--mclass" , type = str ,
71
- help = "Include class column, to use later in training mode" ,
72
- action = "store" , default = None )
71
+ parser .add_argument (
72
+ "--mclass" ,
73
+ type = str ,
74
+ help = "Include class column, to use later in training mode" ,
75
+ action = "store" ,
76
+ default = None )
73
77
74
78
parser .add_argument ("--out-file" ,
75
79
help = "File to output the extracted features" ,
76
80
type = str , default = "/dev/stdout" )
77
81
78
- parser .add_argument ("--max-subtraces-collected" , type = int ,
79
- help = "Maximum number of subtraces collected (static features only)" , default = 100 )
80
-
81
- parser .add_argument ("--max-subtraces-explored" , type = int ,
82
- help = "Maximum number of subtraces explored (static features only)" , default = 10000 )
83
-
84
- parser .add_argument ("--min-subtrace-size" , type = int ,
85
- help = "Minumum number of events in each subtrace collected (static features only)" , default = 3 )
86
-
87
- parser .add_argument ("--show-stdout" ,
88
- help = "Don't use /dev/null as stdout/stderr (dynamic features only)" ,
89
- action = "store_true" , default = False )
90
-
91
- parser .add_argument ("--inc-mods" ,
92
- help = "Only extract features from the libraries matching the strings inside this file (dynamic features only)" ,
93
- type = str , default = None )
94
-
95
- parser .add_argument ("--ign-mods" ,
96
- help = "Ignore extracted features from the libraries matching the string inside this file (dynamic features only)" ,
97
- type = str , default = None )
98
-
99
- parser .add_argument ("--timeout" , dest = "timeout" , type = int ,
100
- help = "Timeout in seconds (dynamic features only)" , default = 3 )
101
-
102
- parser .add_argument ("--max-mutations" , type = int ,
103
- help = "Maximum number of mutations to the original testcase (dynamic features only)" , default = 0 )
82
+ parser .add_argument (
83
+ "--max-subtraces-collected" ,
84
+ type = int ,
85
+ help = "Maximum number of subtraces collected (static features only)" ,
86
+ default = 100 )
87
+
88
+ parser .add_argument (
89
+ "--max-subtraces-explored" ,
90
+ type = int ,
91
+ help = "Maximum number of subtraces explored (static features only)" ,
92
+ default = 10000 )
93
+
94
+ parser .add_argument (
95
+ "--min-subtrace-size" ,
96
+ type = int ,
97
+ help = "Minumum number of events in each subtrace collected (static features only)" ,
98
+ default = 3 )
99
+
100
+ parser .add_argument (
101
+ "--show-stdout" ,
102
+ help = "Don't use /dev/null as stdout/stderr (dynamic features only)" ,
103
+ action = "store_true" ,
104
+ default = False )
105
+
106
+ parser .add_argument (
107
+ "--inc-mods" ,
108
+ help = "Only extract features from the libraries matching the strings inside this file (dynamic features only)" ,
109
+ type = str ,
110
+ default = None )
111
+
112
+ parser .add_argument (
113
+ "--ign-mods" ,
114
+ help = "Ignore extracted features from the libraries matching the string inside this file (dynamic features only)" ,
115
+ type = str ,
116
+ default = None )
117
+
118
+ parser .add_argument (
119
+ "--timeout" ,
120
+ dest = "timeout" ,
121
+ type = int ,
122
+ help = "Timeout in seconds (dynamic features only)" ,
123
+ default = 3 )
124
+
125
+ parser .add_argument (
126
+ "--max-mutations" ,
127
+ type = int ,
128
+ help = "Maximum number of mutations to the original testcase (dynamic features only)" ,
129
+ default = 0 )
104
130
105
131
options = parser .parse_args ()
106
132
testcase = options .testcase
107
133
108
134
static_only = options .static
109
135
dynamic_only = options .dynamic
110
136
111
- if (not static_only and not dynamic_only ) or (static_only and dynamic_only ):
112
- print "The feature extraction requires to select either static of dynamic features exclusively"
113
- exit (- 1 )
137
+ if (not static_only and not dynamic_only ) or (
138
+ static_only and dynamic_only ):
139
+ print "The feature extraction requires to select either static of dynamic features exclusively"
140
+ exit (- 1 )
114
141
115
142
max_subtraces_collected = options .max_subtraces_collected
116
- max_subtraces_explored = options .max_subtraces_explored
117
- min_subtrace_size = options .min_subtrace_size
143
+ max_subtraces_explored = options .max_subtraces_explored
144
+ min_subtrace_size = options .min_subtrace_size
118
145
119
146
incmodfile = options .inc_mods
120
147
ignmodfile = options .ign_mods
@@ -135,39 +162,42 @@ if __name__ == "__main__":
135
162
136
163
if static_only :
137
164
138
- RandomWalkElf (program , csvfile , mclass , max_subtraces_collected , max_subtraces_explored , min_subtrace_size )
165
+ RandomWalkElf (program , csvfile , mclass , max_subtraces_collected ,
166
+ max_subtraces_explored , min_subtrace_size )
139
167
140
168
elif dynamic_only :
141
169
142
- os .chdir ("inputs" )
170
+ os .chdir ("inputs" )
143
171
144
- envs = dict ()
145
- args = GetArgs ()
146
- files = GetFiles ()
172
+ envs = dict ()
173
+ args = GetArgs ()
174
+ files = GetFiles ()
147
175
148
- original_inputs = RandomInputMutator (args + files , NullMutator )
149
- #expanded_input_generator = RandomInputMutator(args + files, RandomExpanderMutator)
150
- mutated_input_generator = RandomInputMutator (args + files , RandomByteMutator )
151
- if included_mods == []:
152
- included_mods = [program ]
176
+ original_inputs = RandomInputMutator (args + files , NullMutator )
177
+ #expanded_input_generator = RandomInputMutator(args + files, RandomExpanderMutator)
178
+ mutated_input_generator = RandomInputMutator (
179
+ args + files , RandomByteMutator )
180
+ if included_mods == []:
181
+ included_mods = [program ]
153
182
154
- app = Process (program , envs , timeout , included_mods , ignored_mods , no_stdout = not show_stdout )
155
- prt = TypePrinter (csvfile , testcase , mclass )
183
+ app = Process (program , envs , timeout , included_mods ,
184
+ ignored_mods , no_stdout = not show_stdout )
185
+ prt = TypePrinter (csvfile , testcase , mclass )
156
186
157
- # unchanged input
158
- null_mutt , original_input = original_inputs .next ()
159
- original_events = app .getData (prepare_inputs (original_input ))
187
+ # unchanged input
188
+ null_mutt , original_input = original_inputs .next ()
189
+ original_events = app .getData (prepare_inputs (original_input ))
160
190
161
- if original_events is None :
162
- print "Execution of" ,program ,"failed!"
163
- exit (- 1 )
191
+ if original_events is None :
192
+ print "Execution of" , program , "failed!"
193
+ exit (- 1 )
164
194
165
- prt .print_events (program ,original_events )
195
+ prt .print_events (program , original_events )
166
196
167
- for (i , (d , mutated )) in enumerate (mutated_input_generator ):
197
+ for (i , (d , mutated )) in enumerate (mutated_input_generator ):
168
198
169
- if i >= max_mut :
170
- break
199
+ if i >= max_mut :
200
+ break
171
201
172
- events = app .getData (prepare_inputs (mutated ))
173
- prt .print_events (program ,events )
202
+ events = app .getData (prepare_inputs (mutated ))
203
+ prt .print_events (program , events )
0 commit comments