EQL 的全名是 Event Query Language (EQL)。事件查询语言(EQL)是一种用于基于事件的时间序列数据(例如日志,指标和跟踪)的查询语言。在 Elastic Security 平台上,当输入有效的 EQL 时,查询会在数据节点上编译,执行查询并返回结果。这一切都快速、并行地发生,让用户立即看到结果。
要运行 EQL 搜索,搜索到的数据流或索引必须包含时间戳和事件类别字段。默认情况下,EQL 使用 Elastic 通用模式(ECS)中的 @timestamp 和 event.category 字段。 @timestamp 表示时间戳,event.category 表示事件分类。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 创建索引 PUT /gmall # 批量增加数据 PUT _bulk {"index":{"_index":"gmall"}} { "@timestamp":"2022-08-10T15:00:00.00+08:00", "event":{ "category":"page" }, "page":{ "session_id":"42FC7E13-CB3E-5C05-0000-0010A0125101", "last_page_id":"", "page_id":"login", "user_id":"" } } {"index":{"_index":"gmall"}} { "@timestamp":"2022-08-10T15:02:00.00+08:00", "event":{ "category":"page" }, "page":{ "session_id":"42FC7E13-CB3E-5C05-0000-0010A0125101", "last_page_id":"login", "page_id":"good_list", "user_id":"1" } } {"index":{"_index":"gmall"}} { "@timestamp":"2022-08-10T15:05:00.00+08:00", "event":{ "category":"page" }, "page":{ "session_id":"42FC7E13-CB3E-5C05-0000-0010A0125101", "last_page_id":"good_list", "page_id":"good_detail", "user_id":"1" } } {"index":{"_index":"gmall"}} { "@timestamp":"2022-08-10T15:07:00.00+08:00", "event":{ "category":"page" }, "page":{ "session_id":"42FC7E13-CB3E-5C05-0000-0010A0125101", "last_page_id":"good_detail", "page_id":"order", "user_id":"1" } } {"index":{"_index":"gmall"}} { "@timestamp":"2022-08-10T15:08:00.00+08:00", "event":{ "category":"page" }, "page":{ "session_id":"42FC7E13-CB3E-5C05-0000-0010A0125101", "last_page_id":"order", "page_id":"payment", "user_id":"1" } } {"index":{"_index":"gmall"}} { "@timestamp":"2022-08-10T15:08:00.00+08:00", "event":{ "category":"page" }, "page":{ "session_id":"42FC7E13-CB3E-5C05-0000-0010A0125102", "last_page_id":"", "page_id":"login", "user_id":"2" } } {"index":{"_index":"gmall"}} { "@timestamp":"2022-08-10T15:08:00.00+08:00", "event":{ "category":"page" }, "page":{ "session_id":"42FC7E13-CB3E-5C05-0000-0010A0125102", "last_page_id":"login", "page_id":"payment", "user_id":"2" } } |
在事件响应过程中,有很多时候,了解特定时间发生的所有事件是很有用的。使用一种名为any的特殊事件类型,针对所有事件进行匹配,如果想要匹配特定事件,就需要指明事件分类名称
|
1 2 3 4 5 6 7 |
# GET /gmall/_eql/search { "query" : """ any where page.user_id == "1" """ } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
GET /gmall/_eql/search { "query" : """ any where true """, "filter": { "range": { "@timestamp": { "gte": "1654056000000", "lt": "1654056005000" } } } } |
|
1 2 3 4 5 6 7 8 |
GET /gmall/_eql/search { "query" : """ sequence by page.session_id [page where page.page_id=="login"] [page where page.page_id=="good_detail"] """ } |
EQL在 Elastic Securit 中被广泛使用。实际应用时,我们可以使用 EQL 语言来进行检测安全威胁和其他可疑行为。
regsvr32.exe 是一个内置的命令行实用程序,用于在Windows中注册.dll库。作为本机工具,regsvr32.exe 具有受信任的状态,从而使它可以绕过大多数允许列表软件和脚本阻止 程序。有权访问用户命令行的攻击者可以使用 regsvr32.exe 通过.dll库运行恶意脚本,即使在其他情况下也不允许这些脚本运行。
regsvr32 滥用的一种常见变体是Squfullydoo攻击。在 Squfullydoo 攻击中,regsvr32.exe 命令使用 scrobj.dll 库注册并运行远程脚本。
测试数据来自 Atomic Red Team 的测试数据集,其中包括模仿Squibledoo攻击的事件。 数据已映射到Elastic通用架构(ECS)字段:normalized-T1117-AtomicRed-regsvr32.json 将文件内容导入到ES软件中:
|
1 2 3 4 5 6 7 8 |
# 创建索引 PUT my-eql-index # 导入数据 POST my-eql-index/_bulk?pretty&refresh {"index":{}} { ...... } |
|
1 |
GET /_cat/indices/my-eql-index?v=true&h=health,status,index,docs.count |
|
1 2 3 4 5 6 7 8 9 10 11 |
# 查询数据 # ?filter_path=-hits.events 从响应中排除hits.events 属性。此搜索仅用于获取事件计数,而不是匹配事件的列表 # query : 匹配任何进程名称为regsvr32.exe的事件 # size : 最多返回200个匹配事件的匹配,实际查询结果为143个 GET my-eql-index/_eql/search?filter_path=-hits.events { "query": """ any where process.name == "regsvr32.exe" """, "size": 200 } |
该查询将一个事件与创建的event.type相匹配,指示regsvr32.exe进程的开始。根据事件的 process.command_line值,regsvr32.exe 使用 scrobj.dll 注册了脚本 RegSvr32.sct.这符合Squibledoo攻击的行为
|
1 2 3 4 5 6 7 |
# 增加过滤条件查询数据 GET my-eql-index/_eql/search { "query": """ process where process.name == "regsvr32.exe" and process.command_line.keyword != null """ } |
|
1 2 3 4 5 6 7 |
# 增加过滤条件查询数据 GET my-eql-index/_eql/search { "query": """ library where process.name == "regsvr32.exe" and dll.name == "scrobj.dll" """ } |
在许多情况下,攻击者使用恶意脚本连接到远程服务器或下载其他文件。 使用EQL序列查询来检查以下一系列事件:
|
1 2 3 4 5 6 7 8 9 10 |
# 增加过滤条件查询数据 GET my-eql-index/_eql/search { "query": """ sequence by process.pid [process where process.name == "regsvr32.exe"] [library where dll.name == "scrobj.dll"] [network where true] """ } |