【问题标题】:Parsing message field of Windows Event Logs (security) with pandas使用 pandas 解析 Windows 事件日志(安全)的消息字段
【发布时间】:2017-03-21 11:26:47
【问题描述】:

我有一个如下所示的安全事件日志数据框:

"machinename","eventid","entrytype","source","timegenerated","timewritten","username","message"
"MyMachineName","4656","failureaudit","microsoft-windows-security-auditing","3/7/2017 3:34:09 pm","3/7/2017 3:34:09 pm",,"a handle to an object was requested.    subject:   security id:  s-1-5-21-123456789-123456789-123456789-1381912   account name:  account.name.matt   account domain:  mydomain   logon id:  0x0d4d0d1d    object:   object server:  security   object type:  key   object name:  \registry\machine\system\controlset001\control\class\{1d36e972-f315-1111-b2d3-09112bf10211}\properties   handle id:  0x0    process information:   process id:  0x35f4   process name:  c:\windows\system32\wbem\wmiprvse.exe    access request information:   transaction id:  {00000000-0000-0000-0000-000000000000}   accesses:  %%1538      %%4432      %%4435      %%4436         access reasons:  -   access mask:  0x20019   privileges used for access check: -   restricted sid count: 0"
"MyMachineName","4688","successaudit","microsoft-windows-security-auditing","1/1/2011 3:34:09 pm","1/1/2011 3:34:09 pm",,"a new process has been created.    subject:   security id:  s-1-5-18   account name:  account.name.matt    account domain:  mydomain  logon id:  0x3e5    process information:   new process id:  0x1e98   new process name: c:\windows\system32\conhost.exe   token elevation type: %%1936   creator process id: 0x1b8   process command line:     token elevation type indicates the type of token that was assigned to the new process in accordance with user account control policy.    type 1 is a full token with no privileges removed or groups disabled.  a full token is only used if user account control is disabled or if the user is the built-in administrator account or a service account.    type 2 is an elevated token with no privileges removed or groups disabled.  an elevated token is used when user account control is enabled and the user chooses to start the program using run as administrator.  an elevated token is also used when an application is configured to always require administrative privilege or to always require maximum privilege, and the user is a member of the administrators group.    type 3 is a limited token with administrative privileges removed and administrative groups disabled.  the limited token is used when user account control is enabled, the application does not require administrative privilege, and the user does not choose to start the program using run as administrator."

如何扩展“消息”字段并根据每个键值对创建一组列,使句子与键值对分开?

本质上,我想获取任何事件并根据消息中的键值对对其进行转换。

我已将消息拆分如下,但输出将项目放入列表中。不知道如何添加正确的列。

print(security.message.str.split(":\\s"))

任何帮助都会很棒。谢谢。

【问题讨论】:

    标签: python windows python-3.x pandas


    【解决方案1】:

    我真的很想发表评论,但不能这样。您是否检查过您的消息是否正确拆分? 获得项目列表后,您可以使用 join、append 或 concat 添加其他列。见Append column to pandas dataframe

    【讨论】:

    • 我尝试了多种方式拆分。我看到的问题是,我得到了一个拆分的内容列表,但我需要专门创建一个列标题或根据前面有 : 的字段扩展为列名。在安全消息字段中,有许多不同的格式。我正在寻找是否有人专门解决了它。
    • 我认为你需要将值拆分到字典中,检查一下stackoverflow.com/q/186857/5729272 一旦你有了键值对,键就可以成为列名。
    • @johnnyb 正则表达式可能是一个解决方案,但我认为您的数据不适合轻松拆分。大多数键是两个词,但有些不是这样,通过自动捕获内容,您最终会捕获部分数据作为键,反之亦然。
    猜你喜欢
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    相关资源
    最近更新 更多