-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMalwareFamily_Classifier.py
72 lines (57 loc) · 1.83 KB
/
MalwareFamily_Classifier.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
#Static Malware Family Classifier based on Graph Comparison
# © Created By - Devyani Vij
#Header Files
import optparse
import networkx as nx
import re
import matplotlib.pyplot as plt
import pylab
import warnings
import os
import glob
import pyfiglet
warnings.filterwarnings("ignore")
a=False
#Banner
ascii_banner = pyfiglet.figlet_format("Android \t Application \t Family \t Classifier",width=100)
print(ascii_banner)
#Defining options
parser = optparse.OptionParser()
parser.add_option("-p","--path",dest="path",help="Input the Path of the Graph.")
parser.add_option("-g","--graph",dest="graph",help="Input the Name of the Graph.")
parser.add_option("-d","--dataset",dest="data",help="Input the Dataset.")
(options,arguments)=parser.parse_args()
if not options.path:
parser.error("[-] Please specify the Path of the GML using -p or --path")
elif not options.graph:
parser.error("[-] Please specify the GRAPH name by using -g or --graph")
elif not options.data:
parser.error("[-] Please specify the DATASET path name by using -d or --data")
#Reading the users entered .gml file
os.getcwd()
os.chdir(options.path)
os.getcwd()
arr = [x for x in os.listdir() if x.endswith(options.graph)]
files=glob.glob('*.gml')
G1 = nx.read_gml(arr[0],label='label')
#Reading the .gml dataset provide.
os.getcwd()
os.chdir(options.data)
os.getcwd()
files=glob.glob('*.gml')
#Checking whether the .gml belongs to any .gml in the dataset or not
for file in files:
J1 = nx.read_gml(file,label='label')
if(nx.is_isomorphic(J1,G1)):
a=True
b=file
break
else:
continue
print("\033[93mThe Application belongs to - ")
#Print whether it belongs to a family or it's Unknown/Goodware
if(a):
b = b.split('.gml')
print('\033[96m'+b[0]+' Android Family')
else:
print("\033[96mUnknown / GOODWARE")