Splunk Search

How to prepend a value to a field at search-time to sanitize malicious URLs?

JSkier
Communicator

I'd like to sanitize host names during search time in Splunk (IDS alerts), so users don't receive a hyperlink to the bad sites and the alerts don't get snagged by the mail filter. I'd like to keep the inline table results of the alerts for mobile users and general convenience.

For example, www.badsite.com is automatically hyperlinked in e-mail clients, so I'd like to prepend hxxp:// to the field so the sent alert message doesn't get hyperlink or dropped. By specifying a bogus protocol both fat mail client and mail scanner will pass the inline table without issue.

I found something about appending in the community, but that just shows a blank field during search for me (even when I assign httphostname without a period).

eval http.hostname=http.hostname."hxxp://" |

In theory, I'd like this to prepend and actually work:

eval http.hostname="hxxp://".http.hostname |

I'm using Splunk 6.3.2 in a clustered Linux environment, any help is appreciated.

0 Karma
1 Solution

woodcock
Esteemed Legend

Assuming that you have a field called http.hostname then like this:

... | eval "http.hostname" = "hxxp://" . $http.hostname$

Or possibly this:

... | rex field="http.hostname" mode=sed "s/^http:/hxxp:/"

View solution in original post

woodcock
Esteemed Legend

Assuming that you have a field called http.hostname then like this:

... | eval "http.hostname" = "hxxp://" . $http.hostname$

Or possibly this:

... | rex field="http.hostname" mode=sed "s/^http:/hxxp:/"

JSkier
Communicator

This worked perfectly, thanks!
... | eval "http.hostname" = "hxxp://" . $http.hostname$

0 Karma

sundareshr
Legend

Try putting your field name with single quotes. Like this

| eval http.hostname="hxxp://".`http.hostname`
0 Karma

JSkier
Communicator
Error in 'SearchParser': The name 'http.hostname' is invalid. Macro and argument names may only include alphanumerics, '_' and '-'. 
0 Karma
Get Updates on the Splunk Community!

Observability | How to Think About Instrumentation Overhead (White Paper)

Novice observability practitioners are often overly obsessed with performance. They might approach ...

Cloud Platform | Get Resiliency in the Cloud Event (Register Now!)

IDC Report: Enterprises Gain Higher Efficiency and Resiliency With Migration to Cloud  Today many enterprises ...

The Great Resilience Quest: 10th Leaderboard Update

The tenth leaderboard update (11.23-12.05) for The Great Resilience Quest is out >> As our brave ...