使用win32evtlog为多个通道同时创建Windows事件侦听器



我目前正在python中开发一些代码,这些代码应该充当Windows事件日志侦听器。目前,我正在使用这个问题中的代码来处理win32evtlog。EvtSubscribe,它运行良好,但我遇到了两个问题。

1-同时订阅多个频道:

我需要同时收听多个频道,但EvtSubscribe只从特定频道获取事件。有没有办法同时订阅多个频道?我试着用多处理来完成它,但由于某种原因,函数完成了,而不是等待用户输入,就像我在没有多处理的情况下正常执行时一样。这意味着侦听器不会等待事件,而只是关闭。我尝试运行的代码是:

paths = {
"firewall": 'Microsoft-Windows-Windows Firewall With Advanced Security/Firewall'
}
def on_event(action, context, event_handle):
if action == win32evtlog.EvtSubscribeActionDeliver:
print("CAUGHT EVENT")
def log_subscribe(type):
print("in log subscribe")
channel = paths[type]
print("path: ", channel)
handle = win32evtlog.EvtSubscribe(
channel,
win32evtlog.EvtSubscribeToFutureEvents,
None,
Callback = on_event)

input()
win32evtlog.CloseEventLog(handle)
if __name__ == "__main__":
domains = ["firewall"]
with concurrent.futures.ProcessPoolExecutor() as exec:
results = [exec.submit(log_subscribe, domain) for domain in domains]            
for f in concurrent.futures.as_completed(results):
print("HEYY???")

理想情况下,稍后我将能够向路径dict添加新通道,并为每个日志创建一个侦听器。

2-无法访问安全日志:

出于某种原因,安全日志是我唯一无法访问的日志。它总是在访问被拒绝的情况下失败。

handle = win32evtlog.EvtSubscribe(pywintypes.error: (5, 'EvtSubscribe', 'Access is denied.')

有办法解决这个问题吗?理想情况下,我不想以管理员身份运行它来获得访问权限。

有没有更好的方法来解决这个问题?我是否应该考虑另一种方法?提前感谢您的帮助。

1-同时订阅多个频道:

我建议你可以参考线程:Python websockets,订阅多个通道

2-无法访问安全日志:

安全日志是为系统使用而设计的。但是,如果用户被授予SE_Security_NAME权限("管理审核和安全日志"用户权限(,则可以读取和清除安全日志。有关详细信息,请参阅特权。

最新更新