Skip to content

Commit f9c107f

Browse files
feat: enhance network monitoring for UDP packets
Added support for monitoring UDP packets in the NetworkMonitor by introducing handling for the sendto and sendmsg syscalls. Updated logging to reflect the addition of UDP monitoring alongside existing TCP functionality.
1 parent a33c48b commit f9c107f

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

netmon.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ func (netMonitor *NetworkMonitor) handlePacket(attrs nflog.Attribute) {
7171
packet := gopacket.NewPacket(data, layers.LayerTypeIPv4, gopacket.Default)
7272
port := ""
7373
isSYN := false
74+
isUDP := false
7475
// Get the TCP layer from this packet
7576
if tcpLayer := packet.Layer(layers.LayerTypeTCP); tcpLayer != nil {
7677
// Get actual TCP data from this layer
7778
tcp, _ := tcpLayer.(*layers.TCP)
7879
port = tcp.DstPort.String()
7980
isSYN = tcp.SYN
8081

82+
} else if udpLayer := packet.Layer(layers.LayerTypeUDP); udpLayer != nil {
83+
// Get actual UDP data from this layer
84+
udp, _ := udpLayer.(*layers.UDP)
85+
port = udp.DstPort.String()
86+
isUDP = true
8187
}
8288

8389
// Get the IP layer from this packet
@@ -90,7 +96,7 @@ func (netMonitor *NetworkMonitor) handlePacket(attrs nflog.Attribute) {
9096
if !found {
9197
ipAddresses[ipv4Address] = 1
9298

93-
if isSYN {
99+
if isSYN || isUDP {
94100
if netMonitor.Status == "Dropped" {
95101

96102
netMonitor.ApiClient.sendNetConnection(netMonitor.CorrelationId, netMonitor.Repo,

procmon_linux.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,31 @@ func (p *ProcessMonitor) MonitorProcesses(errc chan error) {
107107
errc <- errors.Wrap(err, "failed to add audit rule for syscall connect")
108108
}
109109

110-
WriteLog("Net monitor added")
110+
WriteLog("Net monitor added for TCP (connect)")
111+
112+
// syscall sendto (for UDP)
113+
r, _ = flags.Parse(fmt.Sprintf("-a exit,always -S sendto -k %s", netMonitorTag))
114+
115+
actualBytes, _ = rule.Build(r)
116+
117+
if err = client.AddRule(actualBytes); err != nil {
118+
WriteLog(fmt.Sprintf("failed to add audit rule for sendto %v", err))
119+
errc <- errors.Wrap(err, "failed to add audit rule for syscall sendto")
120+
}
121+
122+
WriteLog("Net monitor added for UDP (sendto)")
123+
124+
// syscall sendmsg (for UDP)
125+
r, _ = flags.Parse(fmt.Sprintf("-a exit,always -S sendmsg -k %s", netMonitorTag))
126+
127+
actualBytes, _ = rule.Build(r)
128+
129+
if err = client.AddRule(actualBytes); err != nil {
130+
WriteLog(fmt.Sprintf("failed to add audit rule for sendmsg %v", err))
131+
errc <- errors.Wrap(err, "failed to add audit rule for syscall sendmsg")
132+
}
133+
134+
WriteLog("Net monitor added for UDP (sendmsg)")
111135

112136
// syscall process start
113137
r, _ = flags.Parse(fmt.Sprintf("-a exit,always -S execve -k %s", processMonitorTag))

0 commit comments

Comments
 (0)