Repository navigation
Expand file tree
/
Copy pathBruteForceTestScript.ps1
More file actions
90 lines (73 loc) · 2.58 KB
/
Copy pathBruteForceTestScript.ps1
File metadata and controls
90 lines (73 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<#
.SYNOPSIS
Generates Windows Security Event ID 4625 (failed logins) for SIEM testing
.DESCRIPTION
Creates realistic failed authentication events to test:
- Windows Event Logging
- Log collection (Winlogbeat)
- Elasticsearch ingestion
- Kibana detection rules
.NOTES
Version: 2.0
Author: Mostafa Essam (0xMOSTA)
#>
param (
[Parameter(Mandatory=$true)]
[string]$TargetUser,
[Parameter(Mandatory=$true)]
[int]$AttemptCount,
[int]$DelayMs = 300,
[switch]$RandomizeSource
)
# Import required assembly
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
# Configuration
$IncorrectPassword = "SIEM_TestPassword123!" # Will always fail
$eventLogSource = "Security"
$startTime = Get-Date
# Generate random IPs if enabled
$sourceIPs = @("192.168.1.10", "10.0.0.15", "172.16.5.20")
if ($RandomizeSource) {
$sourceIPs = 1..10 | ForEach-Object { "192.168.1.$_" }
}
Write-Host @"
[ Brute Force Test Configuration ]
Target User: $TargetUser
Attempts: $AttemptCount
Delay Between: ${DelayMs}ms
Randomize Sources: $($RandomizeSource.IsPresent)
Start Time: $startTime
"@
# Main test loop
1..$AttemptCount | ForEach-Object {
$attemptNum = $_
$currentIP = if ($RandomizeSource) { $sourceIPs | Get-Random } else { $sourceIPs[0] }
try {
# Create authentication context
$context = New-Object System.DirectoryServices.AccountManagement.PrincipalContext(
[System.DirectoryServices.AccountManagement.ContextType]::Machine
)
# Simulate failed login (will generate Event ID 4625)
$null = $context.ValidateCredentials($TargetUser, $IncorrectPassword)
Write-Host "[Attempt $attemptNum] Generated failed login from $currentIP" -ForegroundColor DarkGray
# Optional: Add source IP to the Windows event (requires admin)
if ($false) { # Change to $true if you want to enrich events with source IP
$eventMessage = "Logon attempt failed for $TargetUser from $currentIP"
Write-EventLog -LogName $eventLogSource -Source "Microsoft Windows security auditing" `
-EventID 4625 -EntryType FailureAudit -Message $eventMessage
}
}
catch {
Write-Warning "[Attempt $attemptNum] Error: $($_.Exception.Message)"
}
# Add delay between attempts
if ($attemptNum -lt $AttemptCount) {
Start-Sleep -Milliseconds $DelayMs
}
}
Write-Host @"
`n[ Test Complete ]
Total attempts made: $AttemptCount
Start time: $startTime
End time: $(Get-Date)
"@