forked from diffusiondata/wireshark-dissector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dpt.lua
126 lines (105 loc) · 3.36 KB
/
dpt.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
-- Main
-- This file is the entry point for the plugin. It loads the other packages and adds listeners to Wireshark and
-- modifies the dissection table
-- This assumes that files are in USER_DIR
-- require looks in wireshark directories.
dofile( USER_DIR.."dpt.utilities.lua" )
dofile( USER_DIR.."dpt.info.lua" )
dofile( USER_DIR.."dpt.v5.lua" )
dofile( USER_DIR.."dpt.parse.lua" )
dofile( USER_DIR.."dpt.messages.lua" )
dofile( USER_DIR.."dpt.proto.lua" )
dofile( USER_DIR.."dpt.display.lua" )
dofile( USER_DIR.."dpt.dissector.lua" )
local u = diffusion.utilities
local i = diffusion.info
local dptProto = diffusion.proto.dptProto
local tcpConnections = diffusion.info.tcpConnections
local clientTable = diffusion.info.clientTable
local serverTable = diffusion.info.serverTable
local RD, FD = diffusion.utilities.RD, diffusion.utilities.FD
--------------------------------------
-- Client
Client = {}
function Client:new( host, port )
local result = { host = host, port = port }
setmetatable( result, self )
self.__index = self
return result
end
function Client:matches( host, port )
return self.host == host and self.port == port
end
function Client:isClient()
return true
end
---------------------------------------
-- Server
Server = {}
function Server:new( host, port )
local result = { host = host, port = port }
setmetatable( result, self )
self.__index = self
return result
end
function Server:matches( host, port )
return self.host == host and self.port == port
end
function Server:isClient()
return false
end
local f_tcp_stream = diffusion.utilities.f_tcp_stream
local tcpTap = Listener.new( "tcp", "tcp.flags eq 0x12" ) -- listen to SYN,ACK packets (which are sent by the *server*)
function tcpTap.packet( pinfo )
local streamNumber = f_tcp_stream()
local client = Client:new( u.f_dst_host(), pinfo.dst_port )
clientTable:add( u.f_dst_host(), pinfo.dst_port, client )
local server = Server:new( u.f_src_host(), pinfo.src_port )
serverTable:add( u.f_dst_host(), pinfo.dst_port, server )
tcpConnections[streamNumber] = {
client = client,
server = server
}
info( u.dump( tcpConnections ) )
end
function tcpTap.reset()
info( "resetting tcpConnections" )
end
-- Find the delimeterCount-th occurance of ch in this, or -1. delimeterCount indexes from zero.
function ByteArray:indexn(ch, delimiterCount)
for i = 0, self:len()-1 do
if self:get_index( i ) == ch then
-- Found a match, but is it the right one?
if delimiterCount == 0 then
return i
end
delimiterCount = delimiterCount -1
end
end
return -1
end
-- Find the delimeterCount-th occurance of ch in this, or -1. delimeterCount indexes from zero.
function ByteArray:index(ch)
for i = 0, self:len()-1 do
if self:get_index( i ) == ch then return i end
end
return -1
end
-- Mark up non-printing delimiters
function string:escapeDiff()
local result = self:gsub( string.char(RD), "<RD>" )
return (result:gsub( string.char(FD), "<FD>" ))
end
function string:toRecordString()
return string.format( "[%s]", self:gsub( string.char(FD), ", " ) )
end
-- Split a string into fields by the given delimited
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
-- Register the dissector
tcp_table = DissectorTable.get( "tcp.port" )
tcp_table:add( 8080, dptProto )