Powershell & .NET Classes
Being able to develop tools on the fly is a valuable skill in engagements. We can create tools in Powershell & .NET that can be run with basic privileges.
Last updated
Being able to develop tools on the fly is a valuable skill in engagements. We can create tools in Powershell & .NET that can be run with basic privileges.
Last updated
Chances are Administrators have set some type of security in place to restrict PowerShell scripts.
determines what scripts and files are allowed to run on the current session. It can be Restricted, AllSigned, RemoteSigned Unrestricted, and Bypass.
In Microsoft .NET classes related to AD are found in the System.DirectoryServices.ActiveDirectory namespace.
Let's making this into a PowerShell script file. We'll call it testing.ps1
.
We can build out this path and use it to create our own custom communication scripts to enumerate active directory.
Now that we have the LDAP URI Path we can start to perform queries.
The above image returns all entries in the entire domain. This is a lot of information, it's best to filter out what we're looking for.
One way we can find all users is by Sam-Account-Type. This is the attribute applied to all users, computers, and group objects.
SAM_USER_OBJECT 0x30000000
SAM_GROUP_OBJECT 0x10000000
SAM_MACHINE_ACCOUNT 0x30000001
Let's loop through the newly created Users object and print all the properties for each entry.
Active Directory relies on as it's communication protocol. Like other protocls we can specity a URI scheme. This scheme is known as the LDAP ADsPath.
We can use directly in PowerShell. This is a powerful tool when developing scripts.
In .NET ADSI we can use the object to perform queries against Active Directory. We'll add a FindAll() query that finds all entries in Active Directory.