From 25299eca6dce6aac45b687c0a8f9206670ea3ae5 Mon Sep 17 00:00:00 2001 From: dimagolomozy Date: Mon, 16 Aug 2021 19:07:39 +0300 Subject: [PATCH 1/3] no Src and Dst addr in message --- tcp/tcp_message.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tcp/tcp_message.go b/tcp/tcp_message.go index 4dab30c0c..614b5413a 100644 --- a/tcp/tcp_message.go +++ b/tcp/tcp_message.go @@ -350,6 +350,8 @@ func (parser *MessageParser) processPacket(pckt *Packet) { m = new(Message) m.Direction = pckt.Direction + m.SrcAddr = pckt.SrcIP.String() + m.DstAddr = pckt.DstIP.String() parser.m[mIDX][mID] = m From 05ed82129775549a4f8349edaaad11ec2d5aa791 Mon Sep 17 00:00:00 2001 From: Dima Golomozy Date: Thu, 19 Aug 2021 20:43:26 +0300 Subject: [PATCH 2/3] capture nics (#1000) 1. move the `isDevice(l.host, pi)` to be first, as no need to iterate on all nics if it returns `true` 2. first compare by name, as same nics will have same names 3. if not found by name, compare by ips. the bug was the `strings.HasPrefix` 2 different nics with ipv6: ``` #nic1 ip: f1234::55 #nic2 ip: f1234::55::66::66 ``` so because of the `strings.HasPrefix` it was evaluated as the name nics. but they are not. --- capture/capture.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/capture/capture.go b/capture/capture.go index c26087aea..d155f43cd 100644 --- a/capture/capture.go +++ b/capture/capture.go @@ -569,33 +569,33 @@ func (l *Listener) setInterfaces() (err error) { } for _, pi := range pifis { + if isDevice(l.host, pi) { + l.Interfaces = []pcap.Interface{pi} + return + } + var ni net.Interface for _, i := range ifis { + if i.Name == pi.Name { + ni = i + break + } + addrs, _ := i.Addrs() for _, a := range addrs { for _, pa := range pi.Addresses { - if strings.HasPrefix(a.String(), pa.IP.String()) { + if a.String() == pa.IP.String() { ni = i break } } } - - if len(addrs) == 0 && i.Name == pi.Name { - ni = i - break - } } if ni.Flags&net.FlagLoopback != 0 { l.loopIndex = ni.Index } - if isDevice(l.host, pi) { - l.Interfaces = []pcap.Interface{pi} - return - } - if runtime.GOOS != "windows" { if len(pi.Addresses) == 0 { continue From f25cc66281e430b716cd63a9d18abe27a0b8148c Mon Sep 17 00:00:00 2001 From: Thomas Ake van der Meer Date: Tue, 7 May 2024 20:37:58 +0200 Subject: [PATCH 3/3] Fix proto.DeleteHeader() --- proto/proto.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/proto.go b/proto/proto.go index 5f51d1c57..4e556641c 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -183,9 +183,9 @@ func AddHeader(payload, name, value []byte) []byte { // DeleteHeader takes http payload and removes header name from headers section // Returns modified request payload func DeleteHeader(payload, name []byte) []byte { - _, hs, he, _, _ := header(payload, name) + _, hs, he, _, ve := header(payload, name) if hs != -1 { - return byteutils.Cut(payload, hs, he+1) + return byteutils.Cut(payload, hs, ve+1) } return payload }