Module: Capra

Defined in:
lib/capra.rb,
lib/capra/engine.rb,
lib/capra/version.rb,
lib/capra/private_ips.rb,
lib/capra/snort_rule_parser.rb

Defined Under Namespace

Modules: SnortRuleParser Classes: Engine, Error

Constant Summary collapse

VERSION =
"1.0.0"
PRIVATE_IPS =
[
  IPAddr.new('10.0.0.0/8'),
  IPAddr.new('172.16.0.0/12'),
  IPAddr.new('192.168.0.0/16'),
].freeze

Class Method Summary collapse

Class Method Details

.run_cli!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/capra.rb', line 17

def self.run_cli!
  CommandLion::App.run do
    name "Capra"
    version Capra::VERSION
    description "Intrusion Detection System"

    command :init do
      description "create a base Caprafile in the current working directory"

      action do
        if File.exists?("Caprafile")
          puts "error: Caprafile already exists!"
          exit 1
        end
        File.open("Caprafile", 'w') do |file| 
          file.puts '#!/usr/bin/env ruby'
          file.puts
          file.puts "interface '#{Interfacez.default}'"
          file.puts
          file.puts "# your rules go here"
        end
      end
    end

    command :start do
      description "start the engine"

      default "Caprafile"

      action do
        unless File.exists?(argument)
          puts "error: cannot find #{argument} in the current directory"
          puts
          puts "hint: run `capra init` to create a base Caprafile"
          exit 1
        end

        Capra::Engine.new(file: argument)
      end
    end

    # $ capra convert 'alert tcp any any -> any 21 (msg:"ftp")'
    # rule 'TCP' do |packet|
    #   next unless packet.tcp.dport == 21
    #   alert "ftp"
    # end
    command :convert do
      description "Convert Snort rule(s) to Caprafile syntax"

      type :string

      action do
        if File.file?(argument)
          File.foreach(argument) do |line|
            line = line.strip
            next if line.empty?

            Capra::SnortRuleParser.convert(line)
          end
        else
          Capra::SnortRuleParser.convert(argument)
        end
      end
    end
  end
end