Skip to content

Commit

Permalink
adding event on unexpected_udp_traffic
Browse files Browse the repository at this point in the history
Signed-off-by: h4l0gen <ks3913688@gmail.com>
  • Loading branch information
h4l0gen authored and poiana committed Apr 4, 2024
1 parent 20591ad commit e3ebb1f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions events/syscall/unexpected_udp_traffic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build linux
// +build linux

// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package syscall

import (
"fmt"
"os/exec"
"math/rand"
"github.com/falcosecurity/event-generator/events"
)

var _ = events.Register(GenerateUnexpectedUDPTraffic)

func GenerateUnexpectedUDPTraffic(h events.Helper) error {
// Choose a random port number
port := randInt(1024, 65535)

// Execute the command to send UDP packets
message := "UDP traffic"
cmd := exec.Command("echo", message, "|", "nc", "-u", "127.0.0.1", fmt.Sprintf("%d", port))
err := cmd.Run()
if err != nil {
return err
}

// Log the event
h.Log().Infof("Unexpected UDP Traffic Seen on port %d", port)

return nil
}

// randInt generates a random integer between min and max.
func randInt(min, max int) int {
return min + rand.Intn(max-min+1)
}

0 comments on commit e3ebb1f

Please sign in to comment.