File: idsv2.rb

package info (click to toggle)
ruby-packetfu 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,520 kB
  • sloc: ruby: 8,344; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 672 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env ruby
# -*- coding: binary -*-

# Usage:
# rvmsudo ruby examples/idsv2.rb

# Path setting slight of hand:
$: << File.expand_path("../../lib", __FILE__)
require 'packetfu'

iface = ARGV[0] || PacketFu::Utils.default_int

cap = PacketFu::Capture.new(:iface => iface, :start => true, :filter => "ip")

attack_patterns = ["^gotcha", "owned!*$", "^\x04[^\x00]{50}"]

loop do
  cap.stream.each do |pkt|
    packet = PacketFu::Packet.parse(pkt)
    attack_patterns.each do |sig|
      hit = packet.payload.scan(/#{sig}/i) || nil
      puts "#{Time.now}: %s attacked %s [%s]" % [packet.ip_saddr, packet.ip_daddr, sig.inspect] unless hit.size.zero?
    end
  end
end