Security

Splunk Query with Ldap Info

gdavid
Path Finder

I'm trying to join 2 queries together in a table

From the Active Directory App, i took this query:

eventtype=msad-account-lockout | eval actor=if(EventCode==4767 OR EventCode==671,src_user,src_host) | eval DateTime=strftime(_time, "%c") | table DateTime,signature,user,actor | rename signature as "Action",user as User, actor as "Change On/By"

Then i wanted to get the phone numbers from ldap to call the users so i tried to append this in between with no luck.

| ldapsearch domain=mydomain* search="(&(objectClass=user)(sAMAccountName=myuser))" attrs="dn,mobile,telephoneNumber"*

Errors:
Error in 'ldapsearch' command: This command must be the first command of a search.

can anyone assist? both return results when run independently. the end goal is to setup a real time alert for the lockouts with phone numbers in the emails.

thanks

Tags (1)
0 Karma
1 Solution

ahall_splunk
Splunk Employee
Splunk Employee

You need to use ldapfilter instead.

Go into the SA-ldapsearch app and look at the documentation - it's similar to ldapsearch, but does searches against the event pipeline. You will need to add in src_nt_domain, so something like this should work:

eventtype=msad-account-lockout | eval actor=if(EventCode==4767 OR EventCode=671,src_user,src_host) | ldapfilter domain=$src_nt_domain$ search=(&(objectClass=user)(sAMAccountName=$user$))" attrs="mobile,telephoneNumber" | table _time,signature,user,actor,mobile,telephoneNumber | rename signature as "Action", user as "Locked User", actor as "Changed By", mobile as "Cell", telephoneNumber as "Phone"

Enjoy!

View solution in original post

ahall_splunk
Splunk Employee
Splunk Employee

You need to use ldapfilter instead.

Go into the SA-ldapsearch app and look at the documentation - it's similar to ldapsearch, but does searches against the event pipeline. You will need to add in src_nt_domain, so something like this should work:

eventtype=msad-account-lockout | eval actor=if(EventCode==4767 OR EventCode=671,src_user,src_host) | ldapfilter domain=$src_nt_domain$ search=(&(objectClass=user)(sAMAccountName=$user$))" attrs="mobile,telephoneNumber" | table _time,signature,user,actor,mobile,telephoneNumber | rename signature as "Action", user as "Locked User", actor as "Changed By", mobile as "Cell", telephoneNumber as "Phone"

Enjoy!

gdavid
Path Finder

nevermind, i see my mistake.

additional note: i was getting peridoic emails with no numbers, i noticed that the active directory app doesn't seem to pick up src_nt_domain from 2008 r2 domain controller events properly. i hard-coded my domain in the ldap search as i only have 1.

thanks for you help again.

0 Karma

gdavid
Path Finder

that worked out perfect, missing one " right after search=

can you explain $src_nt_domain$ & $user$, i would've assumed

ldapfilter domain=mydomain search="(&(objectClass=user)(sAMAccountName=src_user))"

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...