Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Achiefs/fim into 140-rule-trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
okynos committed Apr 22, 2024
2 parents eb5c68e + ad0df19 commit a01c68a
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 47 deletions.
8 changes: 7 additions & 1 deletion pkg/deb/debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ fim (0.5.0-1) xenial; urgency=medium

* More info: https://github.com/Achiefs/fim/releases/tag/v0.5.0

-- Jose Fernandez <[email protected]> Fri, 17 Nov 2023 12:57:00 +0000
-- Jose Fernandez <[email protected]> Fri, 19 Apr 2024 16:04:00 +0000

fim (0.4.11-1) xenial; urgency=medium

* More info: https://github.com/Achiefs/fim/releases/tag/v0.4.11

-- Jose Fernandez <[email protected]> Fri, 19 Apr 2024 12:48:00 +0000

fim (0.4.10-1) xenial; urgency=medium

Expand Down
3 changes: 3 additions & 0 deletions pkg/deb/repository/release/fim_0.4.11-1_amd64.deb
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/deb/repository/release/fim_0.4.11-1_arm64.deb
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/deb/repository/test/fim_0.4.11-1_amd64.deb
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/deb/repository/test/fim_0.4.11-1_arm64.deb
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/macos/repository/fim-0.4.11-arm64.pkg
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/macos/repository/fim-0.4.11-x86_64.pkg
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/msi/builder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cd pkg\msi
cp ..\..\target\release\fim.exe .\
cp ..\..\config\windows\config.yml .\

Invoke-Expression "& `"C:\Program Files (x86)\WiX Toolset v3.11\bin\candle.exe`" .\fim.wxs -o .\fim.wixobj"
Invoke-Expression "& `"C:\Program Files (x86)\WiX Toolset v3.*\bin\candle.exe`" .\fim.wxs -o .\fim.wixobj"

Invoke-Expression "& `"C:\Program Files (x86)\WiX Toolset v3.11\bin\light.exe`" -ext WixUIExtension .\fim.wixobj -o fim-$version-1-x64.msi"
Invoke-Expression "& `"C:\Program Files (x86)\WiX Toolset v3.*\bin\light.exe`" -ext WixUIExtension .\fim.wixobj -o fim-$version-1-x64.msi"

3 changes: 3 additions & 0 deletions pkg/msi/repository/fim-0.4.11-1-x64.msi
Git LFS file not shown
5 changes: 4 additions & 1 deletion pkg/rpm/fim.spec
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ rm -fr %{buildroot}
# -----------------------------------------------------------------------------

%changelog
* Fri Nov 17 2023 support <[email protected]> - 0.5.0
* Fri Apr 19 2024 support <[email protected]> - 0.5.0
- More info: https://github.com/Achiefs/fim/releases/tag/v0.5.0

* Fri Apr 19 2024 support <[email protected]> - 0.4.11
- More info: https://github.com/Achiefs/fim/releases/tag/v0.4.11

* Tue Oct 31 2023 support <[email protected]> - 0.4.10
- More info: https://github.com/Achiefs/fim/releases/tag/v0.4.10

Expand Down
3 changes: 3 additions & 0 deletions pkg/rpm/repository/release/fim-0.4.11-1.aarch64.rpm
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/rpm/repository/release/fim-0.4.11-1.x86_64.rpm
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/rpm/repository/test/fim-0.4.11-1.aarch64.rpm
Git LFS file not shown
3 changes: 3 additions & 0 deletions pkg/rpm/repository/test/fim-0.4.11-1.x86_64.rpm
Git LFS file not shown
7 changes: 5 additions & 2 deletions src/auditevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,12 @@ mod tests {

// ------------------------------------------------------------------------

#[ignore] // Just for GH runner error (Passed on local)
#[test]
fn test_from() {
if utils::get_os() == "linux" {
let config = Config::new(&utils::get_os(), None);
let config = Config::new(&utils::get_os(),
Some("test/unit/config/linux/audit_from_test.yml"));
let syscall = HashMap::<String, String>::from([
(String::from("syscall"), String::from("syscall")),
(String::from("ppid"), String::from("ppid")),
Expand Down Expand Up @@ -627,9 +629,10 @@ mod tests {
/*let parent = HashMap::<String, String>::from([
(String::from("name"), String::from("/tmp"))
]);*/

let paths = Vec::from([
HashMap::<String, String>::from([
(String::from("name"), String::from("/tmp")),
(String::from("name"), String::from("/etc")),
(String::from("nametype"), String::from("PARENT"))
]),
HashMap::<String, String>::from([
Expand Down
78 changes: 37 additions & 41 deletions src/rotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
use std::fs::{metadata, File, copy, read_to_string, remove_file, create_dir};
use std::io::Write;
use std::path::Path;
use std::time::{SystemTime, Duration, UNIX_EPOCH};
use std::time::Duration;
use std::thread;
use log::{debug, error, info};
use std::ptr::addr_of_mut;

use crate::config;
use crate::utils;
Expand Down Expand Up @@ -175,55 +176,50 @@ fn rotate_file(filepath: &str, iteration: u32, lock: &mut bool){
#[cfg(not(tarpaulin_include))]
pub fn rotator(){
let config = unsafe { super::GCONFIG.clone().unwrap() };
let mut start_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();

loop{
if (start_time + Duration::new(10, 0)).as_millis() <
SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards").as_millis() {

let log_size = if Path::new(config.clone().log_file.as_str()).exists() {
metadata(config.clone().log_file).unwrap().len() as usize
}else{ 0 };

let events_size = if Path::new(config.clone().events_file.as_str()).exists() {
metadata(config.clone().events_file).unwrap().len() as usize
}else{ 0 };

if events_size >= config.events_max_file_size * 1000000 {
let events_path = Path::new(config.events_file.as_str());
let mut parent_path = events_path.parent().unwrap().to_path_buf();
parent_path.push("archive");

if ! parent_path.exists(){
match create_dir(parent_path.clone()){
Ok(_v) => debug!("Archive directory created successfully."),
Err(e) => error!("Cannot create archive directory, error: {}", e)
};
}

unsafe { rotate_file(config.clone().events_file.as_str(),
get_iteration(parent_path.to_str().unwrap()), &mut config::TMP_EVENTS) };
let log_size = if Path::new(config.clone().log_file.as_str()).exists() {
metadata(config.clone().log_file).unwrap().len() as usize
}else{ 0 };

let events_size = if Path::new(config.clone().events_file.as_str()).exists() {
metadata(config.clone().events_file).unwrap().len() as usize
}else{ 0 };

if events_size >= config.events_max_file_size * 1000000 {
let events_path = Path::new(config.events_file.as_str());
let mut parent_path = events_path.parent().unwrap().to_path_buf();
parent_path.push("archive");

if ! parent_path.exists(){
match create_dir(parent_path.clone()){
Ok(_v) => debug!("Archive directory created successfully."),
Err(e) => error!("Cannot create archive directory, error: {}", e)
};
}

if log_size >= config.log_max_file_size * 1000000 {
let log_path = Path::new(config.log_file.as_str());
let mut parent_path = log_path.parent().unwrap().to_path_buf();
parent_path.push("archive");
unsafe { rotate_file(config.clone().events_file.as_str(),
get_iteration(parent_path.to_str().unwrap()), &mut *addr_of_mut!(config::TMP_EVENTS)) };
}

if ! parent_path.exists(){
match create_dir(parent_path.clone()){
Ok(_v) => debug!("Archive directory created successfully."),
Err(e) => error!("Cannot create archive directory, error: {}", e)
};
}
if log_size >= config.log_max_file_size * 1000000 {
let log_path = Path::new(config.log_file.as_str());
let mut parent_path = log_path.parent().unwrap().to_path_buf();
parent_path.push("archive");

rotate_file(config.clone().log_file.as_str(),
get_iteration(parent_path.to_str().unwrap()), &mut true);
if ! parent_path.exists(){
match create_dir(parent_path.clone()){
Ok(_v) => debug!("Archive directory created successfully."),
Err(e) => error!("Cannot create archive directory, error: {}", e)
};
}

start_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
thread::sleep(Duration::from_secs(1800));
rotate_file(config.clone().log_file.as_str(),
get_iteration(parent_path.to_str().unwrap()), &mut true);
}

debug!("Sleeping rotator thread for 30 minutes");
thread::sleep(Duration::from_secs(1800));
}
}

Expand Down
27 changes: 27 additions & 0 deletions test/unit/config/linux/audit_from_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
node: "FIM"

# Events configuration, where to store produced events
events:
destination: file
file: /var/lib/fim/events.json

# Audit extended files and folders information
audit:
- path: /etc
labels: ["tmp", "linux"]
ignore: [".swp"]
allowed: [".txt", ".rs"]

# Simple files and folders information
monitor:
- path: /bin/
- path: /usr/bin/
labels: ["usr/bin", "linux"]
- path: /etc
labels: ["etc", "linux"]

# App procedure and errors logging
log:
file: /var/log/fim/fim.log
# Available levels [debug, info, error, warning]
level: info

0 comments on commit a01c68a

Please sign in to comment.