Metron基础概念
相关名词对应概念
架构图
mass服务架构(暂时理解不了)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-aEuIeZKv-1629875080431)(https://metron.apache.org/current-book/images/maas_arch.png)]
调整使用Model的Squid的设置
该项配置以json格式存储在$METRON_HOME/config/zookeeper/enrichments/squid.json
中,enrichment是metron中的概念之一。
{
"parserClassName": "org.apache.metron.parsers.GrokParser",
"sensorTopic": "squid",
"parserConfig": {
"grokPath": "/patterns/squid",
"patternLabel": "SQUID_DELIMITED",
"timestampField": "timestamp"
},
"fieldTransformations" : [
{
"transformation" : "STELLAR"
,"output" : [ "full_hostname", "domain_without_subdomains", "is_malicious", "is_alert" ]
,"config" : {
"full_hostname" : "URL_TO_HOST(url)"
,"domain_without_subdomains" : "DOMAIN_REMOVE_SUBDOMAINS(full_hostname)"
,"is_malicious" : "MAP_GET('is_malicious', MAAS_MODEL_APPLY(MAAS_GET_ENDPOINT('dga'), {'host' : domain_without_subdomains}))"
,"is_alert" : "if is_malicious == 'malicious' then 'true' else null"
}
}
]
}
其中URL_TO_HOST,MAP_GET为Stellar函数,其余的配置项看名字应该也知道了。
{
"enrichment" : {
"fieldMap": {}
},
"threatIntel" : {
"fieldMap":{},
"triageConfig" : {
"riskLevelRules" : [
{
"rule" : "is_malicious == 'malicious'",
"score" : 100
}
],
"aggregator" : "MAX"
}
}
}
上面是威胁触发设置,分别设置了规则和权重分值。
完成上面的设置后:
- 需要通过
$METRON_HOME/bin/zk_load_configs.sh --mode PUSH -i $METRON_HOME/config/zookeeper -z node1:2181
将设置更新上去。 - 生成对应的kafka集群topic
/usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper node1:2181 --create --topic squid --partitions 1 --replication-factor 1
启动Topologies 并发送数据
Topology是Storm的类似于job的概念。在该例中,采用Storm进行分析处理。
$METRON_HOME/bin/start_parser_topology.sh -k node1:6667 -z node1:2181 -s squid
启动squid topology。- 生成合法例子:
squidclient http://yahoo.com
- 生成非法例子:
squidclient http://cnn.com
- 发送数据到kafka
cat /var/log/squid/access.log | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list node1:6667 --topic squid
- 查看存储在es里的数据
http://node1:9200/_plugin/head/
来自yahoo.com的没有is_alert
和is_malicious
设置被视为legit
来自cnn.com的is_alert
被设为true且is_malicious
被设为‘malicious’,‘threat:triage:level’被设为100.
Metron Profiler
概念
Profiler是一种特征提取机制,用于生成描述实体行为的profile。实体可以是服务器,用户子网或者是应用。一旦生成了定义正常行为的profile,就可以建立识别异常行为的model
流,窗口,遥感数据可以用于概括和分析。
任何消息内的成员变量都可以用于生成profile。profile也可以由不同数据源的不同变量生成。
用户可以利用Stellar语言转换profile中使用的数据。用户只需要配置所需的profile并确保Profiler拓扑正在运行。
安装
省略,当使用Ambari Mpack安装Metron时,Profiler已经自动安装了。
创建Profiles
创建和精炼profile是一个需要迭代的过程。对流数据进行迭代是缓慢,困难和易于犯错的。因此可以使用Profile debugger进行该项工作。
-
运行 Stellar Shell,可在Stellar Shell中使用Profiler Debugger.
$METRON_HOME/bin/stellar
[root@node01 bin]# ./stellar Stellar, Go! Functions are loading lazily in the background and will be unavailable until loaded fully. {} [Stellar]>>>
-
创建一个简单的helloworld profile,用于给每个ip_src_addr的消息计数。SHELL_EDIT将打开一个编辑窗口。把以下设置复制粘贴进去
[Stellar]>>> conf := SHELL_EDIT()
[Stellar]>>> conf
{
"profiles": [
{
"profile": "hello-world",
"onlyif": "exists(ip_src_addr)",
"foreach": "ip_src_addr",
"init": { "count": "0" },
"update": { "count": "count + 1" },
"result": "count"
}
]
}
代表将SHELL_EDIT()中复制的设置赋值给conf
-
初始化Profiler
[Stellar]>>> profiler := PROFILER_INIT(conf) [Stellar]>>> profiler Profiler{1 profile(s), 0 messages(s), 0 route(s)}
其中有一个profile,0条消息,0个route(未配置)
route用于定义何时将一条message发给特定的profile
有几个profile需要该条消息,就follow几个route -
创建一条message,用于模仿profile需要消费的遥测数据
[Stellar]>>> msg := SHELL_EDIT() [Stellar]>>> msg { "ip_src_addr": "10.0.0.1" }
-
将message发给profile,发几次随你喜欢
[Stellar]>>> PROFILER_APPLY(msg, profiler) Profiler{1 profile(s), 1 messages(s), 1 route(s)} [Stellar]>>> PROFILER_APPLY(msg, profiler) Profiler{1 profile(s), 2 messages(s), 2 route(s)}
-
Flush(刷写)Profiler
- 在Profiler中,刷写每15分钟发生一次;结果为profile的测量结果。每个测量结果都是包含了已生成的profile数据的详细信息的map。value变量是当在Profiler 拓扑中运行profile时写入Hbase的数据。
[Stellar]>>> values := PROFILER_FLUSH(profiler) [Stellar]>>> values [{period={duration=900000, period=1784093, start=1605683700000, end=1605684600000}, profile=hello-world, groups=[], value=4, entity=10.0.0.1}]
-
试试真家伙吧
官网的例子是从kafka中取10条数据
##设置集群地址
[Stellar]>>> %define bootstrap.servers := "node01:6667"
node1:6667
##"mabaoguo"是topic,10为取数据条数
[Stellar]>>> msgs := KAFKA_GET("mabaoguo", 10)
[sisdfs]
[Stellar]>>> msgs := KAFKA_GET("mabaoguo", 100)
[fsdfds, lai,pian,lai,touxi]
[Stellar]>>> msgs
[fsdfds, lai,pian,lai,touxi]
[Stellar]>>> LENGTH(msgs)
2
[Stellar]>>> msgs := KAFKA_GET("mabaoguo", 100)
[69suilaotongzhi]
[Stellar]>>> LENGTH(msgs)
1
似乎是每运行一次KAFKA_GET(),就会取一次数据,直接返回,不等待。
部署Profiles
前提是Profiler安装成功。有两种方法,分别是通过Stellar Shell和命令行进行部署
Stellar Shell
重启Stellar Shell,带上 -z指定zookeeper位置
[root@node1 ~]# source /etc/default/metron
[root@node1 ~]# $METRON_HOME/bin/stellar -z $ZOOKEEPER
Stellar, Go!
[Stellar]>>>
[Stellar]>>> %functions CONFIG CONFIG_GET, CONFIG_PUT
-
定义profile(如已定义请跳过)
-
检查是否已部署
推送一个新的profile设置是有危险的,这会覆盖任何已有的设置。检查一下现有的。并且手动合并已有的设置和你的定义设置。
[Stellar]>>> existing := CONFIG_GET("PROFILER")
{
"profiles" : [ ]
}
##大概是没有的
3.将设置推送给Profiler拓扑,会覆盖任何已有的profile定义
[Stellar]>>> CONFIG_PUT("PROFILER", conf)
检查一下
[Stellar]>>> existing := CONFIG_GET("PROFILER")
{
"profiles" : [ {
"profile" : "hello-world",
"foreach" : "ip_src_addr",
"result" : {
"profile" : "count",
"triage" : { }
},
"type" : "duration",
"onlyif" : "exists(ip_src_addr)",
"init" : {
"count" : "0"
},
"update" : {
"count" : "count + 1"
},
"groupBy" : [ ]
} ]
}
命令行
- 在该位置创建
$METRON_HOME/config/zookeeper/profiler.json
用于保存profile定义的文件。不过我所用的环境里已经有了类似的json文件,可以找找看,看看现有的文件内容吧。
zookeeper下的文件及文件夹,可以从名称中看出对应配置
[root@node01 zookeeper]# ll
总用量 8
drwxr-xr-x 2 root root 292 11月 13 15:15 enrichments
-rw-r--r-- 1 root root 612 11月 13 15:12 global.json
drwxr-xr-x 2 root root 4096 11月 13 15:15 indexing
drwxr-xr-x 2 root root 137 11月 13 15:14 parsers
global.json内容
{
"es.clustername" : "metron",
"es.ip" : "node01.bdp:9300",
"es.date.format" : "yyyy.MM.dd",
"parser.error.topic" : "indexing",
"update.hbase.table" : "metron_update",
"update.hbase.cf" : "t",
"es.client.settings" : {
"client.transport.ping_timeout" : "500s"
},
"profiler.client.period.duration" : "15",
"profiler.client.period.duration.units" : "",
"user.settings.hbase.table" : "user_settings",
"user.settings.hbase.cf" : "cf",
"geo.hdfs.file" : "/apps/metron/geo/GeoLite2-City.mmdb.gz",
"es.async.bulk.size" : "10000",
"es.async.concurrent.num" : "8",
"es.flush.ms" : "1"
}
以上似乎是别的设置。所以也有可能是在子文件夹下,例如enrichment
[root@node01 zookeeper]# cd enrichments/
[root@node01 enrichments]# ll
总用量 48
-rwxr-xr-x 1 root root 382 11月 13 15:14 asset_vul.json
-rw-r--r-- 1 root root 253 11月 13 15:14 attack_pcap.json
-rwxr-xr-x 1 root root 290 11月 13 15:14 conn.json
-rwxr-xr-x 1 root root 331 11月 13 15:15 dns.json
-rw-r--r-- 1 root root 255 11月 13 15:14 extract_files.json
-rwxr-xr-x 1 root root 333 11月 13 15:15 files.json
-rwxr-xr-x 1 root root 332 11月 13 15:15 http.json
-rwxr-xr-x 1 root root 284 11月 13 15:15 probe_asset.json
-rwxr-xr-x 1 root root 332 11月 13 15:15 smtp.json
-rwxr-xr-x 1 root root 338 11月 13 15:14 suricata.json
-rwxr-xr-x 1 root root 281 11月 13 15:15 swv.json
-rwxr-xr-x 1 root root 453 11月 13 15:14 vul.json
多个json配置,随便看一个就好
[root@node01 enrichments]# cat asset_vul.json
{
"enrichment": {
"fieldMap": {
"stellar": {
"config": {
"enrich": [
"enrichments:= BDP_ENRICHMENT_ASSET_VUL_PROCESS(seq_uuid,sensor_id,asset_ip,mac,os,asset_type,sub_category,firm,software,serial_num,device_model,asset_vul,service,timestamp,'node01.bdp','DPRedis@1q2w3e4r','6379')"
]
}
}
}
},
"threatIntel": {
"fieldMap": {
}
}
}
##这个是enrichment配置
2.将设置定义上传到zookeeper
$ source /etc/default/metron
$ cd $METRON_HOME
$ bin/zk_load_configs.sh -m PUSH -i config/zookeeper/ -z $ZOOKEEPER
直接看看zk中对应节点的内容好了
....
太多了,还有刚放上去的hello-world
最后,似乎在DP,并没有用上PROFILER的相关机制。下一篇的话从Metron—platForm开始吧。