Apr 26

Blog Move

I have accepted a position with another company, so this blog is moving.

The new blog location is: ADSecurity.org

Comments posted on this blog may not be approved or replied to. Please use the Contact form if you need help.

Nov 30

Using PowerShell to access Windows Event Logs

Recently, I have worked on a PowerShell script to parse Windows Security logs for specific events. Here are some useful resources:

 

Nov 24

RegEX Cheat Sheet

PowerShell supports Regular Expressions (RegEX) which has tremendous capability.

The RegEX Cheat Sheet is an invaluable resource when using RegEx in PowerShell scripts.

Nov 16

Old School: Searching Active Directory with Windows PowerShell (ADSI)

Old School: Searching Active Directory with Windows PowerShell using ADSI (prior to v2 & AD cmdlets)

Nov 04

Parsing a large multi-line text field (variable) for a specific string and extract text from it:

Parsing a large multi-line text field (variable) for a specific string and extract text from it:

$EventMessage =
@”
An account was successfully logged on.

Subject:
Security ID:  SYSTEM
Account Name:  METCORPWKS201$
Account Domain:  METCORP
Logon ID:  0x2b5
Logon Type:10
New Logon:
Security ID:  METCORP\Administrator
Account Name:  Administrator
Account Domain:  METCORPWKS201
Logon ID:  0bc123d
Logon GUID:  {00000000-0000-0000-0000-000000000000}
Process Information:
Process ID:  0x123
Process Name:  C:\Windows\System32\winlogon.exe
Network Information:
Workstation Name: METCORPWKS201
Source Network Address: 10.10.10.201
Source Port:  1234
Detailed Authentication Information:
Logon Process:  User32
Authentication Package: Negotiate
Transited Services: –
Package Name (NTLM only): –
Key Length:  0

This event is generated when a logon session is created. It is generated on the computer that was accessed.

The subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe.

The logon type field indicates the kind of logon that occurred. The most common types are 2 (interactive) and 3 (network).

The New Logon fields indicate the account for whom the new logon was created, i.e. the account that was logged on.

The network fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.

The authentication information fields provide detailed information about this specific logon request.

The authentication information fields provide detailed information about this specific logon request.

Logon GUID is a unique identifier that can be used to correlate this event with a KDC event.
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.

“@

$EventMessageLogonNumber = $EventMessage | Select-String -Pattern “Logon Type:\w+” -AllMatches | Select -ExpandProperty matches | Select -ExpandProperty value
$EventMessageAccountNameText = $EventMessage | Select-String -Pattern “Account Name:\s+\w+” -AllMatches | Select -ExpandProperty matches | Select -ExpandProperty value
$EventMessageAccountName = (($EventMessageNameText -split “:”)[1]) -Replace(“`t”,””)
$EventMessageWorkstationNameText = $EventMessage | Select-String -Pattern “Workstation Name:\s+\S+” -AllMatches | Select -ExpandProperty matches | Select -ExpandProperty value
$EventMessageWorkstationName = (($EventMessageWorkstationNameText -split “:”)[1]) -Replace(“`t”,””)
$EventMessageSourceIPText = $EventMessage | Select-String -Pattern “Source Network Address:\s+\S+” -AllMatches | Select -ExpandProperty matches | Select -ExpandProperty value
$EventMessageSourceIP = (($EventMessageSourceIPText -split “:”)[1]) -Replace(“`t”,””)
$EventMessageLogonNumber
$EventMessageAccountName
$EventMessageWorkstationName
$EventMessageSourceIP

Oct 30

Drop (remove) the last character from a string

Drop (remove) the last character from a string:

$ComputerName = ‘DCCOMP01$’
$ComputerName = $ComputerName.Substring(0,$ComputerName.Length-1)
$ComputerName

Result is “DCCOMP01”.
This works especially well when the last character is a special PowerShell reserved one like “$”.

Oct 23

Escape a PowerShell reserved character, split the escaped character, and extract text from it

Escape a PowerShell reserved character, split the escaped character, and extract text from it:

$RepChar = ‘\\’
$UserNameField = “DOMAIN\User1”
$UserName = ($UserNameField -split($RepChar))[1]
$UserName

Result is “User1”

Oct 18

Windows Server 2012 R2 Available Now

Post content has moved to ADSecurity.org.

Direct link to content: http://adsecurity.org/?p=868

 

Oct 16

Updated Post on Machine Account (AD Computer Object) Password Updates

Post Update.

I recently updated content for the post:

Machine Account (AD Computer Object) Password Updates
 
 

Oct 15

Create a HashTable (aka lookup table) from a CSV file

Create a HashTable (aka lookup table) from a CSV file

$IPComputerHashTable = @{}
$IPComputerHashTableData = Import-CSV $IPComputerHashTableFile -Header IPvAddress,ComputerName
ForEach ($IPComputerHashTableDataItem in $IPComputerHashTableData )
{
$IPComputerHashTableDataItemIPvAddress = $IPComputerHashTableDataItem.IPvAddress
$IPComputerHashTableDataItemComputerName = $IPComputerHashTableDataItem.ComputerName
$IPComputerHashTable.Set_Item(“$IPComputerHashTableDataItemIPvAddress”,”$IPComputerHashTableDataItemComputerName”)
}

Older posts «