21
21
22
22
from app .translator .const import DEFAULT_VALUE_TYPE
23
23
from 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
24
27
from app .translator .core .models .platform_details import PlatformDetails
25
28
from app .translator .core .render import BaseQueryFieldValue , PlatformQueryRender
26
29
from app .translator .core .str_value_manager import StrValue
34
37
)
35
38
from app .translator .platforms .palo_alto .str_value_manager import cortex_xql_str_value_manager
36
39
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
+
37
50
38
51
class CortexXQLFieldValue (BaseQueryFieldValue ):
39
52
details : PlatformDetails = cortex_xql_query_details
@@ -51,12 +64,6 @@ def _get_value_type(field_name: str, value: Union[int, str, StrValue], value_typ
51
64
52
65
@staticmethod
53
66
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"'
60
67
return f'"{ value } "'
61
68
62
69
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]:
178
185
def generate_prefix (self , log_source_signature : CortexXQLLogSourceSignature , functions_prefix : str = "" ) -> str :
179
186
functions_prefix = f"{ functions_prefix } | " if functions_prefix else ""
180
187
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