|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +/* |
| 3 | +Copyright (C) 2024 The Falco Authors. |
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +Unless required by applicable law or agreed to in writing, software |
| 9 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +See the License for the specific language governing permissions and |
| 12 | +limitations under the License. |
| 13 | +*/ |
| 14 | + |
| 15 | +package syscall |
| 16 | + |
| 17 | +import ( |
| 18 | + "os" |
| 19 | + |
| 20 | + "github.com/falcosecurity/event-generator/events" |
| 21 | +) |
| 22 | + |
| 23 | +var _ = events.Register( |
| 24 | + ReadShellConfigurationFile, |
| 25 | + events.WithDisabled(), // this rules is not included in falco_rules.yaml (stable rules), so disable the action |
| 26 | +) |
| 27 | + |
| 28 | +func ReadShellConfigurationFile(h events.Helper) error { |
| 29 | + shellConfigFiles := []string{ |
| 30 | + "/etc/bashrc", |
| 31 | + "/etc/profile", |
| 32 | + "/etc/csh.cshrc", |
| 33 | + "/etc/csh.login", |
| 34 | + } |
| 35 | + |
| 36 | + var errRead error |
| 37 | + |
| 38 | + // Iterate over shellConfigFiles until a file is successfully opened. |
| 39 | + for _, configFile := range shellConfigFiles { |
| 40 | + file, err := os.Open(configFile) |
| 41 | + if err == nil { |
| 42 | + h.Log().Infof("A shell configuration file %s was read by a non-shell program", configFile) |
| 43 | + defer file.Close() |
| 44 | + return err |
| 45 | + } else if !os.IsNotExist(err) { |
| 46 | + errRead = err |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + return errRead |
| 51 | +} |
0 commit comments