Skip to content

Commit 8d15ad6

Browse files
committed
Multiple tags concealment now supported for offset/value parameters, ongoing work into path
1 parent c34d13e commit 8d15ad6

File tree

9 files changed

+79
-40
lines changed

9 files changed

+79
-40
lines changed

dhalsim/network_attacks/concealment_netfilter_queue.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, intermediate_yaml_path: Path, yaml_index: int, queue_number:
3131
if 'concealment_data' in self.intermediate_attack.keys():
3232
if self.intermediate_attack['concealment_data']['type'] == 'path':
3333
self.concealment_type = 'path'
34-
self.concealment_data_pd = pd.read_csv(self.intermediate_attack['concealment_data'])
34+
self.concealment_data_pd = pd.read_csv(self.intermediate_attack['concealment_data']['path'])
3535
elif self.intermediate_attack['concealment_data']['type'] == 'value':
3636
self.concealment_type = 'value'
3737
else:
@@ -45,41 +45,45 @@ def get_attack_tag(self, a_tag_name):
4545
return tag
4646

4747
def handle_enip_response(self, ip_payload):
48-
this_session = int.from_bytes(p[Raw].load[4:8], sys.byteorder)
48+
this_session = int.from_bytes(ip_payload[Raw].load[4:8], sys.byteorder)
4949
this_context = int.from_bytes(ip_payload[Raw].load[12:20], sys.byteorder)
50-
this_session_dict = None
50+
51+
self.logger.debug('ENIP response session: ' + str(this_session))
52+
self.logger.debug('ENIP response context: ' + str(this_context))
5153

5254
# Attack values to PLCs
5355
for session in self.attack_session_ids:
5456
# We support multi tag sending, using the same session. Context varies among tags
5557
if session['session'] == this_session and session['context'] == this_context:
56-
this_session_dict = session
5758
for tag in self.intermediate_attack['tags']:
58-
if this_session_dict['tag'] == tag['tag']:
59-
if 'value' in tag['tag'].keys():
59+
if session['tag'] == tag['tag']:
60+
if 'value' in tag.keys():
6061
return translate_float_to_payload(tag['value'], ip_payload[Raw].load)
6162

62-
elif 'offset' in tag['tag'].keys():
63-
return translate_float_to_payload(translate_payload_to_float(p[Raw].load) + tag['value'],
63+
elif 'offset' in tag.keys():
64+
return translate_float_to_payload(translate_payload_to_float(ip_payload[Raw].load) + tag['offset'],
6465
ip_payload[Raw].load)
6566

6667
# Concealment values to SCADA
6768
for session in self.scada_session_ids:
6869
if session['session'] == this_session and session['context'] == this_context:
69-
this_session_dict = session
70-
for tag in self.intermediate_attack['tags']:
71-
if this_session_dict['tag'] == tag['tag']:
72-
self.logger.debug('Concealing to SCADA: ' + str(this_session))
73-
if self.concealment_type == 'path':
70+
for tag in self.intermediate_attack['concealment_data']['concealment_value']:
71+
if session['tag'] == tag['tag']:
72+
if self.intermediate_attack['concealment_data']['type'] == 'value':
73+
self.logger.debug('Concealing to SCADA: ' + str(this_session))
74+
concealment_value = tag['value']
75+
self.logger.debug('Concealment value is: ' + str(concealment_value))
76+
return translate_float_to_payload(concealment_value, ip_payload[Raw].load)
77+
elif self.intermediate_attack['concealment_data']['type'] == 'offset':
78+
self.logger.debug('Concealing to SCADA: ' + str(this_session))
79+
return translate_float_to_payload(translate_payload_to_float(ip_payload[Raw].load) + tag['offset'],
80+
ip_payload[Raw].load)
81+
elif self.intermediate_attack['concealment_data']['type'] == 'path':
82+
self.logger.debug('Concealing to SCADA: ' + str(this_session))
7483
exp = (self.concealment_data_pd['iteration'] == self.get_master_clock())
7584
concealment_value = float(self.concealment_data_pd.loc[exp][self.attacked_tags].values[-1])
7685
self.logger.debug('Concealing with value: ' + str(concealment_value))
77-
return translate_float_to_payload(concealment_value, ip_payload[Raw].load)
78-
elif self.concealment_type == 'value':
79-
concealment_value = self.intermediate_attack['concealment_data']['concealment_value']
80-
self.logger.debug('Concealment value is: ' + str(concealment_value))
81-
return translate_float_to_payload(concealment_value, ip_payload[Raw].load)
82-
86+
p[Raw].load = translate_float_to_payload(concealment_value, p[Raw].load)
8387

8488
def handle_enip_request(self, ip_payload, offset):
8589

@@ -90,9 +94,10 @@ def handle_enip_request(self, ip_payload, offset):
9094
self.logger.debug('this tag is: ' + str(tag_name))
9195
this_tag = self.get_attack_tag(tag_name)
9296

93-
self.logger.debug('Tag name: ' + str(tag_name))
94-
self.logger.debug('Attack tag: ' + str(this_tag['tag']))
97+
#self.logger.debug('Tag name: ' + str(tag_name))
98+
#self.logger.debug('Attack tag: ' + str(this_tag['tag']))
9599
session_dict = {'session': this_session, 'tag': this_tag['tag'], 'context': context}
100+
self.logger.debug('session dict: ' + str(session_dict))
96101

97102
if ip_payload[IP].src == self.intermediate_yaml['scada']['public_ip']:
98103
self.logger.debug('SCADA Req session')
@@ -102,7 +107,6 @@ def handle_enip_request(self, ip_payload, offset):
102107
self.logger.debug('PLC Req session')
103108
self.attack_session_ids.append(session_dict)
104109

105-
106110
def capture(self, packet):
107111
"""
108112
This function is the function that will run in the thread started in the setup function.
@@ -123,12 +127,17 @@ def capture(self, packet):
123127
packet.set_payload(bytes(p))
124128
self.logger.debug(f"Value of network packet for {p[IP].dst} overwritten.")
125129
packet.accept()
130+
return
126131

127132
else:
128133
if len(p) == 118:
134+
self.logger.debug('handling request 57')
129135
self.handle_enip_request(p, 57)
136+
self.logger.debug('handled request')
130137
elif len(p) == 116:
138+
self.logger.debug('handling request 56')
131139
self.handle_enip_request(p, 56)
140+
self.logger.debug('handled request')
132141
else:
133142
packet.accept()
134143
return

dhalsim/network_attacks/synced_attack.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ def main_loop(self):
305305
pass
306306

307307
self.set_sync(3)
308-
self.logger.debug("Setting sync in 3")
309308

310309
@abstractmethod
311310
def attack_step(self):

examples/anytown_topology/anytown_concealment_mitm.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ network_attacks:
66
value: 8.0
77
concealment_data:
88
type: value
9-
concealment_value: 42.0
9+
concealment_value:
10+
- tag:
1011
#type: path
1112
#path: concealment_test.csv
1213
trigger:

examples/anytown_topology/anytown_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ demand: pdd
99
log_level: debug
1010
demand_patterns: demands_anytown_small.csv
1111
#attacks: !include anytown_concealment_mitm.yaml
12+
attacks: !include anytown_dos.yaml

examples/ctown_topology/ctown_concealment_mitm.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
network_attacks:
2+
- name: plc4attack
3+
type: concealment_mitm
4+
tags:
5+
- tag: T3
6+
value: 8.0
7+
- tag: T4
8+
value: 8.0
9+
target: PLC4
10+
concealment_data:
11+
type: path
12+
path: concealment_test.csv
13+
trigger:
14+
#start: 648
15+
#end: 792
16+
start: 10
17+
end: 15
18+
type: time
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
network_attacks:
2+
- name: plc4attack
3+
type: concealment_mitm
4+
tags:
5+
- tag: T3
6+
offset: 10.0
7+
- tag: T4
8+
offset: 10.0
9+
target: PLC4
10+
concealment_data:
11+
type: value
12+
concealment_value:
13+
- tag: T3
14+
value: 42.0
15+
- tag: T4
16+
value: 84.0
17+
trigger:
18+
start: 648
19+
end: 792
20+
type: time
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
inp_file: ctown_map.inp
2-
iterations: 2880
2+
#iterations: 2880
3+
iterations: 20
34
network_topology_type: complex
45
plcs: !include ctown_plcs.yaml
56

67
log_level: debug
78
simulator: epynet
89
demand: pdd
9-
attacks: !include ctown_concealment_mitm.yaml
10+
attacks: !include ctown_concealment_mitm_path.yaml

examples/ctown_topology/ctown_plcs.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- name: PLC4 # PLC4, T3,
3434
sensors:
3535
- T3
36+
- T4
3637
- name: PLC5 # PLC5, PU8F PU10F PU11F J302 J306 J307 J317, PU8 PU10 PU11
3738
sensors:
3839
- PU8F
@@ -46,9 +47,9 @@
4647
- PU8
4748
- PU10
4849
- PU11
49-
- name: PLC6 # PLC6, T4,
50-
sensors:
51-
- T4
50+
#- name: PLC6 # PLC6, T4,
51+
# sensors:
52+
# - T4
5253
- name: PLC7 # PLC7, T5,
5354
sensors:
5455
- T5

0 commit comments

Comments
 (0)