2121
2222from app .translator .const import DEFAULT_VALUE_TYPE
2323from app .translator .core .custom_types .values import ValueType
24+ from app .translator .core .mapping import SourceMapping
25+ from app .translator .core .models .field import FieldValue , Keyword
26+ from app .translator .core .models .identifier import Identifier
2427from app .translator .core .models .platform_details import PlatformDetails
2528from app .translator .core .render import BaseQueryFieldValue , PlatformQueryRender
2629from app .translator .core .str_value_manager import StrValue
3437)
3538from app .translator .platforms .palo_alto .str_value_manager import cortex_xql_str_value_manager
3639
40+ SOURCE_MAPPING_TO_FIELD_VALUE_MAP = {
41+ "windows_registry_event" : {
42+ "EventType" : {
43+ "SetValue" : "REGISTRY_SET_VALUE" ,
44+ "DeleteValue" : "REGISTRY_DELETE_VALUE" ,
45+ "CreateKey" : "REGISTRY_CREATE_KEY" ,
46+ }
47+ }
48+ }
49+
3750
3851class CortexXQLFieldValue (BaseQueryFieldValue ):
3952 details : PlatformDetails = cortex_xql_query_details
@@ -51,12 +64,6 @@ def _get_value_type(field_name: str, value: Union[int, str, StrValue], value_typ
5164
5265 @staticmethod
5366 def _wrap_str_value (value : str ) -> str :
54- if value == "SetValue" :
55- return '"REGISTRY_SET_VALUE"'
56- if value == "DeleteValue" :
57- return '"REGISTRY_DELETE_VALUE"'
58- if value == "CreateKey" :
59- return '"REGISTRY_CREATE_KEY"'
6067 return f'"{ value } "'
6168
6269 def equal_modifier (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
@@ -178,3 +185,29 @@ def process_raw_log_field(self, field: str, field_type: str) -> Optional[str]:
178185 def generate_prefix (self , log_source_signature : CortexXQLLogSourceSignature , functions_prefix : str = "" ) -> str :
179186 functions_prefix = f"{ functions_prefix } | " if functions_prefix else ""
180187 return f"{ functions_prefix } { log_source_signature } "
188+
189+ def apply_token (self , token : Union [FieldValue , Keyword , Identifier ], source_mapping : SourceMapping ) -> str :
190+ if (
191+ isinstance (token , FieldValue )
192+ and source_mapping .source_id in SOURCE_MAPPING_TO_FIELD_VALUE_MAP
193+ and token .field .source_name in SOURCE_MAPPING_TO_FIELD_VALUE_MAP [source_mapping .source_id ]
194+ ):
195+ values_to_update = []
196+ token_values = token .values
197+ for token_value in token_values :
198+ if (
199+ isinstance (token_value , str )
200+ and token_value
201+ in SOURCE_MAPPING_TO_FIELD_VALUE_MAP [source_mapping .source_id ][token .field .source_name ]
202+ ):
203+ values_to_update .append (
204+ SOURCE_MAPPING_TO_FIELD_VALUE_MAP [source_mapping .source_id ][token .field .source_name ][
205+ token_value
206+ ]
207+ )
208+ else :
209+ values_to_update .append (token_value )
210+ if values_to_update != token_values :
211+ token .value = values_to_update
212+
213+ return super ().apply_token (token = token , source_mapping = source_mapping )
0 commit comments