-
Notifications
You must be signed in to change notification settings - Fork 5
/
Global_Vars.py
163 lines (117 loc) · 5.49 KB
/
Global_Vars.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
## ##
# Author: Peter Manev #
# peter.manev@openinfosecfoundation.org #
## ##
#you need to
#apt-get install tshark
## !!! IMPORTANT - LATEST DEV Scapy is needed !!!
# REMOVE your current scapy installation !!!
# then ->
# hg clone http://hg.secdev.org/scapy-com
# python setup.py install
import sys, urllib , os, subprocess, random
import yaml
from scapy.all import *
from ParseYamlConfig import parseYamlConfig
def init_Pcap_Id():
global pcap_id
pcap_id = 000
def load_The_Pcap():
global pcap_file_loaded
print "Provided pcap file is - " , sys.argv[1]
pcap_file_checked = sys.argv[1]
#check if pcap is there
if not os.path.isfile(pcap_file_checked):
sys.stderr.write('The supplied pcap file - %s - does not exist!!!\
\n' % pcap_file_checked)
sys.exit(1)
pcap_file_loaded = rdpcap(pcap_file_checked)
#return pcap_file_loaded
def preRunChecks():
global results_directory
global source_name
global repository_name
if len(sys.argv) != 5:
print sys.argv
sys.stderr.write('Usage: \n \
1. script name , \n \
2. full path to pcap file , \n \
3. full path to directory where results are wanted to be stored, \n \
4. source name - \"a-z, A-Z, 0-9, _\" characters allowed only !! \n \
5. repository - \"private\" , \"public\" , \"PRIVATE\" or \"PUBLIC\" \n \n \
EXAMPLE: python PacifyThePcap.py ../pcaps-and-misc/test.pcap ../TEST TestCasses private \
\n \n ' )
sys.exit(1)
print "Provided directory for results is - " , sys.argv[2]
results_directory = sys.argv[2]
print "Provided name for source is - ", sys.argv[3]
source_name = sys.argv[3]
#check if pcap to be name is in correct syntax
#for the regression script
if not (re.match('^[a-zA-Z0-9_]*$',source_name)):
sys.stderr.write('The supplied source name - %s - is not within syntax!!' \
% source_name)
sys.stderr.write('\nPlease use only \" a-z A-Z 0-9 _ \" characters !!\n')
sys.exit(1)
print "Provided name for the repository is - ", sys.argv[4]
repository_name = sys.argv[4]
#check if repository name is in correct syntax
#for the regression script - private, public, PRIVATE or PUBLIC
if not (re.match('(public|private|PUBLIC|PRIVATE)',repository_name)):
sys.stderr.write('The supplied repository name - %s - is not within syntax!!' \
% repository_name)
sys.stderr.write('\nPlease use only \"private\" , \"public\" , \"PRIVATE\" or \"PUBLIC\" words !!\n \n')
sys.exit(1)
#check if dir exists, if not
#create it
if not os.path.exists(results_directory):
print "Main directory does not exist - therefore - created.... \n %s" % \
results_directory
os.makedirs(results_directory)
#Python documentation - os.path.join()
#If any component is an absolute path, all previous components
#(on Windows, including the previous drive letter, if there was one)
#are thrown away, and joining continues.
if not os.path.exists(os.path.join(results_directory, 'Midstream')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'Midstream')
os.makedirs(os.path.join(results_directory, 'Midstream'))
if not os.path.exists(os.path.join(results_directory, 'Midstream', 'Dot1Q')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'Midstream', 'Dot1Q')
os.makedirs(os.path.join(results_directory, 'Midstream', 'Dot1Q'))
if not os.path.exists(os.path.join(results_directory, 'Midstream', 'QinQ')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'Midstream', 'QinQ')
os.makedirs(os.path.join(results_directory, 'Midstream', 'QinQ'))
if not os.path.exists(os.path.join(results_directory, 'Midstream', 'Regular')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'Midstream', 'Regular')
os.makedirs(os.path.join(results_directory, 'Midstream', 'Regular'))
if not os.path.exists(os.path.join(results_directory, 'Dot1Q')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'Dot1Q')
os.makedirs(os.path.join(results_directory, 'Dot1Q'))
if not os.path.exists(os.path.join(results_directory, 'QinQ')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'QinQ')
os.makedirs(os.path.join(results_directory, 'QinQ'))
if not os.path.exists(os.path.join(results_directory, 'Regular')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'Regular')
os.makedirs(os.path.join(results_directory, 'Regular'))
if not os.path.exists(os.path.join(results_directory, 'Rules')):
print "SubDirectory does not exist - therefore - created.... \n %s" % \
os.path.join(results_directory, 'Rules')
os.makedirs(os.path.join(results_directory, 'Rules'))
def returnYamlOptions():
global yaml_options
yaml_options = parseYamlConfig().parseYaml()
def returnProcessesToStart(yaml_options):
global processes_to_start
processes_to_start = parseYamlConfig().getProcesses(yaml_options)
def returnChunks(yaml_options):
global chunks
chunks = parseYamlConfig().getChunks(yaml_options)