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 <ks3913688@gmail.com>

adding an event on interpreted procs inbound network activity

Signed-off-by: h4l0gen <ks3913688@gmail.com>

commits squashed

Signed-off-by: h4l0gen <ks3913688@gmail.com>

sqaushing commits

Signed-off-by: h4l0gen <ks3913688@gmail.com>
  • Loading branch information
h4l0gen authored and poiana committed May 14, 2024
1 parent ebc6f6c commit c2adca2
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
61 changes: 61 additions & 0 deletions events/helper/inbound_connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 helper

import (
"net"
"strconv"

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

var _ = events.Register(InboundConnection)

func InboundConnection(h events.Helper) error {
address, _ := getAvailableLocalAddress()
listener, err := net.Listen("tcp", address)
if err != nil {
return err
}
defer listener.Close()
return nil
}

func getAvailableLocalAddress() (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 ip.String() + ":" + strconv.Itoa(listener.Addr().(*net.TCPAddr).Port), nil
}
return "", err
}
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 c2adca2

Please sign in to comment.