File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python2
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Fri May 24 00:10:01 2019
5
+
6
+ @author: uranusq
7
+ """
8
+ import json
9
+ from keras .models import model_from_json
10
+ from keras_preprocessing .text import tokenizer_from_json
11
+ import numpy as np
12
+ from keras .preprocessing import sequence
13
+
14
+ mode = 100
15
+
16
+
17
+ with open ("model_100api_600_genLegal.json" , "r" ) as f :
18
+ model = model_from_json (f .read ())
19
+ model .load_weights ('model_100api_600_check.h5' )
20
+
21
+ with open ("tokenizer.json" , "rb" ) as f :
22
+ data = json .load (f )
23
+ tokenizer = tokenizer_from_json (data )
24
+
25
+
26
+ def predict_rnn (api_calls ):
27
+ if len (api_calls ) > mode :
28
+ api_calls = api_calls [- mode :]
29
+ tokens = tokenizer .texts_to_sequences (api_calls )
30
+
31
+ if len (tokens ) < mode :
32
+ for i in range (mode - len (tokens )):
33
+ tokens .append ([0 ])
34
+ tokens = sequence .pad_sequences (tokens )
35
+ tokens = np .reshape (tokens , (1 , mode ))
36
+ #tokens = np.fliplr(tokens)
37
+ return model .predict (tokens )[0 ]
38
+
39
+
40
+ if __name__ == "__main__" :
41
+ api_calls = ["NtClose" , "LdrLoadDll" , "cryptacquirecontexta" ]
42
+ res = predict_rnn (api_calls )
43
+ if res > 0.5 :
44
+ print ("Malicious: " , res )
45
+ else :
46
+ print ("Ok: " , res )
47
+
You can’t perform that action at this time.
0 commit comments