Home
%3CLINGO-SUB%20id%3D%22lingo-sub-828311%22%20slang%3D%22en-US%22%3ERe%3A%20Hunting%20for%20reconnaissance%20activities%20using%20LDAP%20search%20filters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-828311%22%20slang%3D%22en-US%22%3EThis%20is%20an%20interesting%20approach%20but%20I%20have%20to%20wonder%20about%20false%20positives%20in%20larger%20organizations.%20What%20are%20you%20seeing%20as%20to%20the%20signal-to-noise%20ratio%20of%20this%20type%20of%20monitoring%20in%20practice%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-829091%22%20slang%3D%22en-US%22%3ERe%3A%20Hunting%20for%20reconnaissance%20activities%20using%20LDAP%20search%20filters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-829091%22%20slang%3D%22en-US%22%3E%3CP%3EWatching%20with%20anticipation%20for%20the%20next%20Sysmon%20update!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-824726%22%20slang%3D%22en-US%22%3EHunting%20for%20reconnaissance%20activities%20using%20LDAP%20search%20filters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-824726%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20Lightweight%20Directory%20Access%20Protocol%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fprevious-versions%2Fwindows%2Fdesktop%2Fldap%2Flightweight-directory-access-protocol-ldap-api%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3E(LDAP%3C%2FA%3E)%20protocol%20is%20heavily%20used%20by%20system%20services%20and%20apps%20for%20many%20important%20operations%20like%20querying%20for%20user%20groups%20and%20getting%20user%20information.%20It%E2%80%99s%20a%20prime%20target%20for%20Active%20Directory%20attacks%2C%20Kerberoasting%2C%20and%20other%20reconnaissance%20steps%20after%20attackers%20have%20infiltrated%20a%20network.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAttackers%20are%20known%20to%20use%20LDAP%20to%20gather%20information%20about%20users%2C%20machines%2C%20and%20the%20domain%20structure.%20Attackers%20can%20then%20take%20over%20high-privileged%20accounts%20by%20finding%20the%20shortest%20path%20to%20sensitive%20assets.%20Spotting%20these%20reconnaissance%20activities%2C%20especially%20from%20patient%20zero%20machines%2C%20is%20critical%20in%20detecting%20and%20containing%20cyberattacks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20new%20LDAP%20extension%20to%20Windows%20endpoints%20provides%20visibility%20into%20LDAP%20search%20queries.%20This%20instrumentation%20is%20captured%20by%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fwindows%2Fmicrosoft-defender-atp%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EMicrosoft%20Defender%20ATP%3C%2FA%3E%2C%20allowing%20blue%20teams%20to%20hunt%20down%20suspicious%20queries%20and%20prevent%20attacks%20in%20their%20early%20stages.%20In%20this%20blog%20we%E2%80%99ll%20demonstrate%20how%20you%20can%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fwindows%2Fsecurity%2Fthreat-protection%2Fmicrosoft-defender-atp%2Fadvanced-hunting%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eadvanced%20hunting%3C%2FA%3Ein%20Microsoft%20Defender%20ATP%20to%20investigate%20suspicious%20LDAP%20search%20queries.%3C%2FP%3E%20%26nbsp%3B%20Case%20study%3A%20Hunting%20down%20LDAP-based%20attacks%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20demonstrate%20how%20the%20new%20LDAP%20instrumentation%20works%2C%20I%20set%20up%20a%20test%20machine%20and%20installed%20the%20popular%20red-team%20tool%20BloodHoundand%20used%20SharpHoundas%20data%20collector%20tool%20to%20gather%20and%20ingest%20domain%20data.%20SharpHound%20uses%20LDAP%20queries%20to%20collect%20domain%20information%20that%20can%20used%20later%20to%20perform%20attacks%20against%20the%20organization%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EFigure%201.%20SharpHound%20is%20collecting%20domain%20objects%20from%20lmsdn.local%20domain%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMicrosoft%20Defender%20ATP%20captures%20the%20queries%20run%20by%20Sharphound%2C%20as%20well%20as%20the%20actual%20processes%20that%20were%20used.%20Using%20a%20simple%20advanced%20hunting%20query%20that%20performs%20the%20following%20steps%2C%20we%20can%20spot%20highly%20interesting%20reconnaissance%20methods%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3ESearch%20for%20LDAP%20search%20filters%20events%20(ActionType%20%3D%20LdapSearch)%20Parse%20the%20LDAP%20attributes%20and%20flatten%20them%20for%20quick%20filtering%20Use%20a%20distinguished%20name%20to%20target%20your%20searches%20on%20designated%20domains%20If%20needed%2C%20filter%20out%20prevalent%20queries%20to%20reduce%20noise%20or%20define%20specific%20filters%20Investigate%20the%20machine%20and%20its%20processes%20used%20with%20suspicious%20queries%3CP%3EHere%20are%20some%20sample%20queries%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EMiscEvents%20%7C%20where%20ActionType%20%3D%3D%20%22LdapSearch%22%20and%20EventTime%20%26gt%3B%20ago(7h)%20%7C%20project%20ComputerName%2C%20InitiatingProcessFileName%2C%20AdditionalFields%20%7C%20extend%20ldap%20%3D%20parse_json(AdditionalFields)%20%7C%20extend%20AttributeList%20%3D%20ldap.AttributeList%20%7C%20extend%20ScopeOfSearch%20%3D%20ldap.ScopeOfSearch%20%7C%20extend%20SearchFilter%20%3D%20ldap.SearchFilter%20%7C%20extend%20DistinguishName%20%3D%20ldap.DistinguishedName%20%7C%20where%20DistinguishName%20contains%20%22%5BYourDistinguishedName%5D%22%20and%20SearchFilter%20!contains%20%22objectclass%3D*%22%20%7C%20project-away%20AdditionalFields%2C%20ldapMiscEvents%20%7C%20where%20ActionType%20%3D%3D%20%22LdapSearch%22%20and%20EventTime%20%26gt%3B%20ago(7h)%20%7C%20project%20ComputerName%2C%20InitiatingProcessFileName%2C%20AdditionalFields%20%7C%20extend%20LDAP%20%3D%20parse_json(AdditionalFields)%20%7C%20extend%20AttributeList%20%3D%20LDAP.AttributeList%20%7C%20extend%20ScopeOfSearch%20%3D%20LDAP.ScopeOfSearch%20%7C%20extend%20SearchFilter%20%3D%20LDAP.SearchFilter%20%7C%20extend%20DistinguishName%20%3D%20LDAP.DistinguishedName%20%7C%20where%20AttributeList%20has%20%22admincount%22%20%7C%20where%20SearchFilter%20has%20%22user%22%20or%20SearchFilter%20has%20%22computer%22%20or%20SearchFilter%20has%20%22person%22%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EFigure%202.%20Advanced%20hunting%20showing%20example%20LDAP%20query%20results%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOne%20of%20the%20results%20that%20caught%20my%20attention%20is%20a%20generic%20LDAP%20query%20generated%20by%20sharphound.exethat%20aims%20to%20collect%20many%20different%20entities%20from%20the%20domain%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EProcess%3Asharphound.exe%3C%2FP%3E%3CP%3EDistinguishName%3ADC%3Dlmsdn%2CDC%3Dlocal%3C%2FP%3E%3CP%3EScopeOfSearch%3ASubTree%3C%2FP%3E%3CP%3EAttributeList%3A%5B%22objectsid%22%2C%22distiguishedname%22%2C%22samaccountname%22%2C%22distinguishedname%22%2C%22samaccounttype%22%2C%22member%22%2C%22cn%22%2C%22primarygroupid%22%2C%22dnshostname%22%2C%22ms-mcs-admpwdexpirationtime%22%5D%3C%2FP%3E%3CP%3ESearchFilter%3A%3C%2FP%3E%3CP%3E(%7C%3C%2FP%3E%3CP%3E(%7C(samaccounttype%3D268435456)(samaccounttype%3D268435457)(samaccounttype%3D536870912)(smaccounttype%3D536870913)(primarygroupid%3D*))%3C%2FP%3E%3CP%3E(%26amp%3B(sAMAccountType%3D805306369)(!(UserAccountControl%3A1.2.840.113556.1.4.803%3A%3D2)))%3C%2FP%3E%3CP%3E(objectclass%3Ddomain)%3C%2FP%3E%3CP%3E)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBreaking%20this%20search%20query%20into%20a%20visualized%20tree%20shows%20that%20this%20query%20gathers%20groups%2C%20enabled%20machines%2C%20users%20and%20domain%20objects%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3EOR%20OR%20samaccounttype%3D268435456%20(security%20groups)%20samaccounttype%3D268435457%20(non-security%20groups)%20samaccounttype%3D536870912%20(alias%20objects)%20samaccounttype%3D536870913%20(non-security%20alias%20objects)%20primarygroupid%3D*%20(any%20object%20with%20a%20primary%20group%20id%20including%20users%20and%20machines)%20AND%20sAMAccountType%3D805306369%20(machine%20objects)%20NOT%20UserAccountControl%3A1.2.840.113556.1.4.803%3A%3D2%20(disabled%20objects)%20objectclass%3Ddomain%20(domain%20object)%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20looking%20at%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FBloodHoundAD%2FSharpHound%2Fblob%2Fmaster%2FSharphound2%2FEnumeration%2FLdapFilter.cs%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESharpHound%20code%3C%2FA%3E%2C%20we%20can%20verify%20that%20the%20BuildLdapData%20method%20uses%20these%20filters%20and%20attributes%20to%20collect%20data%20from%20internal%20domains%2C%20and%20later%20uses%20this%20to%20build%20the%20BloodHound%20attack%20graph%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EFigure%203.%20SharpHound%20code%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20we%20can%20learn%20from%20the%20BloodHound%20example%2C%20when%20dealing%20with%20LDAP%20queries%2C%20search%20filters%20become%20an%20important%20need%20to%20specify%2C%20target%20and%20reduce%20the%20number%20of%20resulting%20domain%20entities.%20While%20BloodHound%20is%20just%20an%20example%20for%20such%20a%20case%2C%20there%20are%20many%20other%20tools%20out%20there%20that%20use%20the%20same%20method.%20Utilizing%20these%20new%20LDAP%20search%20filters%20events%20can%20help%20us%20gain%20better%20visibility%20into%20recon%20executions%20and%20detect%20suspicious%20attempts%20in%20no%20time.can%20help%20us%20gain%20better%20visibility%20into%20recon%20executions%20and%20detect%20suspicious%20attempts%20in%20no%20time!%3C%2FP%3E%20%26nbsp%3B%20Common%20suspicious%20LDAP%20search%20filters%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20Microsoft%20Defender%20ATP%20Research%20Team%20has%20compiled%20a%20list%20of%20suspicious%20search%20filter%20queries%20found%20being%20used%20in%20the%20wild%20by%20commodity%20and%20recon%20tools.%20This%20list%20provides%20insights%20and%20highlights%20interesting%20LDAP%20query%20filters%20originating%20from%20fileless%20or%20file-based%20executions%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%20%3CP%3ERecon%20tool%3C%2FP%3E%20%3CP%3EFilter%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Frapid7%2Fmetasploit-framework%2Fblob%2F76954957c740525cff2db5a60bcf936b4ee06c42%2Fmodules%2Fpost%2Fwindows%2Fgather%2Fenum_ad_user_comments.rb%23L31%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eenum_ad_user_comments%3C%2FA%3E(Metasploit)%3C%2FP%3E%20%3CP%3E(%26amp%3B(%26amp%3B(objectCategory%3Dperson)(objectClass%3Duser))(%7C(description%3D*pass*)(comment%3D*pass*)))%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Frapid7%2Fmetasploit-framework%2Fblob%2F76954957c740525cff2db5a60bcf936b4ee06c42%2Fmodules%2Fpost%2Fwindows%2Fgather%2Fenum_ad_computers.rb%23L52%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eenum_ad_computers%3C%2FA%3E(Metasploit)%3C%2FP%3E%20%3CP%3E(%26amp%3B(objectCategory%3Dcomputer)(operatingSystem%3D*server*))%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Frapid7%2Fmetasploit-framework%2Fblob%2F76954957c740525cff2db5a60bcf936b4ee06c42%2Fmodules%2Fpost%2Fwindows%2Fgather%2Fenum_ad_groups.rb%23L49%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eenum_ad_groups%3C%2FA%3E(Metasploit)%3C%2FP%3E%20%3CP%3E(%26amp%3B(objectClass%3Dgroup))%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Frapid7%2Fmetasploit-framework%2Fblob%2F76954957c740525cff2db5a60bcf936b4ee06c42%2Fmodules%2Fpost%2Fwindows%2Fgather%2Fenum_ad_managedby_groups.rb%23L53%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eenum_ad_managedby_groups%3C%2FA%3E%3C%2FP%3E%3CP%3E(Metasploit)%3C%2FP%3E%20%3CP%3E(%26amp%3B(objectClass%3Dgroup)(managedBy%3D*))%2C%3C%2FP%3E%3CP%3E(%26amp%3B(objectClass%3Dgroup)(managedBy%3D*)(groupType%3A1.2.840.113556.1.4.803%3A%3D2147483648))%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FPowerShellMafia%2FPowerSploit%2Fblob%2Fc7985c9bc31e92bb6243c177d7d1d7e68b6f1816%2FRecon%2FPowerView.ps1%23L4029%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EGet-NetComputer%3C%2FA%3E(PowerView)%3C%2FP%3E%20%3CP%3E(%26amp%3B(sAMAccountType%3D805306369)(dnshostname%3D*))%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FPowerShellMafia%2FPowerSploit%2Fblob%2Fc7985c9bc31e92bb6243c177d7d1d7e68b6f1816%2FRecon%2FPowerView.ps1%23L2602%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EGet-NetUser%3C%2FA%3E-%20Users%20(Powerview)%3C%2FP%3E%20%3CP%3E(%26amp%3B(samAccountType%3D805306368)(samAccountName%3D*)%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FPowerShellMafia%2FPowerSploit%2Fblob%2Fc7985c9bc31e92bb6243c177d7d1d7e68b6f1816%2FRecon%2FPowerView.ps1%23L2605%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EGet-NetUser%3C%2FA%3E-%20SPNs%20(Powerview)%3C%2FP%3E%20%3CP%3E(%26amp%3B(samAccountType%3D805306368)(servicePrincipalName%3D*)%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FPowerShellMafia%2FPowerSploit%2Fblob%2Fc7985c9bc31e92bb6243c177d7d1d7e68b6f1816%2FRecon%2FPowerView.ps1%23L6007%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EGet-DFSshareV2%3C%2FA%3E(Powerview)%3C%2FP%3E%20%3CP%3E(%26amp%3B(objectClass%3DmsDFS-Linkv2))%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FPowerShellMafia%2FPowerSploit%2Fblob%2Fc7985c9bc31e92bb6243c177d7d1d7e68b6f1816%2FRecon%2FPowerView.ps1%23L4747%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EGet-NetOU%3C%2FA%3E%3C%2FP%3E%3CP%3E(PowerView)%3C%2FP%3E%20%3CP%3E(%26amp%3B(objectCategory%20%3DorganizationalUnit)(name%3D*))%3C%2FP%3E%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FEmpireProject%2FEmpire%2Fblob%2F24adb55b3404e1d319b33b70f4fd6b7448ca407c%2Fdata%2Fmodule_source%2Fcredentials%2FInvoke-Kerberoast.ps1%23L57%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EGet-DomainSearcher%3C%2FA%3E(Empire)%3C%2FP%3E%20%3CP%3E(samAccountType%3D805306368)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20just%20a%20partial%20list%20of%20recon%20tools%3B%20there%20are%20many%20more%20tools%20and%20modules%20out%20there%20that%20use%20the%20same%20method%20to%20collect%20information%20LDAP%20search%20filters.%20As%20we%E2%80%99ve%20learned%20from%20the%20case%20study%2C%20with%20the%20new%20LDAP%20instrumentation%2C%20it%20becomes%20easier%20to%20find%20them%20with%20Microsoft%20Defender%20ATP.%20For%20example%2C%20one%20of%20the%20queries%20above%20found%20the%20following%20files%20gathering%20SPNs%20from%20the%20domain%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EFigure%204.%20Files%20(SHA-256%3A%20feec1457836a5f84291215a2a003fcde674e7e422df8c4ed6fe5bb3b679cdc87%2C%208d7ab0e208a39ad318b3f3837483f34e0fa1c3f20edf287fb7c8d8fa1ac63a2f)%20gathering%20SPNs%20from%20the%20domain%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3ELDAP%20hunting%20guide%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20you%20spot%20an%20interesting%20query%2C%20now%20what%3F%20We%E2%80%99re%20adding%20here%20a%20set%20of%20questions%20you%20might%20have%20during%20your%20next%20threat%20hunting%20work.%20We%E2%80%99re%20answering%20these%20questions%20based%20on%20our%20experience%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQ%3AIs%20this%20search%20filter%20generic%20(e.g.%2C%20searching%20for%20all%20servers)%3F%20Did%20you%20spot%20wildcards%3F%3C%2FP%3E%3CP%3EA%3AIn%20many%20cases%20we%E2%80%99ve%20observed%2C%20generic%20filters%20and%20wildcards%20are%20used%20to%20pull%20out%20entities%20from%20the%20domain.%20Usually%2C%20the%20filters%20were%20pointing%20to%20user%20information%2C%20machines%2C%20groups%2C%20SPNs%2C%20and%20domain%20objects.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQ%3AHow%20often%20do%20you%20see%20this%20query%3F%20Did%20it%20try%20to%20run%20on%20many%20entities%3F%20Is%20it%20unique%20to%20the%20process%20or%20the%20user%3F%3C%2FP%3E%3CP%3EA%3AAnomalies%20can%20help%20you%20understand%20how%20common%20an%20activity%20is%2C%20and%20whether%20or%20not%20it%20deviated%20from%20its%20normal%20behavior.%20Uncommon%20queries%20originating%20from%20abnormal%20users%2C%20living-off-the-land%20binaries%2C%20injected%20processes%2C%20low-prevalent%20processes%2C%20or%20even%20known%20recon%20tools%20are%20areas%20that%20might%20be%20interesting%20to%20start%20investigations%20from.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQ%3ADid%20you%20encounter%20any%20interesting%20attributes%20(e.g.%2C%20personal%20user%20data%2C%20machine%20info)%3F%3C%2FP%3E%3CP%3EA%3AAttributes%20can%20shed%20light%20on%20the%20intent%20and%20the%20type%20of%20data%20that%20is%20extracted.%20There%20is%20no%20real%20need%20to%20specify%20them%2C%20but%20in%20some%20cases%2C%20if%20appear%2C%20they%20can%20help%20understand%20what%20type%20of%20data%20was%20extracted.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQ%3AIs%20the%20scope%20of%20search%20is%20limited%20or%20multi-level%20(e.g.%2C%20subtree%20vs.%20one-level)%3F%3C%2FP%3E%3CP%3EA%3A%20In%20many%20cases%20we%E2%80%99ve%20observed%20subtree%20search%20which%20intends%20to%20look%20at%20all%20child%20and%20based%20object%20which%20basically%20reduce%20the%20number%20of%20queries%20one%20would%20need%20to%20do.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQ%3ADid%20you%20find%20any%20additional%20artifacts%20for%20malicious%20activities%3F%3C%2FP%3E%3CP%3EA%3A%20While%20queries%20might%20look%20suspicious%2C%20it%20might%20not%20be%20enough%20to%20incriminate%20a%20malicious%20activity.%3C%2FP%3E%3CP%3EAs%20true%20for%20many%20hunting%20cases%2C%20looking%20in%20additional%20activities%20could%20help%20conclude%20if%20this%20query%20was%20truly%20suspicious%20or%20not.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20these%20new%20LDAP%20search%20filter%20events%2C%20you%20can%20expand%20your%20threat%20hunting%20scenarios.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fsecurity%2Fthreat-protection%2Fmicrosoft-defender-atp%2Fadvanced-hunting%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EAdvanced%20hunting%3C%2FA%3Eis%20a%20powerful%20capability%20in%20Microsoft%20Defender%20ATP%20that%20allows%20you%20to%20hunt%20for%20possible%20threats%20across%20your%20organization.%20If%20you%20are%20not%20yet%20reaping%20the%20benefits%20of%20Microsoft%20Defender%20ATP%E2%80%99s%20%3CA%20href%3D%22https%3A%2F%2Fcloudblogs.microsoft.com%2Fmicrosoftsecure%2F2018%2F12%2F03%2Finsights-from-the-mitre-attack-based-evaluation-of-windows-defender-atp%2F%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eindustry-leading%20optics%20and%20detection%20capabilities%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fwindowsforbusiness%2Fwindows-atp%3Focid%3Dcx-blog-mmpc%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Esign%20up%20for%20free%20trial%3C%2FA%3Etoday.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBuilding%20off%20of%20Microsoft%20Defender%20ATP%E2%80%99s%20threat%20hunting%20technology%2C%20we%E2%80%99re%20adding%20the%20ability%20to%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fsecurity%2Fblog%2F2019%2F07%2F29%2Fevolution-of-microsoft-threat-protection-july-update%2F%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Ehunt%20for%20threats%20across%20endpoints%20and%20email%3C%2FA%3Ethrough%20Microsoft%20Threat%20Protection.%20To%20learn%20more%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fsecurity%2Ftechnology%2Fthreat-protection%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Evisit%20the%20%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fsecurity%2Ftechnology%2Fthreat-protection%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EMicrosoft%20Threat%20Protection%20website%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENiv%20Sela%2C%20Corina%20Feuerstein%3C%2FP%3E%3CP%3EMicrosoft%20Defender%20ATP%20Team%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-824726%22%20slang%3D%22en-US%22%3E%3CP%3EAttackers%20are%20known%20to%20use%20LDAP%20to%20gather%20information%20about%20users%2C%20machines%2C%20and%20the%20domain%20structure.%20Attackers%20can%20then%20take%20over%20high-privileged%20accounts%20by%20finding%20the%20shortest%20path%20to%20sensitive%20assets.%20Spotting%20these%20reconnaissance%20activities%2C%20especially%20from%20patient%20zero%20machines%2C%20is%20critical%20in%20detecting%20and%20containing%20cyberattacks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E

The Lightweight Directory Access Protocol (LDAP) protocol is heavily used by system services and apps for many important operations like querying for user groups and getting user information. It’s a prime target for Active Directory attacks, Kerberoasting, and other reconnaissance steps after attackers have infiltrated a network.

 

Attackers are known to use LDAP to gather information about users, machines, and the domain structure. Attackers can then take over high-privileged accounts by finding the shortest path to sensitive assets. Spotting these reconnaissance activities, especially from patient zero machines, is critical in detecting and containing cyberattacks.

 

A new LDAP extension to Windows endpoints provides visibility into LDAP search queries. This instrumentation is captured by Microsoft Defender ATP, allowing blue teams to hunt down suspicious queries and prevent attacks in their early stages. In this blog we’ll demonstrate how you can use advanced hunting in Microsoft Defender ATP to investigate suspicious LDAP search queries.

 

Case study: Hunting down LDAP-based attacks

 

To demonstrate how the new LDAP instrumentation works, I set up a test machine and installed the popular red-team tool BloodHound and used SharpHound as data collector tool to gather and ingest domain data. SharpHound uses LDAP queries to collect domain information that can used later to perform attacks against the organization:

 

LDAPBlog1.png

Figure 1. SharpHound is collecting domain objects from lmsdn.local domain

 

Microsoft Defender ATP captures the queries run by Sharphound, as well as the actual processes that were used. Using a simple advanced hunting query that performs the following steps, we can spot highly interesting reconnaissance methods:

 

  1. Search for LDAP search filters events (ActionType = LdapSearch)
  2. Parse the LDAP attributes and flatten them for quick filtering
  3. Use a distinguished name to target your searches on designated domains
  4. If needed, filter out prevalent queries to reduce noise or define specific filters
  5. Investigate the machine and its processes used with suspicious queries

Here are some sample queries:

 

 

MiscEvents | where ActionType == "LdapSearch" and EventTime > ago(7h)
| project ComputerName, InitiatingProcessFileName, AdditionalFields 
| extend ldap = parse_json(AdditionalFields)
| extend AttributeList = ldap.AttributeList
| extend ScopeOfSearch = ldap.ScopeOfSearch
| extend SearchFilter = ldap.SearchFilter
| extend DistinguishName = ldap.DistinguishedName
| where DistinguishName contains "[YourDistinguishedName]" and SearchFilter !contains "objectclass=*"
| project-away AdditionalFields, ldap
MiscEvents | where ActionType == "LdapSearch" and EventTime > ago(7h)
   | project ComputerName, InitiatingProcessFileName, AdditionalFields 
   | extend LDAP = parse_json(AdditionalFields)
   | extend AttributeList = LDAP.AttributeList
   | extend ScopeOfSearch = LDAP.ScopeOfSearch
   | extend SearchFilter = LDAP.SearchFilter
   | extend DistinguishName = LDAP.DistinguishedName
   | where AttributeList has "admincount"
   | where SearchFilter has "user" or SearchFilter has "computer" or SearchFilter has "person"

 

 

LDAPBlog2.png

Figure 2. Advanced hunting showing example LDAP query results

 

One of the results that caught my attention is a generic LDAP query generated by sharphound.exe that aims to collect many different entities from the domain:

 

Process: sharphound.exe

DistinguishName: DC=lmsdn,DC=local

ScopeOfSearch: SubTree

AttributeList: ["objectsid","distiguishedname","samaccountname","distinguishedname","samaccounttype","member","cn","primarygroupid","dnshostname","ms-mcs-admpwdexpirationtime"]

SearchFilter:

(|

(|(samaccounttype=268435456)(samaccounttype=268435457)(samaccounttype=536870912)(smaccounttype=536870913)(primarygroupid=*))

(&(sAMAccountType=805306369)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))

(objectclass=domain)

)

 

Breaking this search query into a visualized tree shows that this query gathers groups, enabled machines, users and domain objects:

 

  • OR
    • OR
      • samaccounttype=268435456 (security groups)
      • samaccounttype=268435457 (non-security groups)
      • samaccounttype=536870912 (alias objects)
      • samaccounttype=536870913 (non-security alias objects)
      • primarygroupid=* (any object with a primary group id including users and machines)
    • AND
      • sAMAccountType=805306369 (machine objects)
      • NOT
        • UserAccountControl:1.2.840.113556.1.4.803:=2 (disabled objects)
      • objectclass=domain (domain object)

 

When looking at SharpHound code, we can verify that the BuildLdapData method uses these filters and attributes to collect data from internal domains, and later uses this to build the BloodHound attack graph:

 

LDAPBlog3.png

Figure 3. SharpHound code

 

As we can learn from the BloodHound example, when dealing with LDAP queries, search filters become an important need to specify, target and reduce the number of resulting domain entities. While BloodHound is just an example for such a case, there are many other tools out there that use the same method. Utilizing these new LDAP search filters events can help us gain better visibility into recon executions and detect suspicious attempts in no time.can help us gain better visibility into recon executions and detect suspicious attempts in no time!

 

Common suspicious LDAP search filters

 

The Microsoft Defender ATP Research Team has compiled a list of suspicious search filter queries found being used in the wild by commodity and recon tools. This list provides insights and highlights interesting LDAP query filters originating from fileless or file-based executions:

 

Recon tool

Filter

enum_ad_user_comments (Metasploit)

(&(&(objectCategory=person)(objectClass=user))(|(description=*pass*)(comment=*pass*)))

enum_ad_computers (Metasploit)

(&(objectCategory=computer)(operatingSystem=*server*))

enum_ad_groups (Metasploit)

(&(objectClass=group))

enum_ad_managedby_groups

(Metasploit)

(&(objectClass=group)(managedBy=*)),

(&(objectClass=group)(managedBy=*)(groupType:1.2.840.113556.1.4.803:=2147483648))

Get-NetComputer (PowerView)

(&(sAMAccountType=805306369)(dnshostname=*))

Get-NetUser - Users (Powerview)

(&(samAccountType=805306368)(samAccountName=*)

Get-NetUser - SPNs (Powerview)

(&(samAccountType=805306368)(servicePrincipalName=*)

Get-DFSshareV2 (Powerview)

(&(objectClass=msDFS-Linkv2))

Get-NetOU

(PowerView)

(&(objectCategory =organizationalUnit)(name=*))

Get-DomainSearcher (Empire)

(samAccountType=805306368)

 

This is just a partial list of recon tools; there are many more tools and modules out there that use the same method to collect information LDAP search filters. As we’ve learned from the case study, with the new LDAP instrumentation, it becomes easier to find them with Microsoft Defender ATP. For example, one of the queries above found the following files gathering SPNs from the domain:

 

LDAPBlog4.png

Figure 4. Files (SHA-256: feec1457836a5f84291215a2a003fcde674e7e422df8c4ed6fe5bb3b679cdc87, 8d7ab0e208a39ad318b3f3837483f34e0fa1c3f20edf287fb7c8d8fa1ac63a2f) gathering SPNs from the domain

 

LDAP hunting guide

 

So you spot an interesting query, now what? We’re adding here a set of questions you might have during your next threat hunting work. We’re answering these questions based on our experience:

 

Q: Is this search filter generic (e.g., searching for all servers)? Did you spot wildcards?

A: In many cases we’ve observed, generic filters and wildcards are used to pull out entities from the domain. Usually, the filters were pointing to user information, machines, groups, SPNs, and domain objects.

 

Q: How often do you see this query? Did it try to run on many entities? Is it unique to the process or the user?

A: Anomalies can help you understand how common an activity is, and whether or not it deviated from its normal behavior. Uncommon queries originating from abnormal users, living-off-the-land binaries, injected processes, low-prevalent processes, or even known recon tools are areas that might be interesting to start investigations from.

 

Q: Did you encounter any interesting attributes (e.g., personal user data, machine info)?

A: Attributes can shed light on the intent and the type of data that is extracted. There is no real need to specify them, but in some cases, if appear, they can help understand what type of data was extracted.

 

Q: Is the scope of search is limited or multi-level (e.g., subtree vs. one-level)?

A: In many cases we’ve observed subtree search which intends to look at all child and based object which basically reduce the number of queries one would need to do.

 

Q: Did you find any additional artifacts for malicious activities?

A: While queries might look suspicious, it might not be enough to incriminate a malicious activity.

As true for many hunting cases, looking in additional activities could help conclude if this query was truly suspicious or not.

 

With these new LDAP search filter events, you can expand your threat hunting scenarios. Advanced hunting is a powerful capability in Microsoft Defender ATP that allows you to hunt for possible threats across your organization. If you are not yet reaping the benefits of Microsoft Defender ATP’s industry-leading optics and detection capabilities, sign up for free trial today.

 

Building off of Microsoft Defender ATP’s threat hunting technology, we’re adding the ability to hunt for threats across endpoints and email through Microsoft Threat Protection. To learn more, visit the Microsoft Threat Protection website.

 

 

Niv Sela, Corina Feuerstein

Microsoft Defender ATP Team

 

2 Comments
Occasional Visitor
This is an interesting approach but I have to wonder about false positives in larger organizations. What are you seeing as to the signal-to-noise ratio of this type of monitoring in practice?
Occasional Visitor

Watching with anticipation for the next Sysmon update!