pstream 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/pstream +45 -8
- data/lib/pstream.rb +50 -13
- data/lib/pstream/error.rb +2 -0
- data/lib/pstream/error/protocol_not_supported.rb +5 -0
- data/lib/pstream/error/stream_not_found.rb +5 -0
- data/lib/pstream/stream.rb +4 -4
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db60008303d60fa05efe50c9481ad9218c69f7f2
|
4
|
+
data.tar.gz: 7eb962f4c41ee92d12b2ae00d68e783d92ba8954
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c364b4931a5f687ef496e1705101ecad13097aa7c8dc5e490e45cfdee15fac03290034db6ff0992f38399245ff2b08d7a938f521de5e30cfbd05328a581d97
|
7
|
+
data.tar.gz: 371ed0e85b84eb5ce2c66c3e0b5a594055c6a08e092146c9fdb75fec6a7e1f83f9c2a4f5c38920aeeb2758c4c74e2d3d2e98de79f395e9cadbf9fa782f8ae9cf
|
data/bin/pstream
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require "colorize"
|
4
|
+
require "io/wait"
|
3
5
|
require "optparse"
|
4
6
|
require "pstream"
|
5
7
|
require "string"
|
@@ -18,6 +20,7 @@ def parse(args)
|
|
18
20
|
options["ciphers"] = false
|
19
21
|
options["prot"] = "tcp"
|
20
22
|
options["stream"] = nil
|
23
|
+
options["verbose"] = false
|
21
24
|
|
22
25
|
info = "Analyze pcap files. Can view tcp/udp streams or " \
|
23
26
|
"ciphersuites in use."
|
@@ -46,6 +49,14 @@ def parse(args)
|
|
46
49
|
options["prot"] = "udp"
|
47
50
|
end
|
48
51
|
|
52
|
+
opts.on(
|
53
|
+
"-v",
|
54
|
+
"--verbose",
|
55
|
+
"Show backtrace when error occurs"
|
56
|
+
) do
|
57
|
+
options["verbose"] = true
|
58
|
+
end
|
59
|
+
|
49
60
|
opts.on("", info.word_wrap)
|
50
61
|
end
|
51
62
|
|
@@ -80,19 +91,45 @@ begin
|
|
80
91
|
pstream = PStream.new(options["pcap"])
|
81
92
|
|
82
93
|
if (options["stream"])
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
puts pstream.udp_streams[options["stream"]].contents
|
88
|
-
end
|
94
|
+
puts pstream.get_stream(
|
95
|
+
options["stream"].to_i,
|
96
|
+
options["prot"]
|
97
|
+
).contents
|
89
98
|
elsif (options["ciphers"])
|
90
99
|
puts pstream.ciphers
|
91
100
|
else
|
92
|
-
puts pstream.
|
101
|
+
puts pstream.to_s
|
93
102
|
end
|
94
103
|
rescue PStream::Error => e
|
95
|
-
puts e.message
|
104
|
+
$stderr.puts e.message.red
|
105
|
+
if (options["verbose"])
|
106
|
+
e.backtrace.each do |line|
|
107
|
+
$stderr.puts line.yellow
|
108
|
+
end
|
109
|
+
end
|
110
|
+
exit PStreamExit::EXCEPTION
|
111
|
+
rescue Interrupt
|
112
|
+
# ^C
|
113
|
+
# Exit gracefully
|
114
|
+
rescue Errno::EPIPE
|
115
|
+
# Do nothing. This can happen if piping to another program such as
|
116
|
+
# less. Usually if less is closed before PStream is done with
|
117
|
+
# STDOUT.
|
118
|
+
rescue Exception => e
|
119
|
+
$stderr.puts "Oops! Looks like an error has occured! If the " \
|
120
|
+
"error persists, file a bug at:"
|
121
|
+
$stderr.puts
|
122
|
+
$stderr.puts " https://gitlab.com/mjwhitta/pstream/issues"
|
123
|
+
$stderr.puts
|
124
|
+
$stderr.puts "Maybe the message below will help. If not, you " \
|
125
|
+
"can use the --verbose flag to get a backtrace.".word_wrap
|
126
|
+
|
127
|
+
$stderr.puts e.message.red
|
128
|
+
if (options["verbose"])
|
129
|
+
e.backtrace.each do |line|
|
130
|
+
$stderr.puts line.yellow
|
131
|
+
end
|
132
|
+
end
|
96
133
|
exit PStreamExit::EXCEPTION
|
97
134
|
end
|
98
135
|
exit PStreamExit::GOOD
|
data/lib/pstream.rb
CHANGED
@@ -2,24 +2,56 @@ require "pathname"
|
|
2
2
|
require "scoobydoo"
|
3
3
|
|
4
4
|
class PStream
|
5
|
-
|
6
|
-
|
5
|
+
attr_reader :tcp_streams
|
6
|
+
attr_reader :udp_streams
|
7
7
|
|
8
8
|
def ciphers
|
9
9
|
# List ciphers during ssl handshake
|
10
10
|
out = %x(
|
11
|
-
tshark -r #{@pcap} -Y ssl.handshake.ciphersuite -V
|
12
|
-
|
11
|
+
tshark -r #{@pcap} -Y ssl.handshake.ciphersuite -V 2>&1 \
|
12
|
+
| \grep -E "Internet Protocol|Hostname:|Cipher Suite"
|
13
13
|
)
|
14
14
|
return out
|
15
15
|
end
|
16
16
|
|
17
|
+
def get_stream(stream, prot = "tcp")
|
18
|
+
case prot
|
19
|
+
when "tcp"
|
20
|
+
if (@tcp_streams.empty? && !@udp_streams.empty?)
|
21
|
+
return get_stream(stream, "udp")
|
22
|
+
end
|
23
|
+
if (stream >= @tcp_streams.length)
|
24
|
+
raise PStream::Error::StreamNotFound.new(stream, prot)
|
25
|
+
else
|
26
|
+
return @tcp_streams[stream]
|
27
|
+
end
|
28
|
+
when "udp"
|
29
|
+
if (@udp_streams.empty? && !@tcp_streams.empty?)
|
30
|
+
return get_stream(stream, "udp")
|
31
|
+
end
|
32
|
+
if (stream >= @udp_streams.length)
|
33
|
+
raise PStream::Error::StreamNotFound.new(stream, prot)
|
34
|
+
else
|
35
|
+
return @udp_streams[stream]
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise PStream::Error::ProtocolNotSupported.new(prot)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
17
42
|
def get_streams(prot)
|
43
|
+
case prot
|
44
|
+
when "tcp", "udp"
|
45
|
+
# Do nothing
|
46
|
+
else
|
47
|
+
raise PStream::Error::ProtocolNotSupported.new(prot)
|
48
|
+
end
|
49
|
+
|
18
50
|
streams = Array.new
|
19
51
|
|
20
52
|
out = %x(
|
21
|
-
tshark -r #{@pcap} -z conv,#{prot} | \grep -E "<->"
|
22
|
-
awk '{print $1, $2, $3, "|", $8, "Frames"}'
|
53
|
+
tshark -r #{@pcap} -z conv,#{prot} 2>&1 | \grep -E "<->" \
|
54
|
+
| awk '{print $1, $2, $3, "|", $8, "Frames"}'
|
23
55
|
)
|
24
56
|
|
25
57
|
count = 0
|
@@ -54,6 +86,16 @@ class PStream
|
|
54
86
|
@udp_streams = get_streams("udp")
|
55
87
|
end
|
56
88
|
|
89
|
+
def negotiated_ciphers
|
90
|
+
f = "ssl.handshake.ciphersuite && ssl.handshake.type == 2"
|
91
|
+
out = %x(
|
92
|
+
tshark -r #{@pcap} -Y "#{f}" -V 2>&1 | \
|
93
|
+
\grep -E "Cipher Suite:" | \
|
94
|
+
sed -r "s|^ +Cipher Suite: ||g" | sort -u
|
95
|
+
)
|
96
|
+
return out.split("\n")
|
97
|
+
end
|
98
|
+
|
57
99
|
def summary
|
58
100
|
ret = Array.new
|
59
101
|
|
@@ -77,16 +119,11 @@ class PStream
|
|
77
119
|
|
78
120
|
# List ciphers that were actually selected
|
79
121
|
ret.push("Ciphers in use:")
|
80
|
-
|
81
|
-
out = %x(
|
82
|
-
tshark -r #{@pcap} -Y "#{f}" -V | \
|
83
|
-
\grep -E "Cipher Suite:" | \
|
84
|
-
sed -r "s|^ +Cipher Suite: ||g" | sort -u
|
85
|
-
)
|
86
|
-
ret.concat(out.split("\n"))
|
122
|
+
ret.concat(negotiated_ciphers)
|
87
123
|
|
88
124
|
return ret.join("\n")
|
89
125
|
end
|
126
|
+
private :summary
|
90
127
|
|
91
128
|
def to_s
|
92
129
|
return summary
|
data/lib/pstream/error.rb
CHANGED
data/lib/pstream/stream.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class PStream::Stream
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
attr_reader :desc
|
3
|
+
attr_reader :frames
|
4
|
+
attr_reader :id
|
5
5
|
|
6
6
|
def contents
|
7
7
|
out = %x(
|
@@ -19,7 +19,7 @@ class PStream::Stream
|
|
19
19
|
@prot = prot
|
20
20
|
end
|
21
21
|
|
22
|
-
def to_s
|
22
|
+
def to_s
|
23
23
|
return contents
|
24
24
|
end
|
25
25
|
end
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pstream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Whittaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.7.7
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.7'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.7.7
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: scoobydoo
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,6 +62,8 @@ files:
|
|
42
62
|
- lib/pstream/error.rb
|
43
63
|
- lib/pstream/error/pcap_not_found.rb
|
44
64
|
- lib/pstream/error/pcap_not_readable.rb
|
65
|
+
- lib/pstream/error/protocol_not_supported.rb
|
66
|
+
- lib/pstream/error/stream_not_found.rb
|
45
67
|
- lib/pstream/error/tshark_not_found.rb
|
46
68
|
- lib/pstream/stream.rb
|
47
69
|
- lib/string.rb
|