pcap2json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e605ad6187e64706737b8b4986ca84e64b5b14b82446f56636650bb6791f8b94
4
+ data.tar.gz: bcfcb3fd42583db53e266d51698f14749bb88482965f2765b8d5d40a9c439876
5
+ SHA512:
6
+ metadata.gz: abfc42a276b3bd7649daeef878c8f07ba71e9d3926022c1691ca81148087dca640fd3491d2d097c51fe3ba12b2cf0c43aa20cbbac1dd09906a24a405d4849bdf
7
+ data.tar.gz: 74acbb3be14387ee73ced083b3f51e698591044eefefa2f1d07b8f1679ef588b085d0c566769de8c1512bf9fdd823dc4ae376cdac14486b334456dcecc8f6a8a
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rspec_status
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kgruber1@emich.edu. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pcap2json.gemspec
6
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pcap2json (0.1.0)
5
+ oj (~> 3.7.11)
6
+ packetgen (~> 3.1.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ interfacez (1.0.3)
14
+ method_source (0.9.2)
15
+ oj (3.7.11)
16
+ packetgen (3.1.2)
17
+ interfacez (~> 1.0)
18
+ pcaprub (~> 0.12.4)
19
+ rasn1 (~> 0.5, >= 0.6.6)
20
+ pcaprub (0.12.4)
21
+ pry (0.12.2)
22
+ coderay (~> 1.1.0)
23
+ method_source (~> 0.9.0)
24
+ rake (10.5.0)
25
+ rasn1 (0.6.8)
26
+ rspec (3.8.0)
27
+ rspec-core (~> 3.8.0)
28
+ rspec-expectations (~> 3.8.0)
29
+ rspec-mocks (~> 3.8.0)
30
+ rspec-core (3.8.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-expectations (3.8.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-mocks (3.8.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-support (3.8.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.17)
45
+ pcap2json!
46
+ pry (~> 0.12.2)
47
+ rake (~> 10.0)
48
+ rspec (~> 3.8.0)
49
+
50
+ BUNDLED WITH
51
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Kent 'picat' Gruber
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # pcap2json
2
+
3
+ Command-linee application to convert packets into json.
4
+
5
+ ## Installation
6
+
7
+ ```console
8
+ $ gem install pcap2json
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```console
14
+ $ pcap2json file test.pcapng
15
+ ```
16
+
17
+ ```console
18
+ $ pcap2json interface eth0
19
+ ```
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/picatx/pcap2json. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
24
+
25
+ ## License
26
+
27
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
28
+
29
+ ## Code of Conduct
30
+
31
+ Everyone interacting in the Pcap2json project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/picatz/pcap2json/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pcap2json"
4
+ require "command_lion"
5
+
6
+ Signal.trap("INT") { abort }
7
+
8
+ CommandLion::App.run do
9
+
10
+ name "pcap2json"
11
+ version Pcap2JSON::VERSION
12
+
13
+ command :file do
14
+ description "Read a pcap/pcapng file as JSON and print to STDOUT"
15
+
16
+ type :string
17
+
18
+ action do
19
+ Pcap2JSON.from_file(argument) do |packet_json|
20
+ puts packet_json
21
+ return
22
+ end
23
+ end
24
+ end
25
+
26
+ command :interface do
27
+ description "Read packets from a given interface as JSON and print to STDOUT"
28
+
29
+ type :string
30
+
31
+ action do
32
+ argument = PacketGen.default_iface if argument.nil?
33
+ Pcap2JSON.from_interface(argument) do |packet_json|
34
+ puts packet_json
35
+ end
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,24 @@
1
+ require "packetgen"
2
+ require "oj"
3
+ require "pcap2json/version"
4
+ require "pcap2json/packetgen_extensions"
5
+
6
+ module Pcap2JSON
7
+ def self.from_file(filename)
8
+ PacketGen::PcapNG::File.new.read_packets(filename) do |packet|
9
+ yield packet.to_json
10
+ end
11
+ rescue StandardError => e
12
+ raise ArgumentError, e unless File.extname(filename.downcase) == '.pcap'
13
+ PCAPRUB::Pcap.open_offline(filename).each_packet do |packet|
14
+ next unless (packet = PacketGen.parse(packet.to_s))
15
+ yield packet.to_json
16
+ end
17
+ end
18
+
19
+ def self.from_interface(interface, **options)
20
+ PacketGen.capture(iface: interface, **options) do |packet|
21
+ yield packet.to_json
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,165 @@
1
+ require "pry"
2
+
3
+ class PacketGen::Packet
4
+ def to_h
5
+ data = Hash.new
6
+ data["time"] = Time.now.to_i
7
+ self.headers.each do |header|
8
+ data[header.protocol_name.downcase] = header.to_h
9
+ rescue # => error
10
+ header.fields.reject { |field| field == :body }.each do |field|
11
+ data[field.to_s] = header.send(field)
12
+ end
13
+ end
14
+ unless self.body.nil?
15
+ data["payload"] = self.body.to_s.encode(Encoding.find('UTF-8'), {invalid: :replace, undef: :replace, replace: ''})
16
+ end
17
+ data
18
+ end
19
+
20
+ def to_json
21
+ Oj.dump(self.to_h)
22
+ end
23
+ end
24
+
25
+ class PacketGen::Header::DHCP
26
+ def to_h
27
+ data = Hash.new
28
+
29
+ data["magic"] = self.magic
30
+
31
+ data["options"] = []
32
+
33
+ self.options.each do |option|
34
+ data["options"] << option.to_human
35
+ end
36
+
37
+ data
38
+ end
39
+ end
40
+
41
+ class PacketGen::Header::BOOTP
42
+ def to_h
43
+ {
44
+ "op" => self.op,
45
+ "htype" => self.htype,
46
+ "hlen" => self.hlen,
47
+ "xid" => self.xid,
48
+ "secs" => self.secs,
49
+ "flags" => self.flags,
50
+ "ciaddr" => self.ciaddr,
51
+ "yiaddr" => self.yiaddr,
52
+ "siaddr" => self.siaddr,
53
+ "giaddr" => self.giaddr,
54
+ "chaddr" => self.chaddr,
55
+ "sname" => self.sname,
56
+ "file" => self.file,
57
+ }
58
+ end
59
+
60
+ end
61
+
62
+ class PacketGen::Header::DNS
63
+ def to_h
64
+ data = Hash.new
65
+ data["id"] = self.id
66
+ #data[:flags] = self.flags
67
+ data["opcode"] = self.opcode
68
+ data["rcode"] = self.rcode
69
+ data["qdcount"] = self.qdcount
70
+ data["ancount"] = self.ancount
71
+ data["nscount"] = self.nscount
72
+ data["arcount"] = self.arcount
73
+ data["qd"] = []
74
+ data["an"] = []
75
+ data["ns"] = []
76
+ data["ar"] = []
77
+ self.qd.to_a.each do |qd|
78
+ data["qd"] << qd.to_human
79
+ end
80
+ self.an.to_a.each do |an|
81
+ data["an"] << an.to_human
82
+ end
83
+ self.ns.to_a.each do |ns|
84
+ data["ns"] << ns.to_human
85
+ end
86
+ self.ar.to_a.each do |ar|
87
+ data["ar"] << ar.to_human
88
+ end
89
+ data
90
+ end
91
+ end
92
+
93
+ class PacketGen::Header::Eth
94
+ def to_h
95
+ {
96
+ "dst" => self.dst,
97
+ "src" => self.src,
98
+ "ethertype" => self.ethertype
99
+ }
100
+ end
101
+ end
102
+
103
+ class PacketGen::Header::IP
104
+ def to_h
105
+ {
106
+ "u8" => self.u8,
107
+ "version" => self.version,
108
+ "ihl" => self.ihl,
109
+ "tos" => self.tos,
110
+ "length" => self.length,
111
+ "frag" => self.frag,
112
+ # flags => self.flags,
113
+ # frag_offset => self.frag_offset,
114
+ "ttl" => self.ttl,
115
+ "protocol" => self.protocol,
116
+ "checksum" => self.checksum,
117
+ "src" => self.src,
118
+ "dst" => self.dst
119
+ }
120
+ end
121
+ end
122
+
123
+ class PacketGen::Header::TCP
124
+ def to_h
125
+ {
126
+ "sport" => self.sport,
127
+ "dport" => self.dport,
128
+ "seqnum" => self.seqnum,
129
+ "acknum" => self.acknum,
130
+ "u16" => self.u16,
131
+ "data_offset" => self.data_offset,
132
+ "reserved" => self.reserved,
133
+ "flags" => self.flags,
134
+ "window" => self.window,
135
+ "checksum" => self.checksum,
136
+ "urg_pointer" => self.urg_pointer,
137
+ # options => self.options
138
+ }
139
+ end
140
+ end
141
+
142
+ class PacketGen::Header::UDP
143
+ def to_h
144
+ {
145
+ "sport" => self.sport,
146
+ "dport" => self.dport,
147
+ "length" => self.length,
148
+ "checksum" => self.checksum
149
+ }
150
+ end
151
+ end
152
+
153
+ class PacketGen::Header::ARP
154
+ def to_h
155
+ {
156
+ "hrd" => self.hrd,
157
+ "pro" => self.pro,
158
+ "hln" => self.hln,
159
+ "op" => self.op,
160
+ "sha" => self.sha,
161
+ "tha" => self.tha,
162
+ "tpa" => self.tpa
163
+ }
164
+ end
165
+ end
@@ -0,0 +1,3 @@
1
+ module Pcap2JSON
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pcap2json/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pcap2json"
8
+ spec.version = Pcap2JSON::VERSION
9
+ spec.authors = ["Kent 'picat' Gruber"]
10
+ spec.email = ["kgruber1@emich.edu"]
11
+
12
+ spec.summary = %q{Convert packets to json from a file or a live network interface.}
13
+ #spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/picatz/pcap2json"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "packetgen", "~> 3.1.2"
25
+ spec.add_dependency "oj", "~> 3.7.11"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.17"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.8.0"
30
+ spec.add_development_dependency "pry", "~> 0.12.2"
31
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pcap2json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kent 'picat' Gruber
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: packetgen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.7.11
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.7.11
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.8.0
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.12.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.12.2
97
+ description:
98
+ email:
99
+ - kgruber1@emich.edu
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/pcap2json
112
+ - lib/pcap2json.rb
113
+ - lib/pcap2json/packetgen_extensions.rb
114
+ - lib/pcap2json/version.rb
115
+ - pcap2json.gemspec
116
+ homepage: https://github.com/picatz/pcap2json
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 3.0.0.beta1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Convert packets to json from a file or a live network interface.
140
+ test_files: []