How would you grab just the distinguishedName value from the LDAP plugin output so it can be used for another action?

I am looking at how to get only the DN from the results of the AD LDAP plugin’s Query action.

For example I do an LDAP query of (mail={email}) since it seems to be reliable and it returns a ton of output.

This is the output object which is of type [array][object] or

{{[“Query For AD User”].[results]}}

so I tried {{[“Query For AD User”].[results].[0].[attributes].[distinguishedname]}}

this is not returning just the DN though.

How would you grab just the distinguishedName value so it can be used for another action?

distinguishedName

You need to cap the N in Name.

Microsoft does camel case, and we usually do snake case, so some of the MS output will do funky things like that.

{{[“Query For AD User”].[results].[0].[attributes].[distinguishedName]}} is still returning the same output.

Let me add that I am putting this var in an artifact to tell what is going on. For some reason it actually just adds this var to the end of the output for {{[“Query For AD User”].[results]}} as “dn”:"{{[“Query For AD User”].[results].[0].[attributes].[distinguishedName]}}"

{{[“Active Directory Users”].[results].[0].[attributes].[distinguishedName]}} has never given me issues returning the dn. I use this both in Artifacts, Joins, and always use this output as the input to any password reset, enable, or disable action.
Just curious, what does this give you in an artifact?

{{#each ["Query For AD User"].[results]}}
{{#with attributes}}
 “dn”:"{{distinguishedName}}"
{{/with}}
{{/each}}
2 Likes

comes back with “dn”:“CN=user info…”

I wonder if your pulling back more than one Object?
After my LDAP queries I always do a Decision Step on the the count of results to make sure I only am working with one account. I then do a Type Converter of String to Object on [results].[0].[attributes] so further down the line I have an easy object to work with e.g. {{[“AD User”].[output].[distinguishedName]}} this is needed if you want to check this in a Decision Step to see if the dn contains an OU

2 Likes

I do this now in an artifact and use the string it creates for the DN now.

{{#each [“Query For AD User”].[results]}}
{{#with attributes}}
{{distinguishedName}}
{{/with}}
{{/each}}

how do you measure the count of the results, curious?

length({{[“Query For AD User”].[results]}}) = 1

We just pushed up an update to the plugin to return the number of results in a variable called count to make it a little more user-friendly. In addition, we now support the ability to query on attributes.

More updates to AD/LDAP plugin forthcoming.

2 Likes

So far this has been working great! There was so much “extra” information that my queries were pulling back that I didn’t need. This is way cleaner. Also, the count is a nice touch, I switched my decisions to start using this

2 Likes

these Rapid7 folks are on the money $$$, I just made the same change. Rock on!

2 Likes