redhound 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +9 -0
- data/lib/redhound/command.rb +2 -1
- data/lib/redhound/header/ether.rb +0 -1
- data/lib/redhound/receiver.rb +11 -3
- data/lib/redhound/version.rb +1 -1
- data/lib/redhound/writer.rb +46 -0
- data/lib/redhound.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f9c914cea67f4e0f32f6dcf84149039eb95f1f2311bd6f410641b67b81d441f
|
4
|
+
data.tar.gz: ac1012da2b103d27bb43d98ca273567efc44fa4995de92af315370f73a899dc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c26cd6fea83dcbd1f60e2615a8070f60ccb036f506f9a46c77d0f935a57027ddf19d7f408271dccc8a31cc3d9624b6e6db62b252bd9b6393de858819a2855c9
|
7
|
+
data.tar.gz: 4ce4cf820846e2e652bfa33a16d08ca942eb1739d0f29a04a18389fb6d992b9ab4b13504de5d5684ab67f753bc02cc94a1c9cd702dcc922b95b2de5a7a9983a8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -20,11 +20,20 @@ gem install redhound
|
|
20
20
|
## Usage
|
21
21
|
|
22
22
|
```command
|
23
|
+
___ ____ __
|
24
|
+
/ _ \___ ___/ / / ___ __ _____ ___/ /
|
25
|
+
/ , _/ -_) _ / _ \/ _ \/ // / _ \/ _ /
|
26
|
+
/_/|_|\__/\_,_/_//_/\___/\_,_/_//_/\_,_/
|
27
|
+
|
28
|
+
Version: 0.1.0
|
29
|
+
Dump and analyze network packets.
|
30
|
+
|
23
31
|
Usage: redhound [options] ...
|
24
32
|
|
25
33
|
Options:
|
26
34
|
-i, --interface INTERFACE name or idx of interface
|
27
35
|
-D, --list-interfaces print list of interfaces and exit
|
36
|
+
-w FILE write packets to a pcap capture file format to file
|
28
37
|
-h, --help display this help and exit
|
29
38
|
-v, --version display version information and exit
|
30
39
|
```
|
data/lib/redhound/command.rb
CHANGED
@@ -15,7 +15,7 @@ module Redhound
|
|
15
15
|
warn 'Error: interface is required'
|
16
16
|
exit 1
|
17
17
|
end
|
18
|
-
Receiver.run(ifname: @options[:ifname])
|
18
|
+
Receiver.run(ifname: @options[:ifname], filename: @options[:filename])
|
19
19
|
end
|
20
20
|
|
21
21
|
def parse(argv)
|
@@ -39,6 +39,7 @@ module Redhound
|
|
39
39
|
list_interfaces
|
40
40
|
exit
|
41
41
|
end
|
42
|
+
o.on('-w FILE', 'write packets to a pcap capture file format to file') { |v| @options[:filename] = v }
|
42
43
|
o.on('-h', '--help', 'display this help and exit') do
|
43
44
|
puts o
|
44
45
|
exit
|
data/lib/redhound/receiver.rb
CHANGED
@@ -5,20 +5,28 @@ require 'socket'
|
|
5
5
|
module Redhound
|
6
6
|
class Receiver
|
7
7
|
class << self
|
8
|
-
def run(ifname:)
|
9
|
-
new(ifname:).run
|
8
|
+
def run(ifname:, filename:)
|
9
|
+
new(ifname:, filename:).run
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(ifname:)
|
13
|
+
def initialize(ifname:, filename:)
|
14
14
|
@ifname = ifname
|
15
15
|
@socket = SocketBuilder.build(ifname:)
|
16
|
+
if filename
|
17
|
+
@writer = Writer.new(filename:)
|
18
|
+
@writer.start
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def run
|
19
23
|
loop do
|
20
24
|
msg, = @socket.recvfrom(2048)
|
21
25
|
Analyzer.analyze(msg:)
|
26
|
+
@writer.write(msg) if @writer
|
27
|
+
rescue Interrupt
|
28
|
+
@writer.stop if @writer
|
29
|
+
break
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
data/lib/redhound/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Redhound
|
4
|
+
class Writer
|
5
|
+
def initialize(filename:)
|
6
|
+
@filename = filename
|
7
|
+
end
|
8
|
+
|
9
|
+
def start
|
10
|
+
@file = File.open(@filename, 'wb')
|
11
|
+
@file.write(file_header)
|
12
|
+
end
|
13
|
+
|
14
|
+
def write(msg)
|
15
|
+
@file.write(packet_record(Time.now, msg.bytesize, msg.bytesize))
|
16
|
+
@file.write(msg)
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop
|
20
|
+
@file.close
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def file_header
|
26
|
+
[
|
27
|
+
0xa1b2c3d4, # Magic Number (little-endian)
|
28
|
+
2, # Version Major
|
29
|
+
4, # Version Minor
|
30
|
+
0, # Timezone offset (GMT)
|
31
|
+
0, # Timestamp accuracy
|
32
|
+
65535, # Snapshot length
|
33
|
+
1 # Link-layer header type (Ethernet)
|
34
|
+
].pack('VvvVVVV')
|
35
|
+
end
|
36
|
+
|
37
|
+
def packet_record(timestamp, captured_length, original_length)
|
38
|
+
[
|
39
|
+
timestamp.to_i, # Timestamp seconds
|
40
|
+
(timestamp.usec || 0), # Timestamp microseconds
|
41
|
+
captured_length, # Captured packet length
|
42
|
+
original_length # Original packet length
|
43
|
+
].pack('VVVV')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/redhound.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redhound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yudai Takada
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: Redhound is a pure Ruby packet analyzer that can be used to capture and
|
13
13
|
analyze network packets.
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/redhound/receiver.rb
|
39
39
|
- lib/redhound/socket_builder.rb
|
40
40
|
- lib/redhound/version.rb
|
41
|
+
- lib/redhound/writer.rb
|
41
42
|
- sig/redhound.rbs
|
42
43
|
homepage: https://github.com/ydah/redhound
|
43
44
|
licenses:
|
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
- !ruby/object:Gem::Version
|
64
65
|
version: '0'
|
65
66
|
requirements: []
|
66
|
-
rubygems_version: 3.6.
|
67
|
+
rubygems_version: 3.6.2
|
67
68
|
specification_version: 4
|
68
69
|
summary: Pure Ruby packet analyzer
|
69
70
|
test_files: []
|