Skip to content

Commit

Permalink
Created script file in dev shm folder if not exists
Browse files Browse the repository at this point in the history
Signed-off-by: GLVS Kiriti <[email protected]>
  • Loading branch information
GLVSKiriti authored and poiana committed Apr 5, 2024
1 parent f1768f7 commit d2a92d1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion events/syscall/execution_from_dev_shm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
package syscall

import (
"os"
"os/exec"

"github.com/falcosecurity/event-generator/events"
Expand All @@ -23,6 +24,28 @@ import (
var _ = events.Register(ExecutionFromDevShm)

func ExecutionFromDevShm(h events.Helper) error {
cmd := exec.Command("/dev/shm/example_script.sh")
scriptPath := "/dev/shm/example_script-created-by-falco-event-generator.sh"

file, err := os.Create(scriptPath)
if err != nil {
return err
}

scriptContent := "#!/bin/bash\n echo 'hello world'"
if _, err := file.WriteString(scriptContent); err != nil {
return err
}

if err := file.Close(); err != nil {
return err
}

// Set execute permission on the file
if err := exec.Command("chmod", "+x", scriptPath).Run(); err != nil {
return err
}

cmd := exec.Command(scriptPath)
defer os.Remove(scriptPath)
return cmd.Run()
}

0 comments on commit d2a92d1

Please sign in to comment.