Skip to content

Commit 6045789

Browse files
authored
Merge pull request #8 from codeyourweb/dev
3.6.0 release
2 parents e9d476a + cac0f16 commit 6045789

20 files changed

+246
-75
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
[![Go Version](https://img.shields.io/badge/Go-1.24+-00ADD8?style=flat-square&logo=go)](https://golang.org)
88
[![License](https://img.shields.io/github/license/codeyourweb/fastfinder?style=flat-square)](LICENSE)
99
[![Release](https://img.shields.io/github/v/release/codeyourweb/fastfinder?style=flat-square)](https://github.com/codeyourweb/fastfinder/releases)
10-
[![Build Status](https://img.shields.io/github/actions/workflow/status/codeyourweb/fastfinder/go_build_windows.yml?style=flat-square&label=Windows)](https://github.com/codeyourweb/fastfinder/actions)
11-
[![Build Status](https://img.shields.io/github/actions/workflow/status/codeyourweb/fastfinder/go_build_linux.yml?style=flat-square&label=Linux)](https://github.com/codeyourweb/fastfinder/actions)
10+
[![Build Status](https://img.shields.io/github/actions/workflow/status/codeyourweb/fastfinder/go_build_windows_amd64.yml?style=flat-square&label=Windows)](https://github.com/codeyourweb/fastfinder/actions)
11+
[![Build Status](https://img.shields.io/github/actions/workflow/status/codeyourweb/fastfinder/go_build_linux_amd64.yml?style=flat-square&label=Linux)](https://github.com/codeyourweb/fastfinder/actions)
1212
[![Platform Support](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux-brightgreen?style=flat-square)](#installation)
1313

1414
## ✨ Overview
@@ -148,6 +148,7 @@ options:
148148
findInRemovableDrives: true # enumerate removable drive content
149149
findInNetworkDrives: true # enumerate network drive content
150150
findInCDRomDrives: true # enumerate physical CD-ROM and mounted iso / vhd...
151+
findInMemory: true # check for results in processes memory
151152
output:
152153
copyMatchingFiles: true # create a copy of every matching file
153154
base64Files: true # base64 matched content before copy

config_integration_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"os"
5+
"os/exec"
56
"path/filepath"
67
"testing"
78
)
@@ -108,14 +109,26 @@ func TestConfigurationMissingRequired(t *testing.T) {
108109

109110
// TestConfigurationEmpty tests handling of empty configuration
110111
func TestConfigurationEmpty(t *testing.T) {
112+
if os.Getenv("TEST_CONFIGURATION_EMPTY_SUBPROCESS") == "1" {
113+
tmpFile := os.Getenv("TEST_CONFIGURATION_EMPTY_FILE")
114+
var config Configuration
115+
config.getConfiguration(tmpFile)
116+
return
117+
}
118+
111119
tmpFile := filepath.Join(t.TempDir(), "empty_config.yml")
112120
os.WriteFile(tmpFile, []byte(""), 0644)
113121

114-
var config Configuration
115-
config.getConfiguration(tmpFile)
122+
cmd := exec.Command(os.Args[0], "-test.run=TestConfigurationEmpty")
123+
cmd.Env = append(os.Environ(), "TEST_CONFIGURATION_EMPTY_SUBPROCESS=1", "TEST_CONFIGURATION_EMPTY_FILE="+tmpFile)
124+
err := cmd.Run()
116125

117-
// Verify no panic occurred
118-
t.Log("Empty configuration handled gracefully")
126+
// We expect an exit error here because LogFatal calls os.Exit(1)
127+
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
128+
t.Log("Empty configuration triggered exit as expected")
129+
return
130+
}
131+
t.Fatalf("process ran with err %v, want exit status 1", err)
119132
}
120133

121134
// TestConfigurationYARAWithRC4 tests YARA section with RC4 encryption

configuration.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ import (
1313
"gopkg.in/yaml.v3"
1414
)
1515

16-
type ConfigurationObject struct {
17-
Line int
18-
19-
Configuration
20-
}
21-
2216
type Configuration struct {
2317
Input Input `yaml:"input"`
2418
Options Options `yaml:"options"`
@@ -45,7 +39,7 @@ type Options struct {
4539
FindInRemovableDrives bool `yaml:"findInRemovableDrives"`
4640
FindInNetworkDrives bool `yaml:"findInNetworkDrives"`
4741
FindInCDRomDrives bool `yaml:"findInCDRomDrives"`
48-
ScanMemory bool `yaml:"scanMemory"`
42+
FindInMemory bool `yaml:"findInMemory"`
4943
}
5044

5145
type Output struct {
@@ -60,17 +54,6 @@ type AdvancedParameters struct {
6054
CleanMemoryIfFileGreaterThanSize int `yaml:"cleanMemoryIfFileGreaterThanSize"`
6155
}
6256

63-
func (i *ConfigurationObject) UnmarshalYAML(value *yaml.Node) error {
64-
err := value.Decode(&i.Configuration)
65-
if err != nil {
66-
return err
67-
}
68-
69-
i.Line = value.Line
70-
71-
return nil
72-
}
73-
7457
func (c *Configuration) getConfiguration(configFile string) *Configuration {
7558
var yamlContent []byte
7659
var err error
@@ -107,15 +90,14 @@ func (c *Configuration) getConfiguration(configFile string) *Configuration {
10790
yamlContent = RC4Cipher(yamlContent, BUILDER_RC4_KEY)
10891
}
10992

110-
var o ConfigurationObject
111-
err = yaml.Unmarshal(yamlContent, &o)
93+
decoder := yaml.NewDecoder(bytes.NewReader(yamlContent))
94+
decoder.KnownFields(true)
95+
err = decoder.Decode(c)
11296

11397
if err != nil {
11498
LogFatal(fmt.Sprintf("%s - %v", configFile, err))
11599
}
116100

117-
*c = o.Configuration
118-
119101
// check for specific user configuration params inconsistencies
120102
if len(c.Input.Path) == 0 || (len(c.Input.Content.Grep) == 0 && len(c.Input.Content.Yara) == 0 && len(c.Input.Content.Checksum) == 0) {
121103
c.Options.ContentMatchDependsOnPathMatch = false
@@ -203,5 +185,6 @@ func (c *Configuration) getConfiguration(configFile string) *Configuration {
203185
}
204186
}
205187

188+
LogMessage(LOG_INFO, "Configuration loaded")
206189
return c
207-
}
190+
}

event_forwarding.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type EventForwarder struct {
2424
currentFilePath string
2525
lastRotation time.Time
2626
fileMutex sync.Mutex
27+
wg sync.WaitGroup
2728
}
2829

2930
// FastFinderEvent represents an event to be forwarded
@@ -133,6 +134,7 @@ func InitializeEventForwarding(config *ForwardingConfig) error {
133134
httpClient: httpClient,
134135
}
135136

137+
eventForwarder.wg.Add(1)
136138
// Start the forwarding goroutine
137139
go eventForwarder.forwardingLoop()
138140

@@ -190,6 +192,30 @@ func ForwardAlertEvent(ruleName, filePath string, fileSize int64, fileHash strin
190192
ForwardEvent("alert", "high", fmt.Sprintf("YARA rule match: %s in %s", ruleName, filePath), metadata)
191193
}
192194

195+
// ForwardGrepMatchEvent forwards a Grep match event
196+
func ForwardGrepMatchEvent(pattern, filePath string, fileSize int64, metadata map[string]string) {
197+
if metadata == nil {
198+
metadata = make(map[string]string)
199+
}
200+
metadata["grep_pattern"] = pattern
201+
metadata["file_path"] = filePath
202+
metadata["file_size"] = fmt.Sprintf("%d", fileSize)
203+
204+
ForwardEvent("alert", "high", fmt.Sprintf("Grep match: %s in %s", pattern, filePath), metadata)
205+
}
206+
207+
// ForwardChecksumMatchEvent forwards a Checksum match event
208+
func ForwardChecksumMatchEvent(checksum, filePath string, fileSize int64, metadata map[string]string) {
209+
if metadata == nil {
210+
metadata = make(map[string]string)
211+
}
212+
metadata["checksum"] = checksum
213+
metadata["file_path"] = filePath
214+
metadata["file_size"] = fmt.Sprintf("%d", fileSize)
215+
216+
ForwardEvent("alert", "high", fmt.Sprintf("Checksum match: %s in %s", checksum, filePath), metadata)
217+
}
218+
193219
// ForwardScanCompleteEvent forwards scan completion statistics
194220
func ForwardScanCompleteEvent(filesScanned, matchesFound, errorsEncountered int, duration time.Duration) {
195221
if eventForwarder == nil {
@@ -243,6 +269,7 @@ func (ef *EventForwarder) shouldForwardEvent(eventType, severity string) bool {
243269

244270
// forwardingLoop runs the periodic event forwarding
245271
func (ef *EventForwarder) forwardingLoop() {
272+
defer ef.wg.Done()
246273
ticker := time.NewTicker(time.Duration(ef.config.FlushTime) * time.Second)
247274
defer ticker.Stop()
248275

@@ -466,11 +493,14 @@ func (ef *EventForwarder) cleanOldFiles() {
466493
// StopEventForwarding stops the event forwarding system
467494
func StopEventForwarding() {
468495
if eventForwarder != nil {
496+
close(eventForwarder.stopChannel)
497+
eventForwarder.wg.Wait()
498+
469499
// Close current file if open
470500
if eventForwarder.currentFile != nil {
471501
eventForwarder.currentFile.Close()
502+
eventForwarder.currentFile = nil
472503
}
473-
close(eventForwarder.stopChannel)
474504
eventForwarder = nil
475505
}
476506
}

examples/CISA-AA21-259A/CISA-AA21-259A.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ options:
2929
findInRemovableDrives: false
3030
findInNetworkDrives: false
3131
findInCDRomDrives: false
32-
scanMemory: false
32+
findInMemory: false
3333
output:
3434
copyMatchingFiles: false
3535
base64Files: false

examples/React2Shell/react2shell.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ options:
2424
findInRemovableDrives: true
2525
findInNetworkDrives: true
2626
findInCDRomDrives: true
27-
scanMemory: true
27+
findInMemory: true
2828
output:
2929
copyMatchingFiles: false
3030
base64Files: false

examples/example_configuration_api_triage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ options:
1111
findInRemovableDrives: false
1212
findInNetworkDrives: false
1313
findInCDRomDrives: false
14-
scanMemory: false
14+
findInMemory: false
1515
output:
1616
copyMatchingFiles: false
1717
base64Files: false

examples/example_configuration_distant.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ options:
1212
findInRemovableDrives: false
1313
findInNetworkDrives: false
1414
findInCDRomDrives: false
15-
scanMemory: false
15+
findInMemory: false
1616
output:
1717
copyMatchingFiles: false
1818
base64Files: false

examples/example_configuration_docker_triage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ options:
3838
findInRemovableDrives: false
3939
findInNetworkDrives: false
4040
findInCDRomDrives: false
41-
scanMemory: false
41+
findInMemory: false
4242
output:
4343
copyMatchingFiles: true
4444
base64Files: true

examples/example_configuration_linux.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ options:
1414
findInRemovableDrives: false
1515
findInNetworkDrives: false
1616
findInCDRomDrives: false
17-
scanMemory: true
17+
findInMemory: true
1818
output:
1919
copyMatchingFiles: false
2020
base64Files: false

0 commit comments

Comments
 (0)