Skip to content

Commit ed0176c

Browse files
committed
Hacker enumeration AD Scripts
1 parent 0a4d1e3 commit ed0176c

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,31 @@
22

33
>Purpose of these PowerShell Scripts, is to get Notable Active Directory Accounts or high value objects:
44
5-
1. Extract a list of notable AD User Accounts that have not change their passwords and did not logon since given date. - Dormant
6-
2. List all possible accounts with SPN values kerberoastable from Active Directory.
7-
3. High value AD Computers
8-
4. Get the current user running permissions for all objects ACL
9-
5. Password Spray single password against list of usernames.
5+
1. Potential weak accounts target by malicious actors with weak passwords
6+
2. Notable AD User Accounts that have not change their passwords and did not logon since given date. - Dormant
7+
3. List all possible accounts with SPN values kerberoastable from Active Directory.
8+
4. High value AD Computers
9+
5. Get the current user running permissions for all objects ACL
10+
6. Password Spray single password against list of usernames.
11+
12+
----
13+
14+
## Potential Weak Targets
15+
16+
>PowerShell active directory script to Identify accounts targeted by malicious actors that gain internal network access:
17+
* Enabled accounts
18+
* Account created over 2 years ago
19+
* password last set older than 1 year
20+
* password never expires flag enabled
21+
22+
>Remediation:
23+
* change to use strong complex passwords
24+
* AD user Account with no recent logon history for last 6 months must be disabled
25+
* Cleanup by removing all group membership and permissions
26+
27+
```
28+
Potential-weak-target-accounts.ps1
29+
```
1030

1131
----
1232

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Load Active Directory Module
2+
Import-Module ActiveDirectory
3+
4+
# Define timeframes
5+
$twoYearsAgo = (Get-Date).AddYears(-2)
6+
$oneYearAgo = (Get-Date).AddYears(-1)
7+
$sixMonthsAgo = (Get-Date).AddMonths(-6)
8+
9+
# Output file paths
10+
$legacyAccountsFile = "C:\Temp\Reports_LegacyAccounts.csv"
11+
$inactiveAccountsFile = "C:\Temp\Reports_InactiveAccounts.csv"
12+
13+
# Create arrays to store results
14+
$legacyAccountsResults = @()
15+
$inactiveAccountsResults = @()
16+
17+
# Get legacy accounts
18+
Write-Output "Identifying legacy accounts..."
19+
$legacyAccounts = Get-ADUser -Filter * -Property WhenCreated, PasswordLastSet, PasswordNeverExpires, Enabled | Where-Object {
20+
$_.WhenCreated -lt $twoYearsAgo -and
21+
$_.PasswordLastSet -lt $oneYearAgo -and
22+
$_.PasswordNeverExpires -eq $true
23+
}
24+
25+
# Collect legacy accounts into the results array
26+
foreach ($account in $legacyAccounts) {
27+
Write-Output "Legacy account found: $($account.SamAccountName)"
28+
$legacyAccountsResults += [PSCustomObject]@{
29+
UserName = $account.SamAccountName
30+
DisplayName = $account.Name
31+
WhenCreated = $account.WhenCreated
32+
PasswordLastSet = $account.PasswordLastSet
33+
PasswordNeverExpires = $account.PasswordNeverExpires
34+
Enabled = $account.Enabled
35+
}
36+
}
37+
38+
# Get inactive accounts
39+
Write-Output "Identifying inactive accounts..."
40+
$inactiveAccounts = Get-ADUser -Filter * -Property LastLogonDate, Enabled | Where-Object {
41+
$_.LastLogonDate -lt $sixMonthsAgo -or
42+
$_.LastLogonDate -eq $null
43+
}
44+
45+
# Collect inactive accounts into the results array
46+
foreach ($inactiveAccount in $inactiveAccounts) {
47+
Write-Output "Inactive account found: $($inactiveAccount.SamAccountName)"
48+
$inactiveAccountsResults += [PSCustomObject]@{
49+
UserName = $inactiveAccount.SamAccountName
50+
DisplayName = $inactiveAccount.Name
51+
LastLogon = $inactiveAccount.LastLogonDate
52+
Enabled = $inactiveAccount.Enabled
53+
Status = "Inactive"
54+
}
55+
}
56+
57+
# Export results to CSV
58+
Write-Output "Exporting results to CSV files..."
59+
$legacyAccountsResults | Export-Csv -Path $legacyAccountsFile -NoTypeInformation -Encoding UTF8
60+
$inactiveAccountsResults | Export-Csv -Path $inactiveAccountsFile -NoTypeInformation -Encoding UTF8
61+
62+
Write-Output "Reports generated:"
63+
Write-Output "Legacy Accounts Report: $legacyAccountsFile"
64+
Write-Output "Inactive Accounts Report: $inactiveAccountsFile"
65+
66+
Write-Output "Script completed successfully."

0 commit comments

Comments
 (0)