In the previous post we discussed some of the limitations of Net commands. Most notably, the output limitation (doesn’t show all groups) and it doesn’t allow for flexible searching. In this post we’ll discuss the DS commands to get around these limitations.
DSGet, DSQuery, DS*
While these tools are useful, they aren’t always available. As a pen tester and red teamer, I have to live with what I can find on the systems I come across. I find that these tools are still more widespread than the latest PowerShell Active Directory cmdlets, at least on non-system administrator systems. Here is a useful Stack Overflow post on the subject.
Recursive Searches
In the last post, we discussed a limitation in net group in that it doesn’t show groups in other groups. The DS commands do! As a reminder, let’s take a look at what we saw with net group
when looking at the list of domain administrators.
Now let’s do the same search, but use the dsquery
and dsget
.
dsquery group -name "Domain Admins" | dsget group -expand -members
This shows us all the good stuff in the group, including the groups and users in those groups no matter how far down they are! Recursion FTW!
Flexible Searches
Some organizations will append or prepend text to the username or display name for administrative, privileged, or service accounts. The dsquery command allows us to search for these accounts using a more flexible seach. The command below will search for users with “(admin)” in the display name.
dsquery user -name *(admin)*
We can also search based on the username with -samid
.
dsquery user -samid *admin*
You can find more search methods by looking at dsquery user /?
.
These searches are MUCH better than what we get with just net user
.
Pipeline
One of the nicest features of the DS commands is that they work well together on the pipeline. I can take the previous “(admin)” search and pipe it into dsget user
to get a better look at the user information.
We can get the memberships of each by them by adding two options: -memberof -expand
As you can see these commands are quite powerful and are a significant upgrade from net user.
Related Stories
View MoreIntroduction to Sliver
By Red Siege | November 7, 2022
By: Justin Palk, Security Consultant Around the time Tim decided he was going to give a Siegecast on selecting a C2, I finished building out a test Windows AD domain […]
Learn MoreMoving beyond T4 – Deconstructing Nmap Tuning
By Red Siege | July 6, 2022
by Alex Norman, Senior Security Consultant Nmap -T4 -iL targets.txt This is a very common scan string that many people use to get initial recon done on assessments and, to […]
Learn MoreCreating a Simple Windows Domain for Offensive Testing: Part 4
By Red Siege | June 23, 2022
By: Justin Palk, Security Consultant This is part four of my series of blog posts on creating a windows domain for offensive security testing. In part 1, I stood up […]
Learn More