In the Splunk GUI, you can select and enable multiple searches. However, what if you want to enable only a set of searches that match specific conditions?. There’s no built-in way to do this yet, but we can use a Splunk query and a python script using the API to accomplish the task.
Query for the searches you want to enableWe can use a rest query in Splunk to look for searches to enable. For example, if you want to find all ESCU searches for Windows that use the process datamodel:
Copy to Clipboard| rest splunk_server=local /servicesNS/-/-/configs/conf-savedsearches | where match(title, "ESCU") AND match(search, "(?i)datamodel=Endpoint.Processes") AND match(search, "dest") AND !match(description, "^WARNING") AND !match(title, "Linux") AND !match(title, "MacOS")| search action.risk=1 disabled=1| table title eai:acl.app disabled action.escu.analytic_story description searchThis query
Once you confirm this search contains all the searches you would like to enable, we can…
Output the results to JSONThis will allow us to input the search results into a Python script.
Append the following to the previous search:
Copy to Clipboard| stats values(title) as searches by eai:acl.app | rename eai:acl.app as app | tojson output_field=search_group| stats values(search_group) as search_groups| eval search_groups="[".mvjoin(search_groups, ",")."]"This additional logic
Copy to Clipboardimport requests# IP or hostnamehost = "127.0.0.1"# Usually 8089mgmt_port = "8089"# Get the value of the splunkd_* cookie after authenticating to Splunk webauth_cookie = ""search_groups = headers = {'Authorization': f'Splunk {auth_cookie}'}for search_group in search_groups: for search in search_group['searches']: url = f"https://{host}:{mgmt_port}/servicesNS/nobody/{search_group['app']}/saved/searches/{search}/enable" response = requests.request("POST", url, headers=headers, verify=False) if response.status_code == 200: print(f"Successfully enabled {search}.") else: print(f"Failed to enable {search}. Response code: {response.status_code}")Before running
Once all the variables are correctly set, run the script. It will take some time to run depending on the number of searches because it’s one API call per search at a time, but it’s much faster than manually going through and clicking enable.
This method is useful when bulk enabling rules for use in RBA, correlation rules, or to just see what alert volume looks like for a large set of rules. From here, if you’re trying to get actionable alerting from a large set of alerts at once, I recommended using correlation rules such as Active Directory Privilege Escalation Identified. Rules like this look at the risk index for multiple rules from the same analytic story triggering from the same host. To tune further, you can identify which rules are involved in the correlation rule most often. Adding exclusions if you can, or disabling the rule if there is no consistent benign activity triggering the rule.
The post Splunk Tutorial: How To Bulk Enable Splunk Searches appeared first on Hurricane Labs.