LoFP LoFP / when a gpo is manually edited and 5136 events are not logging to splunk.

Techniques

Sample rules

Windows AD Suspicious GPO Modification

Description

This analytic looks for a the creation of potentially harmful GPO which could lead to persistence or code execution on remote hosts. Note, this analyic is looking for the absence of the corresponding 5136 events which is evidence of the GPOs being manually edited (using a tool like PowerView) or potentially missing logs.

Detection logic

`wineventlog_security` EventCode=5145 ShareName="\\\\*\\SYSVOL" RelativeTargetName IN (*\\ScheduledTasks.xml, *\\Groups.xml, *\\Registry.xml, *\\Services.xml, *\\Scripts\\*) NOT RelativeTargetName=*\\Scripts\\scripts.ini AccessMask=0x2  
| rex field=AccessList max_match=0 "(?P<AccessList>%%\d+)"  
| table _time AccessMask src_ip src_user RelativeTargetName Logon_ID dvc  
| rex field=RelativeTargetName "Policies\\\(?P<gpo_guid>{.*?})\\\(?P<scope>\w+?)\\\(\w+)\\\(?P<folder>\w+)\\\(?P<file>\w+\.\w+)$" 
| eval src=if(match(src_ip, "(?i)^fe80:"),dvc,src_ip), folder=case(RelativeTargetName like "%\\Scripts\\%","Scripts",folder="Groups","Local users and groups",1=1,folder) 
| appendpipe 
  [
| map search="search `wineventlog_security` EventCode=5136 ObjectClass=groupPolicyContainer AttributeLDAPDisplayName=gPCMachineExtensionNames $gpo_guid$" 
  
| stats min(_time) as _time values(eval(if(OperationType=="%%14675",AttributeValue,null))) as old_value values(eval(if(OperationType=="%%14674",AttributeValue,null))) as new_value values(OperationType) as OperationType by ObjectClass ObjectDN OpCorrelationID src_user SubjectLogonId 
  
| rex field=old_value max_match=10000 "(?P<old_values>\{.*?\})" 
  
| rex field=new_value max_match=10000 "(?P<new_values>\{.*?\})" 
  
| rex field=ObjectDN max_match=10000 "CN=(?P<policy_guid>\{.*?\})" 
  
| mvexpand new_values 
  
| where NOT new_values IN (old_values,"{00000000-0000-0000-0000-000000000000}",policy_guid) AND match(new_values, "^\{[A-Z
|\d]+\-[A-Z
|\d]+\-[A-Z
|\d]+\-[A-Z
|\d]+\-[A-Z
|\d]+\}") 
  
| lookup msad_guid_lookup guid as new_values OUTPUTNEW displayName as policyType 
  
| eval newPolicy=if(policyType like "%",policyType,new_values) 
  
| stats values(OpCorrelationID) as OpCorrelationID values(newPolicy) as newPolicy by ObjectDN 
  
| rex field=ObjectDN max_match=10000 "CN=(?P<gpo_guid>\{.*?\})" 
  
| fields - ObjectDN] 

| stats values(AccessMask) as AccessMask values(src) as src values(src_user) as src_user values(RelativeTargetName) as RelativeTargetName values(Logon_ID) as Logon_ID values(newPolicy) as newPolicy values(OpCorrelationID) as OpCorrelationID values(folder) as folder values(file) as file by gpo_guid  
| mvexpand folder  
| where NOT folder IN (newPolicy) 
| `windows_ad_suspicious_gpo_modification_filter`