rule "[WIN]Detect IP in URL"
when
regex"^([0-9]{1,3}\.){3}[0-9]{1,3}$", to_ip($message.url_hostname)).matches == true
then
set_field("ip_in_url","true");
end
The regx is valid. I checked it on regex101.com. However, Graylog doesn’t validate the regex.
You’re missing an opening parenthesis after the regex function name.
The regular expression also only matches if the url_hostname field contains an IPv4 address without leading or trailing characters. Is that always the case with your messages?
rule "[WIN]Detect IP in URL"
when
regex("^([0-9]{1,3}\.){3}[0-9]{1,3}$", to_ip($message.url_hostname)).matches == true
then
set_field("ip_in_url","true");
end
However, normally, url_hostname should NOT contains IPv4 address.
That’s why I try do detect with this rule when there is some ip adress instead of normal url in the hostname_url field.
Use IP and not dns resolution may be considered as suspicious.
Are there any trailing whitespace characters in the url_hostname field?
Also, your regular expression will only match the first example ( 1.2.3.4) but not the second (1.2.3.4:6666).
Additionally, I just see the to_ip function in your condition, which is wrong there. Regular expressions only work on strings, not IP addresses (the data type, not if a string contains an IP address).
No trailing whitespace characters in the url_hostname field
Yes, this is just a test, I will improve to detect 1.2.3.4:6666
I tried :
rule "[WIN]Detect IP in URL"
when
regex("^([0-9]{1,3}\.){3}[0-9]{1,3}$", to_string($message.url_hostname)).matches == true
then
set_field("ip_in_url","true");
end