查询示例

安全运营常见场景的 SPL 样例

查询示例

以下样例可在安全数据搜索中改索引名与字段名后运行。时间修饰符如 -24h@h 表示「当前小时对齐的近 24 小时」。

按小时统计日志量

index="unix"
| stats count() by tspan(_time, 1h)

带别名:

index="unix"
| stats count() as total by tspan(_time, 1h) as date

近 24 小时告警列表

index="event"
| times earliest=-24h@h latest=now
| where isnotnull(device_ip)
| stats count() by _time, device_ip, event_name, event_level
| sort - _time
| head 100
| lookup asset.csv ip as device_ip OUTPUT application_name

认证失败账号 TOP 10

(index="unix" action="Failed password") OR (index="windows" id="4625")
| times earliest=-24h@h latest=now
| rename 帐户名 as user
| stats count() as totals by user
| sort - totals
| head 10

拒绝访问源地址 TOP(带资产名)

index="firewall" action="deny"
| times earliest=-7d@d latest=now
| stats count() as hits by src_ip
| sort - hits
| head 20
| lookup asset.csv ip as src_ip OUTPUT application_name, owner

派生字段与条件标记

index="proxy"
| eval low_user = lower(username)
| eval is_ok = if(status_code == 200, "Y", "N")
| where is_ok="N"
| table _time, low_user, status_code, url

IP 地理 enrichment

index="firewall"
| iplocation src_ip allfields=true prefix="geo_" lang="CN"
| stats count() by geo_country_name, geo_city_name
| sort - count()
| head 50

earliest / latest

index="unix"
| sort _time
| stats earliest(src_ip) as first_ip, latest(action) as last_action by user

子网内拒绝事件

index="firewall" AND action="deny"
| where cidrmatch(src_ip, "10.0.0.0/8")
| table _time, src_ip, dest_ip, dest_port, action
| sort - _time
| head 200

如何确认成功

  • 语句无语法错误;结果行数与预期量级接近
  • lookup 后资产字段有值(CSV 存在且键匹配)
  • iplocation 后 geo_* 字段对公网 IP 有内容

On this page