-
Notifications
You must be signed in to change notification settings - Fork 212
/
Invoke-DACheck.ps1
79 lines (70 loc) · 2.58 KB
/
Invoke-DACheck.ps1
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
function Invoke-DACheck {
<#
.SYNOPSIS
Checks to see if current user is in DA Groups and if he is returns a specfic string alerting user that they are DA for Automated purposes.
.PARAMETER Initial
Enables a share Anyone can Read/Write to.
#>
[cmdletbinding()]
param(
[Parameter(Position=0,ValueFromPipeline=$true)]
[String[]]
$Initial
)
process {
# Returns list of process owners
$User = Get-User
# Returns list of domain admins
$DomainAdmins = Get-DomainAdmins
# Loop through Process Owners
ForEach ($DomainUser in $DomainAdmins)
{
if($User -match $DomainUser)
{
if($Initial)
{
Write-Output "[!] Found-DA-User: $DomainUser"
}
else
{
Write-Output "[!] Found-DA-User: $DomainUser"
}
}
}
}
}
function Get-DomainAdmins {
<#
.SYNOPSIS
Montiotrs the current DA accounts and alerts the desired admin if a change where to take place whithin the group.
.PARAMETER CheckRate
Pass me a command in a Variable.
.PARAMETER EmailAdress
Pass me a command in a Variable.
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$True)]
[string]$Command
)
process
{
$groupname = 'Domain Admins'
$DAUsers = (New-Object System.DirectoryServices.DirectoryEntry((New-Object System.DirectoryServices.DirectorySearcher("(&(objectCategory=Group)(name=$($groupname)))")).FindOne().GetDirectoryEntry().Path)).member | % { (New-Object System.DirectoryServices.DirectoryEntry("LDAP://"+$_)) } | foreach {$_.sAMAccountName}
return $DAUsers
}
}
function Get-User {
<#
.SYNOPSIS
Montiotrs the current DA accounts and alerts the desired admin if a change where to take place whithin the group.
#>
process {
# This retrieves all running processes that are not running as local system and such
$ProcessOwner = @{}
Get-WmiObject win32_process | ForEach-Object {$ProcessOwner[$_.handle] = $_.getowner().user}
$ProcessOwnerList = Get-Process | Select-Object Id, @{l="Owner";e={$ProcessOwner[$_.id.ToString()]}} | Where-Object {!($ProcessOwner[$_.id.ToString()] -match "(?:SYSTEM|(?:LOCAL|NETWORK) SERVICE)")}
$Output = $ProcessOwnerList | Select-Object Owner -Unique
return $Output
}
}