Last active
August 5, 2023 10:00
-
-
Save picatz/855b4afe458e6ddb12f2acaec29dc058 to your computer and use it in GitHub Desktop.
Simple intrusion detection system engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "packetgen" | |
class IDS | |
def initialize(interface: PacketGen.default_iface, &block) | |
@rules = {} | |
instance_eval &block | |
PacketGen.capture(iface: interface) do |packet| | |
@rules.each do |header, blocks| | |
next unless packet.is? header | |
blocks.each do |block| | |
block.call(packet) | |
end | |
end | |
end | |
end | |
def rule(header, &block) | |
if @rules[header] | |
@rules[header] << block | |
else | |
@rules[header] = [block] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment