Hello all.
Graylog 4.3.13.
I write simple pipeline to exctract mac addresses from messages like this “An ip address conflict is detected. 00:00:00:00:00:01 and 00:00:00:00:00:00 share the same IP address 10.0.0.1”
Log get from Syslog UPD input.
Pipeline:
rule "Zywall find arp message with macs"
when
contains(to_string($message.message), "An ip address conflict is detected", true)
then
let ip_arp = to_string($message.zw_arp_ip);
let mac = regex("(([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}))", to_string($message.message));
let mac1 = to_string(mac["0"]);
let mac2 = to_string(mac["1"]);
set_field("action", "arp attack");
set_field("mac1", mac1);
set_field("mac2", mac2);
set_field("ts_hour", $message.timestamp.hourOfDay);
set_field("ts_minute", $message.timestamp.minuteOfHour);
set_field("ts_second", $message.timestamp.secondOfMinute);
let ts = to_string($message.timestamp);
set_field("ts", ts);
end
let test = to_string(regex("(([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}))", to_string($message.message)));
set_field("test", test);
i got test field {0=00:00:00:00:00:01, 1=00:, 2=01}. Array has not 2nd mac, only 3 members:
1 mac, 5th & 6th group of 1 mac address.
Can anybody help me with this?
In this situation it find only 1 mac
let test = to_string(regex(“(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})”, to_string($message.message)));
let ip_arp = to_string($message.zw_arp_ip);
let mac = regex(“(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})”, to_string($message.message));
Added fields
mac1
00:00:00:00:00:01
test
{0=00:00:00:00:00:01}
In pipilene 2 symbols of \ , i don why forum change 2 \ symbols for 1 \ symbol
Same situation with regex (.{2}:.{2}:.{2}:.{2}:.{2}:.{2})
@gsmith
Yes, i escaped them, and it didn’t help.
What do you mean “full pipe”?
If you mean all pipeline, that its empty, only 1 stage with 1 rule from 1st message.
rule "Between 6 AM and 6 PM"
when
( to_long(to_date($message.timestamp, "American/Chicago").hourOfDay) >= 0 AND to_long(to_date($message.timestamp, "American/Chicago").hourOfDay) <= 6 ) OR
( to_long(to_date($message.timestamp, "American/Chicago").hourOfDay) >= 18 AND to_long(to_date($message.timestamp, "American/Chicago").hourOfDay) <= 0 )
then
set_field("trigger_workhours_off", true);
end
rule "Zywall find arp message with macs"
when
contains(to_string($message.message), "An ip address conflict is detected", true)
then
//let test = to_string(regex("(([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}))", to_string($message.message)));
//let test = to_string(regex("(\\w{2}:\\w{2}:\\w{2}:\\w{2}:\\w{2}:\\w{2})", to_string($message.message)));
let test = to_string(regex("(.{2}:.{2}:.{2}:.{2}:.{2}:.{2})", to_string($message.message)));
set_field("test", test);
let ip_arp = to_string($message.zw_arp_ip);
let mac = regex("(([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}))", to_string($message.message));
let mac1 = to_string(mac["0"]);
let mac2 = to_string(mac["1"]);
let new_message = concat("ARP on ip ", ip_arp);
let new_message = concat(new_message, "
mac 1st device - ");
let new_message = concat(new_message, mac1);
let new_message = concat(new_message, "
mac 2nd device - ");
let new_message = concat(new_message, mac2);
let new_message = concat(new_message, "
Need find problem device");
set_field("message", new_message);
set_field("action", "arp attack");
set_field("ts_hour", $message.timestamp.hourOfDay);
set_field("ts_minute", $message.timestamp.minuteOfHour);
set_field("ts_second", $message.timestamp.secondOfMinute);
let ts = to_string($message.timestamp);
set_field("ts", ts);
set_field("mac1", mac1);
set_field("mac2", mac2);
end
rule "Extract multiple fields"
when
has_field("message")
then
let mac = regex("(\\w{2}:\\w{2}:\\w{2}:\\w{2}:\\w{2}:\\w{2})", to_string($message.message));
set_field ("mac1",mac["0"]);
set_field ("mac2",mac["1"]);
end
My results were the same, I would need to test more later, or perhaps someone else here would know a better way of executing this.