<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic using SA-ldapsearch to search for related accounts in Security</title>
    <link>https://community.splunk.com/t5/Security/using-SA-ldapsearch-to-search-for-related-accounts/m-p/113279#M3566</link>
    <description>&lt;P&gt;I want to set up an alert if an account is disabled in active directory, a related account exists, and is left enabled.  The relationship between the accounts is defined, for example, related accounts have the same sAMAccountName but with a number appended to the end to make them unique.  &lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;I have an account in active directory that was disabled: sAMAccountName=Sara.  I want to verify the account is still disabled, and if so, automatically check active directory to see if Sara1 or Sara(whatever) exists, and if it is still enabled.&lt;/P&gt;

&lt;P&gt;I need to verify because this search will not be running in real-time, so it is possible an account was disabled and re-enabled, and I do not want this to generate results.  &lt;/P&gt;

&lt;P&gt;I have SA-ldapsearch installed, and I can get various parts of this to work, but not all in the same search.&lt;/P&gt;

&lt;P&gt;• I can perform the basic search to return results of all accounts that were disabled.&lt;BR /&gt;&lt;BR /&gt;
• I can use ldapfilter to check attributes and verify the account is still disabled.&lt;/P&gt;

&lt;P&gt;• I have used ldapsearch separately to return attributes of existing accounts, and can use the wildcard to find all the accounts I want.  &lt;/P&gt;

&lt;P&gt;How do I put this all together?  How do I take the results of the first half of my search, and feed them into an ldapsearch command adding a wildcard?  When I try this I run into the problem that ldapsearch must be the first command of a search.  &lt;/P&gt;

&lt;P&gt;I have thought about splitting this into two searches and using a lookup file to store the results, but that seems like an awfully complex way to do this.  And I am not even sure it would work.  &lt;/P&gt;

&lt;P&gt;What other options do I have?  &lt;/P&gt;</description>
    <pubDate>Tue, 14 Jan 2014 19:07:07 GMT</pubDate>
    <dc:creator>JWBailey</dc:creator>
    <dc:date>2014-01-14T19:07:07Z</dc:date>
    <item>
      <title>using SA-ldapsearch to search for related accounts</title>
      <link>https://community.splunk.com/t5/Security/using-SA-ldapsearch-to-search-for-related-accounts/m-p/113279#M3566</link>
      <description>&lt;P&gt;I want to set up an alert if an account is disabled in active directory, a related account exists, and is left enabled.  The relationship between the accounts is defined, for example, related accounts have the same sAMAccountName but with a number appended to the end to make them unique.  &lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;I have an account in active directory that was disabled: sAMAccountName=Sara.  I want to verify the account is still disabled, and if so, automatically check active directory to see if Sara1 or Sara(whatever) exists, and if it is still enabled.&lt;/P&gt;

&lt;P&gt;I need to verify because this search will not be running in real-time, so it is possible an account was disabled and re-enabled, and I do not want this to generate results.  &lt;/P&gt;

&lt;P&gt;I have SA-ldapsearch installed, and I can get various parts of this to work, but not all in the same search.&lt;/P&gt;

&lt;P&gt;• I can perform the basic search to return results of all accounts that were disabled.&lt;BR /&gt;&lt;BR /&gt;
• I can use ldapfilter to check attributes and verify the account is still disabled.&lt;/P&gt;

&lt;P&gt;• I have used ldapsearch separately to return attributes of existing accounts, and can use the wildcard to find all the accounts I want.  &lt;/P&gt;

&lt;P&gt;How do I put this all together?  How do I take the results of the first half of my search, and feed them into an ldapsearch command adding a wildcard?  When I try this I run into the problem that ldapsearch must be the first command of a search.  &lt;/P&gt;

&lt;P&gt;I have thought about splitting this into two searches and using a lookup file to store the results, but that seems like an awfully complex way to do this.  And I am not even sure it would work.  &lt;/P&gt;

&lt;P&gt;What other options do I have?  &lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2014 19:07:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/using-SA-ldapsearch-to-search-for-related-accounts/m-p/113279#M3566</guid>
      <dc:creator>JWBailey</dc:creator>
      <dc:date>2014-01-14T19:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: using SA-ldapsearch to search for related accounts</title>
      <link>https://community.splunk.com/t5/Security/using-SA-ldapsearch-to-search-for-related-accounts/m-p/113280#M3567</link>
      <description>&lt;P&gt;Your best bet for this is to create a lookup with the associated accounts in it.  Create a table with the account name and the associated account.  You should have a CSV file that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;src_nt_domain,src_user,assoc_user
XXX,Sara,Sara1
XXX,Sara,Sara2
XXX,Tom,Tom87
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Whatever is appropriate to your environment.  You can do this with an ldapsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|ldapsearch domain=XXX search="(&amp;amp;(objectClass=user)(!(objectclass=computer)))" attrs="sAMAccountName" | rename sAMAccountName as assoc_user | eval isAssoc=if(match(assoc_user,"\d+$"),1,0) | where isAssoc=1 | rex field=assoc_user "^(?&amp;lt;src_user&amp;gt;.*?)\d+$" | eval src_nt_domain=XXX | table src_nt_domain,src_user,assoc_user | outputlookup associated_users.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, with that lookup, you can do what you want:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=WinEventLog:Security (EventCode=629 OR EventCode=4725) | lookup associated_users src_nt_domain,src_user OUTPUT assoc_user | ldapfilter domain=$src_nt_domain$ search="(sAMAccountName=$assoc_user$)" attrs="userAccountControl" | where userAccountControl!="*DISABLE*" | stats values(assoc_user) by src_nt_domain,src_user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What you will get is a table with the domain and username of the newly-disabled user and the list of associated accounts that have not been disabled yet.&lt;/P&gt;

&lt;P&gt;(Note: search commands have not been verified independently, since I don't have your environment)&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2014 17:17:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Security/using-SA-ldapsearch-to-search-for-related-accounts/m-p/113280#M3567</guid>
      <dc:creator>ahall_splunk</dc:creator>
      <dc:date>2014-02-10T17:17:05Z</dc:date>
    </item>
  </channel>
</rss>

