谷歌YARA-L 2.0——EDR hips、沙箱里、或者云端规则引擎都是可以用的
看yara的使用
https://go.chronicle.security/hubfs/YARA-L%20Overview%20White%20Paper.pdf
看看官方文档宣传的使用(格式丑陋的话看原文):
profile susp_powershell_download_file {
meta:
author = “Chronicle Security”
description = “Rule to detect PowerShell one-liner to download a file”
version = “0.01”
created = “2019-12-16”
reference = “https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Windows%20-%20
Download%20and%20Execute.md”
condition:
if re.regex(strings.lower(udm.process.command_line), “.*powershell.*net.webclient.*”) then
outcome.match()
end }
还支持自定义函数:
profile susp_process_with_variation_of_svchost {
meta:
author = “Chronicle Security”
description = “Rule to detect process paths or command line execution of files with variations on svchost”
version = “0.01”
created = “2019-12-16”
function:
func CheckSvchostVariations()
if (
re.regex(strings.lower(udm.process.command_line), “.*(svch0st|svh0st|svhost|svchst|svchot|svchostexe)\.exe.*”) or
re.regex(strings.lower(udm.process.path), “.*(svch0st|svh0st|svhost|svchst|svchot|svchostexe)\.exe.*”)
) then
return true
end
return false
end
condition:
if ( CheckSvchostVariations() )
then
outcome.match()
end }
一个复杂的例子:
profile malware_powershell_empire
{
meta:
author = “Chronicle Security “
description = “Detection activity related to the OWAAuth malware”
reference = “https://attack.mitre.org/software/S0072/”
version = “1.2”
created = “2019-12-13”
updated = “2020-01-20”
function:
func ScheduledTaskSet()
if re.regex(strings.to_lower(udm.principal.process.command_line), “.*schtasks .*/tn updater.*”) then
return true
end
return false
end
func WritePayload()
if re.regex(strings.to_lower(udm.principal.process.command_line), “.*sal a new-object;iex\\(a io\\.streamreader\\(\\(a io\\.compression\\.deflatestream\\(\\[io.memorystream\\]\\[convert\\]::frombase64string\\(.*\\),\\[io\\.compression\\.compressionmode\\]::decompress\\)\\),\\[text.encoding\\]::ascii.*”)
then
return true
end
return false
end
condition:
if ScheduledTaskSet() or WritePayload() then
outcome.match()
end
}
可以用在EDR里,或者沙箱,都是可以的。检测ATT&CK:
https://github.com/chronicle/detection-rules/blob/main/mitre_attack/T1564_001_windows_hidden_files.yaral
rule mitre_attack_T1564_001_windows_hidden_files
{
meta:
author = "Google Cloud Security"
description = "Manually setting a file to be hidden on Windows"
reference = "https://attack.mitre.org/techniques/T1564/001/"
yara_version = "YL2.0"
rule_version = "1.0"
events:
$e1.metadata.event_type = "PROCESS_LAUNCH"
re.regex($e1.principal.process.command_line, `attrib\.exe \+h`) nocase
condition:
$e1
}
是采集进程信息,然后正则匹配。下面这个是采集注册表信息,然后匹配:
rule mitre_attack_T1037_001_windows_logon_script
{
meta:
author = "Google Cloud Security"
description = "Registry modification related to installation of a custom logon script"
reference = "https://attack.mitre.org/techniques/T1037/001/"
yara_version = "YL2.0"
rule_version = "1.0"
events:
(
$e1.metadata.event_type = "REGISTRY_CREATION" or
$e1.metadata.event_type = "REGISTRY_MODIFICATION"
)
and
re.regex($e1.target.registry.registry_key, `(HKCU|HKEY_CURRENT_USER)\\Environment\\UserInitMprLogonScript`) nocase
condition:
$e1
}
检测命令行的net use IPC:
rule mitre_attack_T1021_002_windows_admin_share
{
meta:
author = "Google Cloud Security"
description = "Net use commands for SMB/Windows admin shares"
reference = "https://attack.mitre.org/techniques/T1021/002/"
yara_version = "YL2.0"
rule_version = "1.0"
events:
re.regex($e1.principal.process.command_line, `net use.* (C|ADMIN|IPC)$`) nocase
condition:
$e1
}
创建计划任务:
rule T1053_005_windows_creation_of_scheduled_task
{
meta:
author = "Google Cloud Security"
description = "Creation of scheduled task using command line"
reference = "https://attack.mitre.org/techniques/T1053/005/"
yara_version = "YL2.0"
rule_version = "1.0"
events:
re.regex($e1.principal.process.command_line, `schtasks /create`) nocase
condition:
$e1
}
更多可以参考:https://github.com/chronicle/detection-rules/tree/main/mitre_attack,明显是不全哪。。。看来谷歌是有所保留的。
检测恶意软件的:
https://github.com/chronicle/detection-rules/blob/main/malware/apt_plugx_user_agent.yaral 从下面写的规则看,绝对是在乱搞,这样不知道有多少误报。。。
rule malware_apt_plugx_user_agent
{
meta:
author = "Google Cloud Security"
description = "HTTP user-agent associated with PlugX"
yara_version = "YL2.0"
rule_version = "1.0"
events:
$e1.network.http.user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)"
condition:
$e1
}
再看一个勒索的,这个签名要气死人。。。
rule malware_ryuk_ransomnote_created
{
meta:
author = "Google Cloud Security"
description = "Identify when a Ryuk Ransomware ransomnote has been written"
yara_version = "YL2.0"
rule_version = "1.0"
events:
$e1.metadata.event_type = "FILE_CREATION"
re.regex($e1.target.file.full_path, `ryukreadme\.(html|txt)$`) nocase
condition:
$e1
}
再看可疑的行为:
https://github.com/chronicle/detection-rules/blob/main/suspicious/command_psexec.yaral
rule suspicious_command_psexec
{
meta:
author = "Google Cloud Security"
description = "Command-line execution of the PsExec tool on Windows"
yara_version = "YL2.0"
rule_version = "1.0"
events:
re.regex($e1.principal.process.command_line, `\bpsexec(\.exe)?\b`) nocase
condition:
$e1
}
可疑的psexec、shutdown关机:
rule suspicious_command_shutdown
{
meta:
author = "Google Cloud Security"
description = "Command-line execution of the 'shutdown' command"
yara_version = "YL2.0"
rule_version = "1.0"
events:
re.regex($e1.principal.process.command_line, `\bshutdown(\.exe)?\b`) nocase
condition:
$e1
}
再看他狩猎的:
https://github.com/chronicle/detection-rules/blob/main/soc_prime_rules/threat_hunting/powershell/sysmon_service_enumeration.yaral
rule sysmon_service_enumeration {
meta:
author = "Osman Demir"
description = "Detects Sysmon Enumeration Activity License: https://github.com/Neo23x0/sigma/blob/master/LICENSE.Detection.Rules.md."
reference = "https://tdm.socprime.com/tdm/info/DnN9qhks24Tp"
version = "0.01"
created = "2021-03-09"
product = "windows"
service = "powershell"
mitre = "discovery, t1063"
events:
(re.regex($selection.target.process.command_line, `ls HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WINEVT\\Channels | Where-Object \\{$_\.name -like \".*sysmon.*\"\\}`) or $selection.target.process.command_line = "ls HKCU:\\Software\\Sysinternals | Select-Object name" or $selection.target.process.command_line = "Get-CimInstance win32_service -Filter \"Description = 'System Monitor service'\"")
condition:
$selection
}
https://github.com/chronicle/detection-rules/blob/main/soc_prime_rules/threat_hunting/sysmon/abusing_azure_browser_sso.yaral
rule abusing_azure_browser_sso {
meta:
author = "Den Iuzvyk"
description = "Detects abusing Azure Browser SSO by requesting OAuth 2.0 refresh tokens for an Azure-AD-authenticated Windows user (i.e. the machine is joined to Azure AD and a user logs in with their Azure AD account) wanting to perform SSO authentication in the browser. An attacker can use this to authenticate to Azure AD in a browser as that user. License: https://github.com/Neo23x0/sigma/blob/master/LICENSE.Detection.Rules.md."
reference = "https://tdm.socprime.com/tdm/info/sX0F2FNTmN68"
version = "0.01"
created = "2021-03-09"
category = "sysmon"
product = "windows"
mitre = "defense_evasion, privilege_escalation, t1073"
events:
(($selection_dll.metadata.product_event_type = "7" and re.regex($selection_dll.target.process.file.full_path, `.*MicrosoftAccountTokenProvider\.dll`)) and not ((re.regex($selection_dll.target.process.file.full_path, `.*BackgroundTaskHost\.exe`) or re.regex($selection_dll.target.process.file.full_path, `.*devenv\.exe`) or re.regex($selection_dll.target.process.file.full_path, `.*iexplore\.exe`) or re.regex($selection_dll.target.process.file.full_path, `.*MicrosoftEdge\.exe`))))
condition:
$selection_dll
}
YARA-L 2.0 语言概览
YARA-L 2.0 是一种计算机语言,用于创建搜索企业日志数据的规则,因为它被注入到您的 Chronicle 帐号中。YARA-L 语法派生自 VirusTotal 开发的 YARA 语言。该语言与 Chronicle Detection Engine 配合使用,让您可以在大量数据中寻找威胁和其他事件。另请参阅 YARA-L 2.0 语言语法
注意:YARA-L 2.0 与旧版 YARA-L 语言不兼容。以旧版 YARA-L 编写的规则不适用于当前版本的 Detection Engine,需要经过修改才能使用新语法。
规则结构
以下示例展示了使用 YARA-L 2.0 编写的规则。每个示例都展示了如何关联规则语言中的事件。
不同城市的登录信息
以下规则可搜索在 4 小时内创建然后删除的用户:
rule UserCreationThenDeletion {
meta:
events:
$create.target.user.userid = $user
$create.metadata.event_type = "USER_CREATION"
$delete.target.user.userid = $user
$delete.metadata.event_type = "USER_DELETION"
$create.metadata.event_timestamp.seconds <=
$delete.metadata.event_timestamp.seconds
match:
$user over 4h
condition:
$create and $delete
}
事件变量:$create 和 $delete
Match 变量:$user
占位符变量:不适用
下面介绍了此规则的工作原理:
- 对用户名为 (
$user) 的事件进行分组,并在找到匹配项时返回该值 ($user)。 - 时间范围为 4 小时,这意味着只有不到 4 小时的事件才会关联。
- 搜索两个事件组(
$create和$delete,其中$create等同于#create >= 1)。 $create对应于USER_CREATION事件,并将用户 ID 调用为$user。$user用于将两组事件联接在一起。$delete对应于USER_DELETION事件,并以$user形式调用用户 ID。此规则查找两个事件组中用户标识符相同的匹配项。- 此规则查找事件
$delete发生的时间晚于$create事件的情况,并在发现时返回匹配项。
单事件与多事件
以下示例展示了一条规则,用于搜索两个特定用户和特定 IP 地址范围之间的匹配项:
rule OrsAndNetworkRange {
meta:
author = "noone@altostrat.com"
events:
// Checks CIDR ranges.
net.ip_in_range_cidr($e.principal.ip, "203.0.113.0/24")
// Detection when the hostname field matches either value using or.
$e.principal.hostname = /pbateman/ or $e.principal.hostname = /sspade/
condition:
$e
}
重复字段
重复字段可以与非重复字段相同。在这种情况下,它们会自动消除歧义,这意味着系统会针对重复字段的各个元素检查条件。
例如,如果您在规则中包含以下语句:
$e.principal.ip = "192.168.12.16"
Chronicle 会在数组中搜索与 "192.168.12.16" 匹配的 IP 地址。在此示例中,将会找到匹配的地址并返回检测结果。
例如,如果您在规则中包含以下语句:
$e.principal.ip = "192.168.12.16" and $e.principal.ip = "10.3.4.100"
Chronicle 会在数组中搜索与 "192.168.12.16" 和 "10.3.4.100" 匹配的 IP 地址。在此示例中,将找不到匹配的地址,因此不会返回检测结果。
重复字段示例
您还可以使用 any 和 all 运算符引用重复字段。如果是这样,它们不会消除歧义,也就是说,系统会针对重复字段的所有元素检查条件。
例如,如果您在规则中包含以下语句:
any $e.principal.ip = "192.168.12.16"
Chronicle 会检查数组中的任何 IP 地址是否与 "192.168.12.16" 匹配。在此示例中,数组将满足检查条件并返回检测结果。
如果您在规则中包含以下语句:
all $e.principal.ip = "192.168.12.16"
Chronicle 会检查数组中的所有 IP 地址是否与 "192.168.12.16" 匹配。在此示例中,数组不满足检查条件,因此不会返回检测结果。
如果您在规则中包含以下语句:
any $e.principal.ip = "192.168.12.16" and any $e.principal.ip = "10.3.4.100"
Chronicle 会检查数组中的任何 IP 地址是否与 "192.168.12.16" 匹配,以及数组中的任何 IP 地址是否与 "10.3.4.100" 匹配。在此示例中,数组会满足检查条件,并返回检测结果。
以下是使用 any 和 all 运算符的有效谓词示例:
any $e.principal.ip = "192.168.12.16"net.ip_in_range_cidr(any $e.principal.ip, "192.168.12.16/24")all $e.network.email.to = /.*@google\.com/re.regex(all $e.network.email.to, `.*google\.com`)
以下是使用 any 和 all 运算符的无效谓词示例:
any $ip = "192.168.12.16"any $e.principal.ip = all $e.target.ipany $e.principal.ip in %reference_list
any 和 all 运算符的限制
以下规则会搜索所有来源 IP 地址在 5 分钟的时间内与已知安全的 IP 地址不匹配的登录事件。
rule SuspiciousIPLogins {
meta:
author = "noone@google.com"
events:
$e.metadata.event_type = "USER_LOGIN"
// Detects if all source IP addresses in an event do not match "100.97.16.0"
// For example, if an event has source IP addresses
// ["100.97.16.1", "100.97.16.2", "100.97.16.3"],
// it will be detected since "100.97.16.1", "100.97.16.2",
// and "100.97.16.3" all do not match "100.97.16.0".
all $e.principal.ip != "100.97.16.0"
// Assigns placeholder variable $ip to the $e.principal.ip repeated field.
// There will be one detection per source IP address.
// For example, if an event has source IP addresses
// ["100.97.16.1", "100.97.16.2", "100.97.16.3"],
// there will be one detection per address.
$e.principal.ip = $ip
match:
$ip over 5m
condition:
$e
}
规则中的正则表达式
默认情况下,YARA-L 2.0 规则使用跃点窗口进行评估。企业事件数据的时间范围分为一组重叠的跃点窗口,每个窗口的持续时间都在 match 部分指定。然后,在每个跃点窗口中关联事件。若有跃点窗口,则无法搜索按特定顺序发生的事件(例如,e1 可在 e2 后最多 2 分钟内发生)。只要事件 e1 与事件 e2 的跃点窗口时长相同,系统就会将它们相关联。
还可以使用滑动窗口评估规则。在滑动窗口时,以指定的数据透视事件变量开始或结束时,会生成时长为 match 区段的滑动窗口。然后,在每个滑动窗口内,事件是相关的。这样,您就可以搜索按特定顺序发生的事件(例如,e1 会在 e2 的 2 分钟内发生)。如果事件 e1 发生在事件 e2 后的滑动窗口内,则事件 e1 与事件 e2 的发生是相关的。
注意:已知使用滑动窗口代替跃点窗口会导致性能下降。Google 建议仅在特定情况下使用滑动窗口,例如绝对有必要使用事件顺序或搜索不存在的事件时。
滑动窗口规则语法
以下 YARA-L 2.0 滑动窗口示例搜索 firewall_1 事件后缺少 firewall_2 事件。after 关键字与数据透视事件变量 $e1 结合使用,指定在关联事件时应仅检查每个 firewall_1 事件 10 分钟后。
rule SlidingWindowRuleExample {
meta:
author = "noone@google.com"
events:
$e1.metadata.product_name = "firewall_1"
$e1.principal.hostname = $host
$e2.metadata.product_name = "firewall_2"
$e2.principal.hostname = $host
match:
$host over 10m after $e1
condition:
$e1 and !$e2
}