提供服务器端抓包功能 注意:windows 需要安装npcap
- vela.capture(cfg) 构建抓包服务
- 内置常量 限制固定环境常量
内置方法:
- dev(cnd) 接口过滤条件,内置:接口过滤条件
- dev_up(cnd) 监听启动的接口,内置:接口过滤条件
- sniffer(proto) 解包协议:协议变量
- ignore(cnd)
- filter(cnd)
- pipe(px)
- thread(int)
- bpf()
- ref() 关联进程
- case() c.case("dst == 127.0.0.1").pipe(do)
- output(io.writer) c.output()
- rate(key , max , timeout) c.rate('dst' , 3000 , 60)
- dns_ignore(cnd)
- dns_filter(cnd)
- dns_pipe(px)
- dns_output(io.writer)
- dns_case(string)
- start() 启动
- 获取DNS信息
- 获取OUTBOUND
local cap = vela.capture("capture")
//todo
cap.dev("name = eth0")
cap.start()
- TCP_OUTBOUND_BPF
- TCP_OUTBOUND_BPF
- UDP_OUTBOUND_BPF
- NOT_LOOPBACK
- NOT_TCP_LISTEN_BPF
- NOT_UDP_LISTEN_BPF
- NOT_TCP_LISTEN_PORT
- NOT_UDP_LISTEN_PORT
动作函数:
- drop 丢弃数据包
- HAVE_IP 接口需要有IP地址
- UP 接口必须是UP的
- LOOPBACK 回环接口
- NOT_LOOPBACK 非回环接口
对应接口字段:
获取主机上的DNS访问记录 内置字段:
- q_type
- q_name
- r_size
- rr
- risk_virus
- risk_web
- risk_login
- risk_weak
- risk_monitor
- risk_xxx xxx为risk class 类型
内置函数:
- prefix(v)
- prefix_trim(v)
- suffix(v)
- suffix_trim(v)
- risk(class)
local vela = vela
local TVirus = vela.TVirus
local c = vela.capture
local out = task.stream.output
--发现恶意域名
local call = vela.call{uri="dns/risk?have&kind=miner&kind=virus&kind=cc"}
--设置缓存 60s
call.cache("dns_risk_bucket" , 60)
local function handle(dns)
if not call.r(dns.q_name) then
return
end
local ev = dns.risk(TVirus)
ev.alert = true
ev.send()
end
local d = c("dns")
--设置线程
d.thread(2)
--设置解包函数
d.sniffer(c.UDP , c.DNS)
--监听数据包
d.dev_up(c.NOT_LOOPBACK)
--过滤数据
d.bpf("udp and port 53")
--忽略
d.dns_ignore("q_name re *.eastmoney.com,*.aliyun.com,*.baidu.com,*.in-addr.arpa")
--设置输出对象
d.dns_output(out.clone("vela-dns-query"))
--检测对象
d.dns_case("proto = DNS|REQUEST").pipe(handle , print)
d.dns_case("name -> /risk/dns?kind=").pipe(handle , print)
--启动
d.start()
监听出网流量
local vela = vela
local call = vela.call
local capture = vela.capture
local out = task.stream.output
local f = vela.format
local TVirus = vela.TVirus
local c = capture("outbound")
--关联进程
c.ref()
--设置线程
c.thread(3)
--设置解包函数
c.sniffer(capture.L4)
--监听数据包
c.dev_up(capture.NOT_LOOPBACK)
--过滤数据
local addr = vela.addr().concat(" or ")
local broker = vela.broker()
c.bpf(f("tcp and tcp[tcpflags] == tcp-syn and src host %s and host not %s and dst net not 10.0.0.0/8" , addr , broker))
--设置输出对象
c.output(out.clone("vela-outbound"))
-- 命中告警
c.case("dst -> ip/risk?have&kind=miner&kind=virus&kind=cc").pipe(function(box)
box.risk(TVirus).send()
end)
c.pipe(handle)
--启动
c.start()