字符串函数中有替换多个/解析unicode吗?

问题描述 投票:0回答:1

我正在使用 AZ/ KQL,我试图找出是否有一个函数能够替换字符串中的多个值,或者(更好的是)有一个函数可以将 unicode 替换为日志中的字符串线。

例如我有日志:

["\u0027\"\u003e\u003csvg/onload=alert(document.domain)\u003e"]

我需要将

\u0027
值替换为字符串,因此例如此日志,理想情况下最终看起来像这样:

["'\"><svg/onload=alert(document.domain)>"]

就上下文而言,日志源是 AZ Sentinel 的 AWS 连接器,它似乎没有函数(我想也许我缺少该函数),但对我来说,CloudTrail 似乎无法处理日志文件,所以默认为 Unicode,但是在这边解析它们似乎是不可能的。

我尝试了 unicode_codepoints_to_string()、replace_string()、iff/iif() 和 Replace_string(),代码如下:

| extend parsd = iff(tolower(AdditionalEventData) contains @'\u003e', replace_string(tostring(AdditionalEventData),@'\u003e',@'>'), AdditionalEventData)
| extend parsd = iff(tolower(parsd) contains @'\u003c', replace_string(tostring(AdditionalEventData),@'\u003c',@'<'), parsd)

| extend parsd = replace_regex(AdditionalEventData,@'U+.\d{1,5}',unicode_codepoints_to_string(AdditionalEventData))

我尝试了已弃用的 make_string() 运算符,但同样,所有这些都是针对整个字符串的多数,我猜我需要执行某种 indexof(substring( 但我对这些运算符的经验并不丰富。

我什至打算尝试单独替换为单独的列,然后用 strcat() 跟进,但这似乎是一个非常极端的路线,并且需要永远考虑所有 unicode 字符,然后将它们返回到单列。

有人知道这个问题有好的解决方案吗? 任何帮助将不胜感激。感谢您的阅读。

unicode kql azure-data-explorer azure-sentinel
1个回答
1
投票

我强烈建议在摄入前解决这个问题。

print log = @'["\u0027"\u003e\u003csvg/onload=alert(document.domain)\u003e"]'
| mv-apply parts = extract_all(@"(.*?)(\\u[[:xdigit:]]{4}|$)", log) on 
  ( 
    summarize fixed_log = array_strcat(make_list(strcat(parts[0], iff(isnotempty(parts[1]), unicode_codepoints_to_string(toint(strcat("0x", substring(parts[1], 2, 4)))), ""))), "")
  )
+----------------------------------------------------------------+--------------------------------------------+
|                              log                               |                 fixed_log                  |
+----------------------------------------------------------------+--------------------------------------------+
| ["\u0027"\u003e\u003csvg/onload=alert(document.domain)\u003e"] | ["'"><svg/onload=alert(document.domain)>"] |
+----------------------------------------------------------------+--------------------------------------------+

小提琴

© www.soinside.com 2019 - 2024. All rights reserved.