CUSTOM_ALLDATA 类型调用插件未生效
0xlwoe21k opened this issue · 6 comments
0xlwoe21k commented
规则如下,在check_node中调用【DetectTTY】插件,类型为文档中的【CUSTOM_ALLDATA】
<rule rule_id="pipe_shell_detect" author="mg" type="Detection">
<rule_name>pipe_shell_custom_detect</rule_name>
<alert_data>True</alert_data>
<harm_level>high</harm_level>
<desc kill_chain_id="persistent" affected_target="host_process">Double Piped Reverse Shell Detection, Connection Part</desc>
<filter part="data_type">59</filter>
<check_list>
<!-- <check_node type="EQU" part="exe" logic_type="or" separator="|">
<![CDATA[/bin/cat|/usr/bin/cat|/usr/bin/ls|/bin/ls|/usr/bin/cp|/bin/cp]]>
</check_node> -->
<check_node type="CUSTOM_ALLDATA">DetectTTY</check_node>
</check_list>
<node_designate></node_designate>
<del />
<modify></modify>
<action />
<append type="static" append_field_name="alert_type_us">persistent</append>
<append type="static" append_field_name="rule_name">pipe_shell_custom_detect</append>
</rule>
【DetectTTY】插件代码
from ast import Try
import json
class Plugin(object):
def __init__(self):
self.name = None
self.type = None
self.log = None
self.redis = None
def plugin_exec(self, arg, config):
self.log.info(arg)
result = dict()
try:
data = json.loads(arg)
tty = data['tty']
new_tty = tty[:3]+'/'+tty[3:]
if data['stdin'].find(new_tty) > -1 and data['stdout'].find(new_tty) > -1:
result["flag"] = False
result["msg"] = arg
self.log.info('false')
else:
result["flag"] = True
result["msg"] = arg
self.log.info('true')
except Exception as e:
result["flag"] = False
result["msg"] = arg
self.log.info('exce')
return result
目录【DetectTTY/elkeid.txt】的内容
[root@elkeid DetectTTY]# cat elkeid.txt
[plugin]
name = DetectTTY
type = Custom
description = tty
runtime = Python
author = mg
执行相关命令后,未发现日志信息有任何关于此插件的信息打印,但是其它插件有信息打印出来
TaeRoen commented
@0xlwoe21k 感觉是python代码中, plugin_exec里的try部分最后漏了一行 return result, 加上试试
0xlwoe21k commented
@TaeRoen 确实漏了return ,但是不影响,因为根本没有进入到plugin_exec来,self.log.info(arg) 没有打印任何东西。
当把CUSTOM_ALLDATA 改成CUSTOM后就可以了
TaeRoen commented
@0xlwoe21k 其实这些log是return时带回给hub进程的, 如果plugin里没有return, log可能也不会在hub里打印出来. 这时候可以去看下 plugin.stdout文件, 那个文件才是plugin进程的输出
TaeRoen commented
@0xlwoe21k check_node里的 CUSTOM_ALLDATA, 对应的 plugin type是 Origin, 改下DetectTTY/elkeid.txt看下
0xlwoe21k commented