iptables 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +3 -0
- data/README.md +17 -0
- data/bin/iptables-decode +18 -0
- data/iptables.gemspec +21 -0
- data/lib/iptables.rb +327 -0
- data/sample_data/complex-iptables-135 +219 -0
- data/sample_data/complex-iptables-147 +270 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/iptables/decoder/basic_spec.rb +7 -0
- data/spec/unit/iptables/decoder/rule_spec.rb +151 -0
- data/spec/unit/iptables/decoder/shellsplit_spec.rb +27 -0
- data/spec/unit/iptables/decoder/switch_hash_spec.rb +131 -0
- metadata +112 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Iptables::Decoder#switch_hash' do
|
4
|
+
context 'default iptables compatibility' do
|
5
|
+
subject do
|
6
|
+
Iptables::Decoder.new
|
7
|
+
end
|
8
|
+
|
9
|
+
tests = [
|
10
|
+
{:name => "basic 1",
|
11
|
+
:input => ["-A", "OUTPUT", "-s", "1.1.1.2/32", "-j", "CLASSIFY", "--set-class", "0004:0056"],
|
12
|
+
:output => [
|
13
|
+
{:values=>["OUTPUT"], :switch=>"A"},
|
14
|
+
{:values=>["1.1.1.2/32"], :switch=>"s"},
|
15
|
+
{:values=>["CLASSIFY"], :switch=>"j"},
|
16
|
+
{:values=>["0004:0056"], :switch=>"set-class"}]},
|
17
|
+
{:name => "negate 1",
|
18
|
+
:input => ["-A", "OUTPUT", "!", "-o", "eth0"],
|
19
|
+
:output => [
|
20
|
+
{:values=>["OUTPUT"], :switch=>"A"},
|
21
|
+
{:negate=>true, :values=>["eth0"], :switch=>"o"}]},
|
22
|
+
{:name => "multivalues 1",
|
23
|
+
:input => ["-A", "INPUT", "-s", "1.1.1.1/32", "-p", "tcp", "-m", "tcp", "!", "--tcp-flags", "FIN,SYN,RST,ACK", "SYN"],
|
24
|
+
:output => [
|
25
|
+
{:values=>["INPUT"], :switch=>"A"},
|
26
|
+
{:values=>["1.1.1.1/32"], :switch=>"s"},
|
27
|
+
{:values=>["tcp"], :switch=>"p"},
|
28
|
+
{:values=>["tcp"], :switch=>"m"},
|
29
|
+
{:negate=>true, :values=>["FIN,SYN,RST,ACK", "SYN"], :switch=>"tcp-flags"}]},
|
30
|
+
{:name => "complex 1",
|
31
|
+
:input => ["-A", "INPUT", "-p", "ah", "-m", "ah", "!", "--ahspi", "1", "-m", "connmark", "--mark", "0x3/0x1", "-m", "ah", "--ahspi", "3", "-m", "connmark", "!", "--mark", "0x18/0x1"],
|
32
|
+
:output => [
|
33
|
+
{:values=>["INPUT"], :switch=>"A"},
|
34
|
+
{:values=>["ah"], :switch=>"p"},
|
35
|
+
{:values=>["ah"], :switch=>"m"},
|
36
|
+
{:negate=>true, :values=>["1"], :switch=>"ahspi"},
|
37
|
+
{:values=>["connmark"], :switch=>"m"},
|
38
|
+
{:values=>["0x3/0x1"], :switch=>"mark"},
|
39
|
+
{:values=>["ah"], :switch=>"m"},
|
40
|
+
{:values=>["3"], :switch=>"ahspi"},
|
41
|
+
{:values=>["connmark"], :switch=>"m"},
|
42
|
+
{:negate=>true, :values=>["0x18/0x1"], :switch=>"mark"}]},
|
43
|
+
{:name => "complex 2",
|
44
|
+
:input => ["-A", "INPUT", "-s", "1.1.1.1/32", "-m", "connbytes", "!", "--connbytes", "10:1000", "--connbytes-mode", "packets", "--connbytes-dir", "both"],
|
45
|
+
:output => [
|
46
|
+
{:values=>["INPUT"], :switch=>"A"},
|
47
|
+
{:values=>["1.1.1.1/32"], :switch=>"s"},
|
48
|
+
{:values=>["connbytes"], :switch=>"m"},
|
49
|
+
{:negate=>true, :values=>["10:1000"], :switch=>"connbytes"},
|
50
|
+
{:values=>["packets"], :switch=>"connbytes-mode"},
|
51
|
+
{:values=>["both"], :switch=>"connbytes-dir"}]},
|
52
|
+
{:name => "space args 1",
|
53
|
+
:input => ["-A", "INPUT", "-p", "tcp", "-m", "comment", "--comment", "000 foo", "-j", "ACCEPT"],
|
54
|
+
:output => [
|
55
|
+
{:values=>["INPUT"], :switch=>"A"},
|
56
|
+
{:values=>["tcp"], :switch=>"p"},
|
57
|
+
{:values=>["comment"], :switch=>"m"},
|
58
|
+
{:values=>["000 foo"], :switch=>"comment"},
|
59
|
+
{:values=>["ACCEPT"], :switch=>"j"}]},
|
60
|
+
]
|
61
|
+
tests.each do |t|
|
62
|
+
it "run sample test [#{t[:name]}]" do
|
63
|
+
subject.switch_hash(t[:input]).should eq t[:output]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context '1.3.5 iptables compatibility' do
|
69
|
+
subject do
|
70
|
+
Iptables::Decoder.new(:iptables_compatibility => '1.3.5')
|
71
|
+
end
|
72
|
+
|
73
|
+
tests = [
|
74
|
+
{:name => "basic 1",
|
75
|
+
:input => ["-A", "OUTPUT", "-s", "1.1.1.2/32", "-j", "CLASSIFY", "--set-class", "0004:0056"],
|
76
|
+
:output => [
|
77
|
+
{:values=>["OUTPUT"], :switch=>"A"},
|
78
|
+
{:values=>["1.1.1.2/32"], :switch=>"s"},
|
79
|
+
{:values=>["CLASSIFY"], :switch=>"j"},
|
80
|
+
{:values=>["0004:0056"], :switch=>"set-class"}]},
|
81
|
+
{:name => "negate 1",
|
82
|
+
:input => ["-A", "OUTPUT", "-o", "!", "eth0"],
|
83
|
+
:output => [
|
84
|
+
{:values=>["OUTPUT"], :switch=>"A"},
|
85
|
+
{:negate=>true, :values=>["eth0"], :switch=>"o"}]},
|
86
|
+
{:name => "multivalues 1",
|
87
|
+
:input => ["-A", "INPUT", "-s", "1.1.1.1/32", "-p", "tcp", "-m", "tcp", "!", "--tcp-flags", "FIN,SYN,RST,ACK", "SYN"],
|
88
|
+
:output => [
|
89
|
+
{:values=>["INPUT"], :switch=>"A"},
|
90
|
+
{:values=>["1.1.1.1/32"], :switch=>"s"},
|
91
|
+
{:values=>["tcp"], :switch=>"p"},
|
92
|
+
{:values=>["tcp"], :switch=>"m"},
|
93
|
+
{:negate=>true, :values=>["FIN,SYN,RST,ACK", "SYN"], :switch=>"tcp-flags"}]},
|
94
|
+
{:name => "complex 1",
|
95
|
+
:input => ["-A", "INPUT", "-p", "ah", "-m", "ah", "!", "--ahspi", "1", "-m", "connmark", "--mark", "0x3/0x1", "-m", "ah", "--ahspi", "3", "-m", "connmark", "!", "--mark", "0x18/0x1"],
|
96
|
+
:output => [
|
97
|
+
{:values=>["INPUT"], :switch=>"A"},
|
98
|
+
{:values=>["ah"], :switch=>"p"},
|
99
|
+
{:values=>["ah"], :switch=>"m"},
|
100
|
+
{:negate=>true, :values=>["1"], :switch=>"ahspi"},
|
101
|
+
{:values=>["connmark"], :switch=>"m"},
|
102
|
+
{:values=>["0x3/0x1"], :switch=>"mark"},
|
103
|
+
{:values=>["ah"], :switch=>"m"},
|
104
|
+
{:values=>["3"], :switch=>"ahspi"},
|
105
|
+
{:values=>["connmark"], :switch=>"m"},
|
106
|
+
{:negate=>true, :values=>["0x18/0x1"], :switch=>"mark"}]},
|
107
|
+
{:name => "complex 2",
|
108
|
+
:input => ["-A", "INPUT", "-s", "1.1.1.1/32", "-m", "connbytes", "!", "--connbytes", "10:1000", "--connbytes-mode", "packets", "--connbytes-dir", "both"],
|
109
|
+
:output => [
|
110
|
+
{:values=>["INPUT"], :switch=>"A"},
|
111
|
+
{:values=>["1.1.1.1/32"], :switch=>"s"},
|
112
|
+
{:values=>["connbytes"], :switch=>"m"},
|
113
|
+
{:negate=>true, :values=>["10:1000"], :switch=>"connbytes"},
|
114
|
+
{:values=>["packets"], :switch=>"connbytes-mode"},
|
115
|
+
{:values=>["both"], :switch=>"connbytes-dir"}]},
|
116
|
+
{:name => "space args 1",
|
117
|
+
:input => ["-A", "INPUT", "-p", "tcp", "-m", "comment", "--comment", "000 foo", "-j", "ACCEPT"],
|
118
|
+
:output => [
|
119
|
+
{:values=>["INPUT"], :switch=>"A"},
|
120
|
+
{:values=>["tcp"], :switch=>"p"},
|
121
|
+
{:values=>["comment"], :switch=>"m"},
|
122
|
+
{:values=>["000 foo"], :switch=>"comment"},
|
123
|
+
{:values=>["ACCEPT"], :switch=>"j"}]},
|
124
|
+
]
|
125
|
+
tests.each do |t|
|
126
|
+
it "run sample test [#{t[:name]}]" do
|
127
|
+
subject.switch_hash(t[:input]).should eq t[:output]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iptables
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ken Barber
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-03-20 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description:
|
49
|
+
email:
|
50
|
+
- ken@bob.sh
|
51
|
+
executables:
|
52
|
+
- iptables-decode
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- .ruby-version
|
60
|
+
- .travis.yml
|
61
|
+
- Gemfile
|
62
|
+
- README.md
|
63
|
+
- bin/iptables-decode
|
64
|
+
- iptables.gemspec
|
65
|
+
- lib/iptables.rb
|
66
|
+
- sample_data/complex-iptables-135
|
67
|
+
- sample_data/complex-iptables-147
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/unit/iptables/decoder/basic_spec.rb
|
70
|
+
- spec/unit/iptables/decoder/rule_spec.rb
|
71
|
+
- spec/unit/iptables/decoder/shellsplit_spec.rb
|
72
|
+
- spec/unit/iptables/decoder/switch_hash_spec.rb
|
73
|
+
homepage: https://github.com/kbarber/ruby-iptables
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 57
|
87
|
+
segments:
|
88
|
+
- 1
|
89
|
+
- 8
|
90
|
+
- 7
|
91
|
+
version: 1.8.7
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.24
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: iptables-save encoder/decoder
|
108
|
+
test_files:
|
109
|
+
- spec/unit/iptables/decoder/basic_spec.rb
|
110
|
+
- spec/unit/iptables/decoder/rule_spec.rb
|
111
|
+
- spec/unit/iptables/decoder/shellsplit_spec.rb
|
112
|
+
- spec/unit/iptables/decoder/switch_hash_spec.rb
|