Skip to content

Commit dedd6c0

Browse files
committed
Finally some progress in the concealment attack. The cip parser does not work as intended, but for now we can use the approach of checking packet length to get tag value and sesison ID.
1 parent ebc9d7d commit dedd6c0

File tree

7 files changed

+28
-44
lines changed

7 files changed

+28
-44
lines changed

dhalsim/network_attacks/mitm_attack.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ def __init__(self, intermediate_yaml_path: Path, yaml_index: int):
3333
# Process object to handle nfqueue
3434
self.nfqueue_process = None
3535

36-
def clear_ip_tables(self):
37-
38-
os.system(f'iptables -t mangle -D INPUT -p tcp -j NFQUEUE --queue-num 1')
39-
os.system(f'iptables -t mangle -D FORWARD -p tcp -j NFQUEUE --queue-num 1')
40-
41-
os.system('iptables -D FORWARD -p icmp -j DROP')
42-
os.system('iptables -D INPUT -p icmp -j DROP')
43-
os.system('iptables -D OUTPUT -p icmp -j DROP')
4436

4537
def setup(self):
4638
"""
@@ -55,26 +47,7 @@ def setup(self):
5547
5648
Finally, it launches the thread that will examine all captured packets.
5749
"""
58-
59-
""""
60-
if self.direction == 'source':
61-
os.system(f'iptables -t mangle -A PREROUTING -p tcp --sport 44818 -s {self.target_plc_ip} -j NFQUEUE '
62-
f'--queue-num 1')
63-
elif self.direction == 'destination':
64-
os.system(f'iptables -t mangle -A PREROUTING -p tcp --sport 44818 -d {self.target_plc_ip} -j NFQUEUE '
65-
f'--queue-num 1 ')
66-
else:
67-
self.logger.error('Wrong direction configured, direction must be source or destination')
68-
raise DirectionError('Wrong direction configured')
69-
"""
70-
71-
self.clear_ip_tables()
72-
73-
os.system(f'iptables -t mangle -A PREROUTING -p tcp -j NFQUEUE --queue-num 1')
74-
75-
os.system('iptables -A FORWARD -p icmp -j DROP')
76-
os.system('iptables -A INPUT -p icmp -j DROP')
77-
os.system('iptables -A OUTPUT -p icmp -j DROP')
50+
self.modify_ip_tables(True)
7851

7952
# Launch the ARP poison by sending the required ARP network packets
8053
launch_arp_poison(self.target_plc_ip, self.intermediate_attack['gateway_ip'])
@@ -116,7 +89,7 @@ def teardown(self):
11689
self.logger.debug(f"MITM Attack ARP Restore between {self.target_plc_ip} and "
11790
f"{self.intermediate_attack['gateway_ip']}")
11891

119-
self.clear_ip_tables()
92+
self.modify_ip_tables(False)
12093
self.logger.debug(f"Restored ARP")
12194

12295
self.logger.debug("Stopping nfqueue subprocess...")
@@ -132,6 +105,24 @@ def attack_step(self):
132105
pass
133106

134107

108+
@staticmethod
109+
def modify_ip_tables(append=True):
110+
111+
if append:
112+
os.system(f'iptables -t mangle -A PREROUTING -p tcp -j NFQUEUE --queue-num 1')
113+
114+
os.system('iptables -A FORWARD -p icmp -j DROP')
115+
os.system('iptables -A INPUT -p icmp -j DROP')
116+
os.system('iptables -A OUTPUT -p icmp -j DROP')
117+
else:
118+
119+
os.system(f'iptables -t mangle -D INPUT -p tcp -j NFQUEUE --queue-num 1')
120+
os.system(f'iptables -t mangle -D FORWARD -p tcp -j NFQUEUE --queue-num 1')
121+
122+
os.system('iptables -D FORWARD -p icmp -j DROP')
123+
os.system('iptables -D INPUT -p icmp -j DROP')
124+
os.system('iptables -D OUTPUT -p icmp -j DROP')
125+
135126
def is_valid_file(parser_instance, arg):
136127
"""Verifies whether the intermediate yaml path is valid."""
137128
if not os.path.exists(arg):

dhalsim/network_attacks/naive_netfilter_queue.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def capture(self, pkt):
2727
self.logger.debug('capture method')
2828
try:
2929
p = IP(pkt.get_payload())
30-
#self.logger.debug('packet')
3130
if len(p) == 102:
3231
self.logger.debug('modifying')
3332
if 'value' in self.intermediate_attack.keys():

dhalsim/parser/config_parser.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ class SchemaParser:
181181
str,
182182
string_pattern
183183
),
184-
Optional('direction', default='source'): And(
185-
str,
186-
Use(str.lower),
187-
Or('source', 'destination'), error="'direction' should be one of the following:"
188-
" 'source' or 'destination'."
189-
),
190184
'tag': And(
191185
str,
192186
string_pattern,

dhalsim/python2/generic_plc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def get_tag_for_cache(self, tag, plc_ip, cache_update_time):
280280
try:
281281
received = Decimal(self.receive((tag, 1), plc_ip))
282282
self.cache[tag] = received
283-
self.logger.debug('Received value {value}, from IP {ip}'.format(value=received, ip=plc_ip))
283+
#self.logger.debug('Received value {value}, from IP {ip}'.format(value=received, ip=plc_ip))
284284
return True
285285
except Exception as e:
286286
self.logger.info(

dhalsim/python2/generic_scada.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ def update_cache(self, lock, cache_update_time):
297297
ip=plc_ip, e=str(e)))
298298
time.sleep(cache_update_time)
299299
continue
300-
self.logger.debug(
301-
"SCADA cache updated for {tags}, with value {values}, from {ip}".format(tags=self.plc_data[plc_ip],
302-
values=values,
303-
ip=plc_ip))
300+
#self.logger.debug(
301+
# "SCADA cache updated for {tags}, with value {values}, from {ip}".format(tags=self.plc_data[plc_ip],
302+
# values=values,
303+
# ip=plc_ip))
304304

305305
time.sleep(cache_update_time)
306306

examples/ctown_topology/ctown_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
inp_file: ctown_map.inp
2-
iterations: 25
2+
iterations: 2880
33
network_topology_type: complex
44
plcs: !include ctown_plcs.yaml
55

examples/ctown_topology/ctown_mitm.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ network_attacks:
66
tag: T3
77
direction: destination
88
trigger:
9-
start: 5
10-
end: 20
9+
start: 648
10+
end: 936
1111
type: time

0 commit comments

Comments
 (0)