Skip to content

Commit dd1af31

Browse files
committed
1.2 release and linux version preparation
1 parent b014ebf commit dd1af31

File tree

6 files changed

+145
-106
lines changed

6 files changed

+145
-106
lines changed

examples/example_configuration.yaml renamed to examples/example_configuration_windows.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# TODO check REGEX / YARA / checksum
21
input:
32
path:
43
- '%APPDATA%\\*.exe'
@@ -10,7 +9,7 @@ input:
109
grep:
1110
- 'fastfinder.exe'
1211
yara:
13-
- './example_rule.yar'
12+
- './examples/example_rule_windows.yar'
1413
checksum:
1514
- 'c4884dadc3680439e30bf48ae0ca7048'
1615
- '7A320D69E436911A9EAF676D8C2B6A22580BF79F'
File renamed without changes.

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424
}
2525

2626
// parse configuration file
27-
parser := argparse.NewParser("fastfinder", "Incident Response - Fast suspicious file finder")
27+
parser := argparse.NewParser("fastfinder", "(v1.2) Incident Response - Fast suspicious file finder")
2828
configPath := parser.String("c", "configuration", &argparse.Options{Required: true, Default: "configuration.yaml", Help: "Fastfind configuration file"})
2929
sfxPath := parser.String("b", "build", &argparse.Options{Required: false, Help: "Output a standalone package with configuration and rules in a single binary"})
3030
outLogPath := parser.String("o", "output", &argparse.Options{Required: false, Help: "Save fastfinder logs in the specified file"})

utils_common.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package main
2+
3+
import (
4+
"encoding/base64"
5+
"io"
6+
"log"
7+
"os"
8+
"path/filepath"
9+
"strings"
10+
)
11+
12+
type Env struct {
13+
Name string
14+
Value string
15+
}
16+
17+
type DriveInfo struct {
18+
Name string
19+
Type uint32
20+
}
21+
22+
const (
23+
DRIVE_UNKNOWN = 0
24+
DRIVE_NO_ROOT_DIR = 1
25+
DRIVE_REMOVABLE = 2
26+
DRIVE_FIXED = 3
27+
DRIVE_REMOTE = 4
28+
DRIVE_CDROM = 5
29+
DRIVE_RAMDISK = 6
30+
)
31+
32+
// GetEnvironmentVariables return a list of environment variables in []Env slice
33+
func GetEnvironmentVariables() (environmentVariables []Env) {
34+
for _, item := range os.Environ() {
35+
envPair := strings.SplitN(item, "=", 2)
36+
env := Env{
37+
Name: envPair[0],
38+
Value: envPair[1],
39+
}
40+
environmentVariables = append(environmentVariables, env)
41+
}
42+
43+
return environmentVariables
44+
}
45+
46+
// ListFilesRecursively returns a list of files in the specified path and its subdirectories
47+
func ListFilesRecursively(path string) *[]string {
48+
var files []string
49+
50+
err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
51+
if err != nil {
52+
LogMessage(LOG_ERROR, "[ERROR]", err)
53+
return filepath.SkipDir
54+
}
55+
56+
if !f.IsDir() {
57+
files = append(files, path)
58+
}
59+
return nil
60+
})
61+
62+
if err != nil {
63+
LogMessage(LOG_ERROR, "[ERROR]", err)
64+
}
65+
66+
return &files
67+
}
68+
69+
// FileCopy copy the specified file from src to dst path, and eventually encode its content to base64
70+
func FileCopy(src, dst string, base64Encode bool) {
71+
dst += filepath.Base(src) + ".fastfinder"
72+
srcFile, err := os.Open(src)
73+
if err != nil {
74+
log.Fatal(err)
75+
}
76+
defer srcFile.Close()
77+
78+
dstFile, err := os.Create(dst)
79+
if err != nil {
80+
log.Fatal(err)
81+
}
82+
defer dstFile.Close()
83+
84+
if base64Encode {
85+
encoder := base64.NewEncoder(base64.StdEncoding, dstFile)
86+
defer encoder.Close()
87+
88+
_, err = io.Copy(encoder, srcFile)
89+
} else {
90+
_, err = io.Copy(dstFile, srcFile)
91+
}
92+
93+
if err != nil {
94+
log.Fatal(err)
95+
}
96+
}
97+
98+
// Contains checks if a string is contained in a slice of strings
99+
func Contains(s []string, str string) bool {
100+
for _, v := range s {
101+
if v == str {
102+
return true
103+
}
104+
}
105+
106+
return false
107+
}

utils_linux.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build linux
2+
3+
package main
4+
5+
import (
6+
"encoding/base64"
7+
"io"
8+
"log"
9+
"os"
10+
"path/filepath"
11+
"strings"
12+
"syscall"
13+
"unsafe"
14+
)
15+
16+
type Env struct {
17+
Name string
18+
Value string
19+
}
20+
21+
// HideConsoleWindow hide the process console window
22+
func HideConsoleWindow() {
23+
LogMessage(LOG_INFO, "[COMPAT]", "Hide console not implented on linux. You should consider run this program as a task")
24+
}
25+
26+
// CreateMutex creates a named mutex to avoid multiple instance run
27+
func CreateMutex(name string) (uintptr, error) {
28+
return 0, nil
29+
}
30+
31+
// EnumLogicalDrives returns a list of all logical drives letters on the system.
32+
func EnumLogicalDrives() (drivesInfo []DriveInfo) {
33+
return drivesInfo
34+
}

utils.go renamed to utils_windows.go

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,14 @@
1+
//go:build windows
2+
13
package main
24

35
import (
4-
"encoding/base64"
5-
"io"
6-
"log"
7-
"os"
8-
"path/filepath"
9-
"strings"
106
"syscall"
117
"unsafe"
128

139
"golang.org/x/sys/windows"
1410
)
1511

16-
type Env struct {
17-
Name string
18-
Value string
19-
}
20-
21-
type DriveInfo struct {
22-
Name string
23-
Type uint32
24-
}
25-
26-
const (
27-
DRIVE_UNKNOWN = 0
28-
DRIVE_NO_ROOT_DIR = 1
29-
DRIVE_REMOVABLE = 2
30-
DRIVE_FIXED = 3
31-
DRIVE_REMOTE = 4
32-
DRIVE_CDROM = 5
33-
DRIVE_RAMDISK = 6
34-
)
35-
3612
var (
3713
modKernel32 = windows.NewLazySystemDLL("kernel32.dll")
3814
modUser32 = windows.NewLazySystemDLL("user32.dll")
@@ -69,43 +45,6 @@ func CreateMutex(name string) (uintptr, error) {
6945
}
7046
}
7147

72-
// GetEnvironmentVariables return a list of environment variables in []Env slice
73-
func GetEnvironmentVariables() (environmentVariables []Env) {
74-
for _, item := range os.Environ() {
75-
envPair := strings.SplitN(item, "=", 2)
76-
env := Env{
77-
Name: envPair[0],
78-
Value: envPair[1],
79-
}
80-
environmentVariables = append(environmentVariables, env)
81-
}
82-
83-
return environmentVariables
84-
}
85-
86-
// ListFilesRecursively returns a list of files in the specified path and its subdirectories
87-
func ListFilesRecursively(path string) *[]string {
88-
var files []string
89-
90-
err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
91-
if err != nil {
92-
LogMessage(LOG_ERROR, "[ERROR]", err)
93-
return filepath.SkipDir
94-
}
95-
96-
if !f.IsDir() {
97-
files = append(files, path)
98-
}
99-
return nil
100-
})
101-
102-
if err != nil {
103-
LogMessage(LOG_ERROR, "[ERROR]", err)
104-
}
105-
106-
return &files
107-
}
108-
10948
// EnumLogicalDrives returns a list of all logical drives letters on the system.
11049
func EnumLogicalDrives() (drivesInfo []DriveInfo) {
11150
var drives []string
@@ -135,46 +74,6 @@ func EnumLogicalDrives() (drivesInfo []DriveInfo) {
13574
return drivesInfo
13675
}
13776

138-
// FileCopy copy the specified file from src to dst path, and eventually encode its content to base64
139-
func FileCopy(src, dst string, base64Encode bool) {
140-
dst += filepath.Base(src) + ".fastfinder"
141-
srcFile, err := os.Open(src)
142-
if err != nil {
143-
log.Fatal(err)
144-
}
145-
defer srcFile.Close()
146-
147-
dstFile, err := os.Create(dst)
148-
if err != nil {
149-
log.Fatal(err)
150-
}
151-
defer dstFile.Close()
152-
153-
if base64Encode {
154-
encoder := base64.NewEncoder(base64.StdEncoding, dstFile)
155-
defer encoder.Close()
156-
157-
_, err = io.Copy(encoder, srcFile)
158-
} else {
159-
_, err = io.Copy(dstFile, srcFile)
160-
}
161-
162-
if err != nil {
163-
log.Fatal(err)
164-
}
165-
}
166-
167-
// Contains checks if a string is contained in a slice of strings
168-
func Contains(s []string, str string) bool {
169-
for _, v := range s {
170-
if v == str {
171-
return true
172-
}
173-
}
174-
175-
return false
176-
}
177-
17877
// map drive DWORD returned by EnumLogicalDrives to drive letters
17978
func bitsToDrives(bits uint32) (drives []string) {
18079
for i := 0; i < 26; i++ {

0 commit comments

Comments
 (0)