Re-enable getStreamProps function

This commit is contained in:
M. Mert Yildiran 2021-08-19 12:12:52 +03:00
parent 58deed9eab
commit 4a8629c63e
No known key found for this signature in database
GPG Key ID: D42ADB236521BF7A
2 changed files with 21 additions and 23 deletions

View File

@ -286,6 +286,15 @@ func startPassiveTapper(outputItems chan *api.OutputChannelItem) {
var handle *pcap.Handle
var err error
if localhostIPs, err := getLocalhostIPs(); err != nil {
// TODO: think this over
rlog.Info("Failed to get self IP addresses")
rlog.Errorf("Getting-Self-Address", "Error getting self ip address: %s (%v,%+v)", err, err, err)
ownIps = make([]string, 0)
} else {
ownIps = localhostIPs
}
// Set up pcap packet capture
if *fname != "" {
log.Printf("Reading from pcap dump %q", *fname)

View File

@ -3,9 +3,11 @@ package tap
import (
"bufio"
"fmt"
"log"
"strconv"
"github.com/romana/rlog"
"github.com/up9inc/mizu/tap/api"
"log"
"github.com/google/gopacket" // pulls in all layers decoders
"github.com/google/gopacket/tcpassembly"
@ -26,11 +28,6 @@ func containsPort(ports []string, port string) bool {
return false
}
// TODO: remove?
func Emit(item *api.OutputChannelItem) {
log.Printf("Emit item: %+v\n", item)
}
func (h *tcpStream) clientRun(tcpID *api.TcpID, emitter api.Emitter) {
b := bufio.NewReader(&h.r)
for _, extension := range extensions {
@ -65,20 +62,18 @@ func (h *tcpStreamFactory) New(net, transport gopacket.Flow) tcpassembly.Stream
DstPort: transport.Dst().String(),
Ident: fmt.Sprintf("%s:%s", net, transport),
}
//dstPort, _ := strconv.Atoi(transport.Dst().String())
//streamProps := h.getStreamProps(net.Src().String(), net.Dst().String(), dstPort)
//if streamProps.isTapTarget {
//
//}
dstPort, _ := strconv.Atoi(transport.Dst().String())
streamProps := h.getStreamProps(net.Src().String(), net.Dst().String(), dstPort)
if streamProps.isTapTarget {
if containsPort(allOutboundPorts, transport.Dst().String()) {
go stream.clientRun(tcpID, h.Emitter)
} else if containsPort(allOutboundPorts, transport.Src().String()) {
go stream.serverRun(tcpID, h.Emitter)
}
}
//if h.shouldNotifyOnOutboundLink(net.Dst().String(), dstPort) {
// h.outbountLinkWriter.WriteOutboundLink(net.Src().String(), net.Dst().String(), dstPort, "", "")
//}
if containsPort(allOutboundPorts, transport.Dst().String()) {
go stream.clientRun(tcpID, h.Emitter)
} else if containsPort(allOutboundPorts, transport.Src().String()) {
go stream.serverRun(tcpID, h.Emitter)
}
return &stream.r
}
@ -96,12 +91,6 @@ func (factory *tcpStreamFactory) getStreamProps(srcIP string, dstIP string, dstP
}
return &streamProps{isTapTarget: false}
} else {
isTappedPort := dstPort == 80 || (gSettings.filterPorts != nil && (inArrayInt(gSettings.filterPorts, dstPort)))
if !isTappedPort {
rlog.Debugf("getStreamProps %s", fmt.Sprintf("- notHost1 %d", dstPort))
return &streamProps{isTapTarget: false, isOutgoing: false}
}
isOutgoing := !inArrayString(ownIps, dstIP)
if !*anydirection && isOutgoing {