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 MoreAttacking SAML implementations
By Red Siege | November 2, 2021
SAML and SAML Attacks Recently a client mentioned that they wanted me to pay particular attention to the SAML authentication on an app I was going to be testing. It’s […]
Learn MoreBypassing Signature-Based AV
By Red Siege | August 25, 2021
If you want to execute arbitrary code on an endpoint during a penetration test, red team, or assumed breach, chances are you’ll have to evade some kind of antivirus solution. […]
Learn MoreSans Core Netwars Tournament of Champions Europe
By Red Siege | August 9, 2021
From Justin Palk, Security Consultant: I’ll be honest, it feels good to win. Popping a shell sends a shiver down my spine. But getting into a duel with another team […]
Learn More