Skip to content

Instantly share code, notes, and snippets.

@picatz
Last active August 5, 2023 10:00
Show Gist options
  • Save picatz/855b4afe458e6ddb12f2acaec29dc058 to your computer and use it in GitHub Desktop.
Save picatz/855b4afe458e6ddb12f2acaec29dc058 to your computer and use it in GitHub Desktop.
Simple intrusion detection system engine
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