forked from gojue/ecapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecapture.lua
65 lines (51 loc) · 2.19 KB
/
ecapture.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
-- eCapture enhances the capture data viewable in the Wireshark, will show more information about process information.
-- HomePage : https://ecapture.cc
-- Repo : https://github.com/gojue/ecapture
-- Author : CFC4N <[email protected]>
-- License : GPL v3
-- Version : 0.1.0
-- Date : 2022-10-22
ecapture = Proto("eCapture", "eCapture enhances the capture data viewable in the Wireshark, will show more information about process information. more information: https://ecapture.cc")
local ECAPTURE_MAGIC = 0xCC0C4CFC
local fields = {}
fields.magic = ProtoField.uint32("ecapture.magic", "Magic", base.HEX)
fields.pid = ProtoField.int32("ecapture.pid", "PID", base.DEC)
fields.Comm = ProtoField.string("ecapture.Comm", "Comm", base.ASCII)
-- fields.Cmdline = ProtoField.string("ecapture.Cmdline", "Cmdline", base.ASCII)
ecapture.fields = fields
function ecapture.dissector(buffer, pinfo, tree)
-- for now only IP packets are supported
eth_header_protocol = buffer(12 ,2):uint()
if eth_header_protocol ~= 0x800 then
return
end
-- ethernet header is always 14 bytes, and after 2 bytes into IP header, you'll have IP packet's total length
local ethernet_header_size = 14
local iplen = buffer(16 ,2):uint()
local framelen = buffer:len()
local trailerlength = framelen - ethernet_header_size - iplen
-- check padding type
-- -4: skip the FCS
local trailer = buffer(iplen+ethernet_header_size ,trailerlength )
if trailerlength < 9 then
return
end
-- simple sanity check with the magic number
local magic = trailer(0, 4):uint()
if(magic ~= ECAPTURE_MAGIC) then
-- print("trailerlength:"..trailerlength)
-- print("magic:%x", magic)
-- print("trailer:%x", trailer)
return
end
local pid = trailer(4, 4):uint()
local subtree = tree:add(ecapture, buffer(), string.format("eCapture, pid: %d",pid))
subtree:add(fields.pid, pid)
local commLen = trailer(8, 1):uint()
subtree:add(fields.Comm, trailer(9,commLen))
-- local cmdlineLen = trailer(9+commLen, 2):uint()
-- subtree:add(fields.cmdlineLen, trailer(9+commLen,cmdlineLen))
-- local cmdline = trailer(11+commLen, cmdlineLen):string()
-- subtree:add(fields.Cmdline, cmdline)
end
register_postdissector(ecapture)