【发布时间】:2021-11-15 00:34:57
【问题描述】:
我在 Powershell 中有一个字符串,其中包含以下数据
An account failed to log on.
Subject:
Security ID: S-1-5-18
Account Name: TEX
Account Domain: TD2
Logon ID: 0x3E7
Logon Type: 8
Account For Which Logon Failed:
Security ID: S-1-0-0
Account Name: test_mathysf
Account Domain: tdlz2
Failure Information:
Failure Reason: Unknown user name or bad password.
Status: 0xC000006D
Sub Status: 0xC000006A
Process Information:
Caller Process ID: 0x4f80
Caller Process Name: C:\Windows\System32\inetsrv\w3wp.exe
Network Information:
Workstation Name: T22
Source Network Address: 192.168.10.28
Source Port: 45221
Detailed Authentication Information:
Logon Process: Advapi
Authentication Package: Negotiate
Transited Services: -
Package Name (NTLM only): -
Key Length: 0
This event is generated when a logon request fails. It is generated on the computer where access was attempted.
The Subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Ser
ver service, or a local process such as Winlogon.exe or Services.exe.
The Logon Type field indicates the kind of logon that was requested. The most common types are 2 (interactive) and 3 (network).
The Process Information fields indicate which account and process on the system requested the logon.
The Network Information fields indicate where a remote logon request originated. Workstation name is not always available and may be l
eft blank in some cases.
The authentication information fields provide detailed information about this specific logon request.
- Transited services indicate which intermediate services have participated in this logon request.
- Package name indicates which sub-protocol was used among the NTLM protocols.
- Key length indicates the length of the generated session key. This will be 0 if no session key was requested.
我想使用以下正则表达式模式转义 Subject 和 Key Lenght 之间的所有内容。
$pattern = "(?<=.*Subject:)\w+?(?=Length:*)"
正则表达式的结果应该是这样的
Subject:
Security ID: S-1-5-18
Account Name: TEX
Account Domain: TD2
Logon ID: 0x3E7
Logon Type: 8
Account For Which Logon Failed:
Security ID: S-1-0-0
Account Name: test_mathysf
Account Domain: tdlz2
Failure Information:
Failure Reason: Unknown user name or bad password.
Status: 0xC000006D
Sub Status: 0xC000006A
Process Information:
Caller Process ID: 0x4f80
Caller Process Name: C:\Windows\System32\inetsrv\w3wp.exe
Network Information:
Workstation Name: T22
Source Network Address: 192.168.10.28
Source Port: 45221
Detailed Authentication Information:
Logon Process: Advapi
Authentication Package: Negotiate
Transited Services: -
Package Name (NTLM only): -
Key Length: 0
但在我的项目中,正则表达式不起作用。 (它没有匹配)
之后,我将使用 ConvertFrom-StringData cmdlet 创建包含条目的哈希表(例如 Security ID --> Key = S-1-5-18)
有人知道问题出在哪里吗?
【问题讨论】:
-
这个字符串是从哪里来的?如果您可以访问底层事件数据,则将其提取为 XML 会容易得多
-
肯定需要基础数据样本。另外,您是否将正则表达式复制/粘贴到您的帖子中,或者您是否手动输入 - 我注意到您的模式中的“长度”一词拼写错误。
-
正则表达式字符串中有类型吗? ...(?=长度:*)...
-
主题前的 * 在 regex101.com 中给出错误。这也不会匹配多行字符串。使用 get-winevent 和使用 toxml() 肯定更容易。
-
@WaitingForGuacamole 数据来自 syslog api 作为 json。 Json 具有“文本”字段,其中包含作为普通字符串的文本
标签: regex powershell