Skip to content

Commit

Permalink
adding an event on interpreted procs inbound network activity
Browse files Browse the repository at this point in the history
Signed-off-by: h4l0gen <[email protected]>

adding an event on interpreted procs inbound network activity

Signed-off-by: h4l0gen <[email protected]>

commits squashed

Signed-off-by: h4l0gen <[email protected]>
  • Loading branch information
h4l0gen committed Apr 24, 2024
1 parent 31789dc commit 9d863e8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
63 changes: 63 additions & 0 deletions events/helper/inbound_connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 helper

import (
"fmt"
"net"

"github.com/falcosecurity/event-generator/events"
)

var _ = events.Register(InboundConnection)

func InboundConnection(h events.Helper) error {
address, _ := getRandomLocalAddress()
listener, err := net.Listen("tcp", address)
if err != nil {
return err
}
fmt.Println("Server started on", address)
defer listener.Close()
fmt.Println("Server closed on", address)
return nil
}

func getRandomLocalAddress() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
for _, addr := range addrs {
ipNet, ok := addr.(*net.IPNet)
if !ok {
continue
}
if ipNet.IP.IsLoopback() || ipNet.IP.IsUnspecified() {
continue
}
ip := ipNet.IP.To4()
if ip == nil {
continue
}
listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: ip})
if err != nil {
continue
}
listener.Close()
return fmt.Sprintf("%s:%d", ip, listener.Addr().(*net.TCPAddr).Port), nil
}
return "", fmt.Errorf("no valid local address found")
}
28 changes: 28 additions & 0 deletions events/syscall/interpreted_inbound_network_activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2024 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 (
"github.com/falcosecurity/event-generator/events"
)

var _ = events.Register(
InterpretedProcsInboundNetworkActivity,
events.WithDisabled(), // this rule is not included in falco_rules.yaml (stable rules), so disable the action
)

func InterpretedProcsInboundNetworkActivity(h events.Helper) error {
return h.SpawnAs("lua", "helper.InboundConnection")
}

0 comments on commit 9d863e8

Please sign in to comment.