pcaprub_helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24f0791508cb1079b631f67eba8609ed7a82a2b1
4
+ data.tar.gz: eea6ae08badb9663907dba96ff021b4e56f8d5de
5
+ SHA512:
6
+ metadata.gz: 46d133364eaa869be71446d2e0bb8be4dba5e34d72aef304c910e38d89603f01db2a414528c10992415e68bf2cc5f26022f40cce371b420d9d885c175f31c9a0
7
+ data.tar.gz: 9f3f985cb2c72e5ea3e8323c022608efbf9afdd19e32179880993919daadde63509df24d6cc2573fe397374de6741ab75eea0719573b69ba3e452df3340cea14
@@ -0,0 +1,21 @@
1
+ # History
2
+ ## Released Versions
3
+ ### Version 0.0.1
4
+ #### Patch: Inital code
5
+ ##### Added
6
+ - Travis Yml
7
+ - History(this file)
8
+ - Rakefile
9
+ - Gemspec
10
+ - Gemfile
11
+ - Inital code
12
+ - PcaprubHelper module
13
+ - PcaprubHelper::DSL module
14
+ - PcaprubHelper version constants
15
+ - Inital tests
16
+ - Helper
17
+ - PcaprubHelper spec
18
+
19
+ ##### Updated
20
+ - Readme
21
+ - Git ignore
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Ben Slaughter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,17 @@
1
+ pcaprub_helper
2
+ ==============
3
+
4
+ [![Code Climate](https://codeclimate.com/github/benSlaughter/pcaprub_helper/badges/gpa.svg)](https://codeclimate.com/github/benSlaughter/pcaprub_helper)
5
+ [![Build Status](https://travis-ci.org/benSlaughter/pcaprub_helper.svg?branch=master)](https://travis-ci.org/benSlaughter/pcaprub_helper)
6
+ [![Dependency Status](https://gemnasium.com/benSlaughter/pcaprub_helper.svg)](https://gemnasium.com/benSlaughter/pcaprub_helper)
7
+ [![Test Coverage](https://codeclimate.com/github/benSlaughter/pcaprub_helper/badges/coverage.svg)](https://codeclimate.com/github/benSlaughter/pcaprub_helper)
8
+ [![Coverage Status](https://img.shields.io/coveralls/benSlaughter/pcaprub_helper.svg)](https://coveralls.io/r/benSlaughter/pcaprub_helper)
9
+
10
+ Helper methods built on top of pcaprub
11
+
12
+ ## Installation
13
+
14
+ Gem install pcaprub_helper
15
+
16
+ ## Helpful docs
17
+ [Help with creating filters](http://www.tcpdump.org/manpages/pcap-filter.7.html)
@@ -0,0 +1,95 @@
1
+ require 'pcaprub'
2
+ require 'uri'
3
+
4
+ # helper module for pcaprub
5
+ module PcaprubHelper
6
+ class << self
7
+ attr_reader :cap, :last_cap
8
+ attr_accessor :interface, :snaplen, :promisc, :timeout
9
+ attr_accessor :filter, :url_filter
10
+
11
+ def configure
12
+ yield self
13
+ end
14
+
15
+ def capture_this
16
+ build_capture
17
+ yield
18
+ @last_cap = parse_capture
19
+ destroy_capture
20
+ end
21
+
22
+ def verify_query_string(**kwargs)
23
+ return false unless @last_cap
24
+
25
+ @last_cap.each do |packet|
26
+ kwargs.each do |key, value|
27
+ return false unless packet =~ query_string_validator(key, value)
28
+ end
29
+ end
30
+
31
+ true
32
+ end
33
+
34
+ def verify_path_string(*args)
35
+ return false unless @last_cap
36
+
37
+ @last_cap.each do |packet|
38
+ args.each do |value|
39
+ return false unless packet =~ path_string_validator(value)
40
+ end
41
+ end
42
+
43
+ true
44
+ end
45
+
46
+ def look_up_device
47
+ PCAPRUB::Pcap.lookupdev
48
+ rescue PCAPRUB::BindingError
49
+ puts "lookupdev : no suitable device found, defaulting to 'en0'"
50
+ 'en0'
51
+ end
52
+
53
+ private
54
+
55
+ def query_string_validator(key, value)
56
+ /(\&|\?)#{key}[\[\]]{0,2}=#{value}(\&|\s)/i
57
+ end
58
+
59
+ def path_string_validator(value)
60
+ %r{\/#{value}\/i}
61
+ end
62
+
63
+ def build_capture
64
+ @cap = PCAPRUB::Pcap.open_live(@interface, @snaplen, @promisc, @timeout)
65
+ @cap.setfilter(@filter || '')
66
+ end
67
+
68
+ def destroy_capture
69
+ @cap.close
70
+ @cap = nil
71
+ end
72
+
73
+ def parse_capture
74
+ packets = []
75
+ loop do
76
+ packet = @cap.next
77
+ break unless packet
78
+ next unless filter(packet)
79
+ packets << URI.decode(packet)
80
+ end
81
+ packets
82
+ end
83
+
84
+ def filter(packet)
85
+ @url_filter ? packet =~ @url_filter : true
86
+ end
87
+ end
88
+ end
89
+
90
+ PcaprubHelper.configure do |config|
91
+ config.interface = config.look_up_device
92
+ config.snaplen = 65_535
93
+ config.promisc = true
94
+ config.timeout = 0
95
+ end
@@ -0,0 +1,19 @@
1
+ require 'pcaprub_helper'
2
+
3
+ # helper module for pcaprub
4
+ module PcaprubHelper
5
+ # DSL module can be included for Pcaprub helper
6
+ module DSL
7
+ def capture_this(&block)
8
+ PcaprubHelper.capture_this(&block)
9
+ end
10
+
11
+ def verify_query_string(**kwargs)
12
+ PcaprubHelper.verify_query_string(kwargs)
13
+ end
14
+
15
+ def verify_path_string(*args)
16
+ PcaprubHelper.verify_path_string(args)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # helper module for pcaprub
2
+ module PcaprubHelper
3
+ VERSION = '0.0.1'
4
+ DATE = '2014-10-21'
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'codeclimate-test-reporter'
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ CodeClimate::TestReporter.start
5
+
6
+ require 'pcaprub_helper/dsl'
7
+
8
+ RSpec.configure do |config|
9
+ config.color = true
10
+ config.formatter = :documentation
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ describe PcaprubHelper do
4
+ it 'is a module' do
5
+ expect(PcaprubHelper).to be_a Module
6
+ end
7
+
8
+ describe PcaprubHelper::DSL do
9
+ it 'is a module' do
10
+ expect(PcaprubHelper::DSL).to be_a Module
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pcaprub_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Slaughter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pcaprub
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.11'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ description: Helper methods for pcaprub making life easy.
112
+ email: b.p.slaughter@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - History.md
118
+ - LICENSE
119
+ - README.md
120
+ - lib/pcaprub_helper.rb
121
+ - lib/pcaprub_helper/dsl.rb
122
+ - lib/pcaprub_helper/version.rb
123
+ - spec/helper.rb
124
+ - spec/pcaprub_helper_spec.rb
125
+ homepage: http://benslaughter.github.io/pcaprub_helper/
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.2.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A group of helper methods for pcaprub
149
+ test_files:
150
+ - spec/helper.rb
151
+ - spec/pcaprub_helper_spec.rb
152
+ has_rdoc: