Class: PStream

Inherits:
Object
  • Object
show all
Defined in:
lib/pstream.rb

Defined Under Namespace

Classes: Error, Stream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pcap) ⇒ PStream

Returns a new instance of PStream.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pstream.rb', line 40

def initialize(pcap)
    if (ScoobyDoo.where_are_you("tshark").nil?)
        raise PStream::Error::TsharkNotFound.new
    end

    @pcap = Pathname.new(pcap).expand_path

    if (!@pcap.exist?)
        raise PStream::Error::PcapNotFound.new(@pcap)
    elsif (!@pcap.readable?)
        raise PStream::Error::PcapNotReadable.new(@pcap)
    end

    @tcp_streams = get_streams("tcp")
    @udp_streams = get_streams("udp")
end

Instance Attribute Details

#tcp_streamsObject

Returns the value of attribute tcp_streams.



5
6
7
# File 'lib/pstream.rb', line 5

def tcp_streams
  @tcp_streams
end

#udp_streamsObject

Returns the value of attribute udp_streams.



6
7
8
# File 'lib/pstream.rb', line 6

def udp_streams
  @udp_streams
end

Instance Method Details

#ciphersObject



8
9
10
11
12
13
14
15
# File 'lib/pstream.rb', line 8

def ciphers
    # List ciphers during ssl handshake
    out = %x(
        tshark -r #{@pcap} -Y ssl.handshake.ciphersuite -V | \
             \grep -E "Internet Protocol|Hostname:|Cipher Suite"
    )
    return out
end

#summaryObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pstream.rb', line 57

def summary
    ret = Array.new

    # List TCP streams
    ret.push("TCP Streams:")
    count = 0
    @tcp_streams.each do |stream|
        ret.push("#{count} | #{stream.desc} | #{stream.frames}")
        count += 1
    end
    ret.push("")

    # List UDP streams
    ret.push("UDP Streams:")
    count = 0
    @udp_streams.each do |stream|
        ret.push("#{count} | #{stream.desc} | #{stream.frames}")
        count += 1
    end
    ret.push("")

    # List ciphers that were actually selected
    ret.push("Ciphers in use:")
    f = "ssl.handshake.ciphersuite && ssl.handshake.type == 2"
    out = %x(
        tshark -r #{@pcap} -Y "#{f}" -V | \
            \grep -E "Cipher Suite:" | \
            sed -r "s|^ +Cipher Suite: ||g" | sort -u
    )
    ret.concat(out.split("\n"))

    return ret.join("\n")
end

#to_sObject



91
92
93
# File 'lib/pstream.rb', line 91

def to_s
    return summary
end