Splunk Search

Best approach for using a sub-search to compare time frames

trevorQmulos
New Member

I am looking for the most efficient way to do a sub search to see if vulnerabilities still exist now vs 90 days.

Currently I do a search from 90 days back and spit that file to a csv and then do a lookup and pass those to the search but want to automate this process instead of constantly updating a lookup file. I have listed the base search below.

index=network sourcetype=nessus severity!=informational 
|  dedup signature_id, dest_dns  ]
|  dedup signature_id, dest_dns 
| eval hostnamesplit=split(dest_dns,".") 
| eval hostnamesplit=mvindex(hostnamesplit,0)
| lookup AssetTag.csv Asset as hostnamesplit OUTPUT BusinessUnit1 System1
| eval Combo=mvzip(BusinessUnit1, System1) 
| fields - System1, BusinessUnit1  
| mvexpand Combo 
| makemv Combo delim="," 
| eval BU1=mvindex(Combo,0) 
| eval Sys1=mvindex(Combo,1) 
| fields - Combo
| dedup hostnamesplit signature_id BU1 Sys1
| table BU1 signature Sys1 dest_dns severity 
|  rename  Sys1 AS "System", signature AS "Signature", BU1 AS "Business Unit",dest_dns as "Host" severity as "Severity"
0 Karma
1 Solution

sundareshr
Legend

Try this

index=network sourcetype=nessus severity!=informational (earliest=-90d@d latest=-90d@d+1d) OR (earliest=@d) 
 |  dedup signature_id, dest_dns  ]
 |  dedup signature_id, dest_dns 
 | eval hostnamesplit=split(dest_dns,".") 
 | eval hostnamesplit=mvindex(hostnamesplit,0)
 | lookup AssetTag.csv Asset as hostnamesplit OUTPUT BusinessUnit1 System1
 | eval Combo=mvzip(BusinessUnit1, System1) 
 | fields - System1, BusinessUnit1  
 | mvexpand Combo 
 | makemv Combo delim="," 
 | eval BU1=mvindex(Combo,0) 
 | eval Sys1=mvindex(Combo,1) 
 | fields - Combo
 | dedup hostnamesplit signature_id BU1 Sys1
 | eval month=strftime(_time, "%b")
 | eval x=BU1."^".signature."^".Sys1."^".dest_dns."^".severity
 | chart count over x by month
 | fields - count
 | rex field=x (?<BU1>[^\^]+)\^(?<signature>[^\^]+)\^(?<Sys1>[^\^]+)\^(?<dest_dns>[^\^]+)\^(?<severity>[^\^]+)
 |  rename  Sys1 AS "System", signature AS "Signature", BU1 AS "Business Unit",dest_dns as "Host" severity as "Severity"

View solution in original post

sundareshr
Legend

Try this

index=network sourcetype=nessus severity!=informational (earliest=-90d@d latest=-90d@d+1d) OR (earliest=@d) 
 |  dedup signature_id, dest_dns  ]
 |  dedup signature_id, dest_dns 
 | eval hostnamesplit=split(dest_dns,".") 
 | eval hostnamesplit=mvindex(hostnamesplit,0)
 | lookup AssetTag.csv Asset as hostnamesplit OUTPUT BusinessUnit1 System1
 | eval Combo=mvzip(BusinessUnit1, System1) 
 | fields - System1, BusinessUnit1  
 | mvexpand Combo 
 | makemv Combo delim="," 
 | eval BU1=mvindex(Combo,0) 
 | eval Sys1=mvindex(Combo,1) 
 | fields - Combo
 | dedup hostnamesplit signature_id BU1 Sys1
 | eval month=strftime(_time, "%b")
 | eval x=BU1."^".signature."^".Sys1."^".dest_dns."^".severity
 | chart count over x by month
 | fields - count
 | rex field=x (?<BU1>[^\^]+)\^(?<signature>[^\^]+)\^(?<Sys1>[^\^]+)\^(?<dest_dns>[^\^]+)\^(?<severity>[^\^]+)
 |  rename  Sys1 AS "System", signature AS "Signature", BU1 AS "Business Unit",dest_dns as "Host" severity as "Severity"

sundareshr
Legend

Try this change to your query

You now have

| chart count over x by month
| fields - count

Change this to

| stats values(month) as months by x
| where mvcount(months)=2
| fields - months
0 Karma

trevorQmulos
New Member

Was able to get it working perfectly. Thanks again for all of your help sundareshr.

0 Karma

trevorQmulos
New Member

I get under the statistics, no results found when I made the selected changes.

 index=network sourcetype=nessus severity!=informational (earliest=-120d@d latest=-90d@d+1d) OR (latest=-30d@d earliest=@d) dest_dns=hqw0prd1rebs61.ent.pbgc.gov
  | dedup signature_id, dest_dns  
  | eval hostnamesplit=split(dest_dns,".") 
  | eval hostnamesplit=mvindex(hostnamesplit,0)
  | lookup AssetTag.csv Asset as hostnamesplit OUTPUT BusinessUnit1 System1
  | eval Combo=mvzip(BusinessUnit1, System1) 
  | fields - System1, BusinessUnit1  
  | mvexpand Combo 
  | makemv Combo delim="," 
  | eval BU1=mvindex(Combo,0) 
  | eval Sys1=mvindex(Combo,1) 
  | fields - Combo  
  | dedup hostnamesplit signature_id BU1 Sys1 | eval x=BU1."^".signature."^".Sys1."^".dest_dns."^".severity   | rex field=x "(?<BU1>[^\^]+)\^(?<signature>[^\^]+)\^(?<Sys1>[^\^]+)\^(?<dest_dns>[^\^]+)\^(?<severity>[^\^]+)"   
 | stats values(month) as months by x
 | where mvcount(months)=2
 | fields - months
 |  rename  Sys1 AS "System", signature AS "Signature", BU1 AS "Business Unit",dest_dns as "Host" severity as "Severity"

Is what my query is as of now.

0 Karma

sundareshr
Legend

Yes, you can use that timeframe.

0 Karma

trevorQmulos
New Member

Error in 'SearchParser': Missing a search command before '^'. Error at position '791'

I also had a rogue ] in the search

0 Karma

sundareshr
Legend

Missing quotes in the rex command. Make this change

... | rex field=x "(?<BU1>[^\^]+)\^(?<signature>[^\^]+)\^(?<Sys1>[^\^]+)\^(?<dest_dns>[^\^]+)\^(?<severity>[^\^]+)" | ...
0 Karma

trevorQmulos
New Member

Does this compare the two time frames in the initial search? So basically this should return anything that was found today that also was found 90 days ago.

0 Karma

sundareshr
Legend

That's correct.

0 Karma

trevorQmulos
New Member

Say that our scan results are dumped in over periods of time so not just one month. Am I able to do something like this

 index=network sourcetype=nessus severity!=informational dest_dns=hqw0prd1rebs61.ent.pbgc.gov (earliest=-120d@d latest=-90d@d+1d) OR (earliest=-30d@d latest=@d)   

Sorry for the late response, revisiting this subject and running into a few issues.

0 Karma

trevorQmulos
New Member

I have also noticed that its not making sure that events were found in both time ranges. For instance, It's displaying results that were found in June but if I do a separate search, that signature doesn't show up in the past 30 days. Any other suggestions on how to resolve the issue?

0 Karma

gfuente
Motivator

Hello

You could use the outputlookup command to automate the refresh of the lookup. Schedule this query at midnight everyday, for the past 90 days:

"your base query that list all the vulnerabilities" | outputlookup AssetTag.csv 

Then, the rest of the logic of your query will continue beign valid

Regards

0 Karma

trevorr2004
Engager

The AssetTag.csv is how I map systems to Business Units. Nothing is kept track inside that csv about scanned vulnerabilities. Basically I just want to take a search from today and check to see if they still existed 90 days ago to track how effective our patching currently is.

0 Karma

gfuente
Motivator

Ok, my mistake. But the solution is the same. Schedule the 90 days vulnerabilities query and dump the results to a lookup, and then in your actual search use the lookup to perform the comparison. It will be much better than running a 90 days subsearch everytime you need to run the main search

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...