From ddf4731586ea982b98c444ed4331725a715ae29d Mon Sep 17 00:00:00 2001 From: praveen-rikhari Date: Mon, 11 Mar 2024 22:03:38 +0530 Subject: [PATCH] falco: create hardlink over sensitive file event added Signed-off-by: praveen-rikhari --- .../create_hardlink_over_sensitive_files.go | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 events/syscall/create_hardlink_over_sensitive_files.go diff --git a/events/syscall/create_hardlink_over_sensitive_files.go b/events/syscall/create_hardlink_over_sensitive_files.go new file mode 100644 index 00000000..061f87ab --- /dev/null +++ b/events/syscall/create_hardlink_over_sensitive_files.go @@ -0,0 +1,43 @@ +// 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 ( + "os" + "os/exec" + + "github.com/falcosecurity/event-generator/events" +) + +var _ = events.Register(CreateHardlinkOverSensitiveFiles) + +func CreateHardlinkOverSensitiveFiles(h events.Helper) error { + path, err := exec.LookPath("ln") + if err != nil { + // if we don't have a ln, just bail + return &events.ErrSkipped{ + Reason: "ln utility not found in path", + } + } + + tmpDir, err := os.MkdirTemp(os.TempDir(), "event-generator-syscall-CreateHardlinkOverSensitiveFiles") + if err != nil { + return err + } + defer os.ReadDir(tmpDir) + + cmd := exec.Command(path, "-v", "/etc", tmpDir+"/etc_link") + return cmd.Run() +}