Skip to content

Commit 8331d57

Browse files
committed
Initial release
1 parent dbf492f commit 8331d57

14 files changed

+714
-2
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Jean-Pierre GARNIER
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
[![Project Status](https://img.shields.io/badge/status-BETA-yellow?style=flat-square)]()
21
# _FastFinder_ - Incident Response - Fast suspicious file finder
32

43
## What is this project designed for?
@@ -29,7 +28,7 @@ Depending on where you are looking for files, _FastFinder_ could be used with ad
2928
a configuration file example is available [here](configuration.yaml.example) in this repository
3029
```
3130
input:
32-
path: [] # match file path AND / OR file name based on simple string ('?' and '*' wildcards are available for simple string) OR regular expression (regex have to be enclosed by "/<regex>/")
31+
path: [] # match file path AND / OR file name based on simple string
3332
content:
3433
grep: [] # match literal string value inside file contente
3534
yara: [] # use yara rule and specify rules path(s) for more complex pattern search (wildcards / regex / conditions)
@@ -41,6 +40,13 @@ output:
4140
base64Files: true # base64 matched content before copy
4241
filesCopyPath: '' # empty value will copy matched files in the fastfinder.exe folder
4342
```
43+
### Note for input path:
44+
* '?' for simple char and '\*' for multiple chars wildcards are available for simple string
45+
* environment variables are also available
46+
* regular expression are allowed , they should be enclosed by /<regex>/
47+
* input path are always case INSENSITIVE
48+
* input content grep strings are always case SENSITIVE
49+
* backslashes haven't to be escaped on simple string pattern (see example)
4450

4551
## About this project and future versions
4652
I initially created this project to automate the creation of fastfind on a wide computer network.

README.windows-compilation.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
# Installing _FastFinder_ on Windows
3+
4+
_FastFinder_ is design for Windows platform but it's a little bit tricky because it's strongly dependant of go-yara and CGO. Here's a little step by step guide:
5+
6+
## Before installation
7+
8+
All the installation process will be done with msys2/mingw terminal. In order to avoid any error, you have to ensure that your installation directories don't contains space or special characters. I haven't tested to install as a simple user, I strongly advise you to install everything with admin privileges on top of your c:\ drive.
9+
10+
For the configurations and examples below, my install paths are:
11+
12+
* GO: c:\Go
13+
* GOPATH: C:\Users\myuser\go
14+
* Msys2: c:\msys64
15+
* Git: c:\Git
16+
17+
## Install msys2 and dependencies:
18+
19+
First of all, note that you won't be able to get _FastFinder_ working if the dependencies are compiled with another compiler than GCC. There is currently some problems with CGO when external libraries are compiled with Visual C++, so no need to install Visual Studio or vcpkg.
20+
21+
* Download msys2 [from the official website](https://www.msys2.org/) and install it
22+
* there, you will find two distincts binaries shorcut "MSYS2 MSYS" and "MSYS2 MinGW 64bits". Please launch this second one.
23+
* install dependencies with the following command line: `pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-pkg-config base-devel openssl-devel`
24+
* add environment variables in mingw terminal: `export PATH=$PATH:/c/Go/bin:/c/msys64/mingw64/bin:/c/Git/bin`
25+
26+
## Download and compile libyara
27+
28+
It's strongly advised NOT to clone VirusTotal's YARA repository but to download the source code of the latest release. If you compile libyara from the latest commit, it could generate some side effects when linking this library with _FastFinder_ and GCO.
29+
30+
* download latest VirusTotal release source code [from here](https://github.com/VirusTotal/yara/releases)
31+
* unzip the folder in a directory without space and special char
32+
* in mingw terminal, go to yara directory (backslash have to be replace with slash eg. cd c:/yara)
33+
* compile and install using the following command: `./bootstrap.sh &&./configure && make && make install`
34+
35+
## Configure your OS
36+
37+
With this step, you won't need to use mingw terminal anymore and you will be able to use Go to install _FastFinder_ and compile your projects directly from Windows cmd / powershell.
38+
39+
Make sure you have the following as system environment variables (not user env vars). If not, create them:
40+
```
41+
GOARCH=<your-architecture> (eg. amd64)
42+
GOOS=windows
43+
CGO_CFLAGS=-IC:/msys64/mingw64/include
44+
CGO_LDFLAGS=-LC:/msys64/mingw64/lib -lyara -lcrypto
45+
PKG_CONFIG_PATH=C:/msys64/mingw64/lib/pkgconfig
46+
```
47+
You also need C:\msys64\mingw64\bin in your system PATH env vars.
48+
49+
Make sure you have got the following user environment var (not system var):
50+
51+
GOPATH=%USERPROFILE%\go
52+
53+
Note that paths must be written with slashs and not backslash. As already said, don't use path with spaces or special characters.
54+
55+
## Download, Install and compile FastFinder
56+
Now, from Windows cmd or Powershell, you can install _FastFinder_: `go get github.com/codeyourweb/fastfinder`
57+
Compilation should be done with: `go build -tags yara_static -a -ldflags '-extldflags "-static"' .`

configuration.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"log"
6+
"regexp"
7+
"strings"
8+
9+
"gopkg.in/yaml.v2"
10+
)
11+
12+
type Configuration struct {
13+
Input Input `yaml:"input"`
14+
Options Options `yaml:"options"`
15+
Output Output `yaml:"output"`
16+
}
17+
18+
type Input struct {
19+
Path []string `yaml:"path"`
20+
Content Content `yaml:"content"`
21+
}
22+
23+
type Content struct {
24+
Grep []string `yaml:"grep"`
25+
Yara []string `yaml:"yara"`
26+
}
27+
28+
type Options struct {
29+
FindInHardDrives bool `yaml:"findInHardDrives"`
30+
FindInRemovableDrives bool `yaml:"findInRemovableDrives"`
31+
FindInNetworkDrives bool `yaml:"findInNetworkDrives"`
32+
}
33+
34+
type Output struct {
35+
Base64Files bool `yaml:"base64Files"`
36+
FilesCopyPath string `yaml:"filesCopyPath"`
37+
}
38+
39+
func (c *Configuration) getConfiguration(configFile string) *Configuration {
40+
41+
yamlFile, err := ioutil.ReadFile(configFile)
42+
if err != nil {
43+
log.Fatalf("Configuration file reading error #%v ", err)
44+
}
45+
err = yaml.Unmarshal(yamlFile, c)
46+
if err != nil {
47+
log.Fatalf("Configuration file parsing error: %v", err)
48+
}
49+
50+
environmentVariables := getEnvironmentVariables()
51+
52+
for i := 0; i < len(c.Input.Path); i++ {
53+
// replace environment variables
54+
for _, env := range environmentVariables {
55+
if strings.Contains(strings.ToLower(c.Input.Path[i]), "%"+strings.ToLower(env.Name)+"%") {
56+
c.Input.Path[i] = strings.Replace(c.Input.Path[i], "%"+env.Name+"%", env.Value, -1)
57+
}
58+
}
59+
60+
// handle regex and simple find strings
61+
if c.Input.Path[i][0] != '/' || c.Input.Path[i][len(c.Input.Path[i])-1] != '/' {
62+
c.Input.Path[i] = regexp.QuoteMeta(strings.ToLower(c.Input.Path[i]))
63+
// use regular expression ".+" for "*" search pattern
64+
if strings.Contains(strings.ToLower(c.Input.Path[i]), "\\\\\\*") {
65+
c.Input.Path[i] = strings.Replace(c.Input.Path[i], "\\\\\\*", ".+", -1)
66+
}
67+
68+
if strings.Contains(strings.ToLower(c.Input.Path[i]), "\\?") {
69+
c.Input.Path[i] = strings.Replace(c.Input.Path[i], "\\?", ".", -1)
70+
}
71+
} else {
72+
c.Input.Path[i] = strings.Trim(c.Input.Path[i], "/")
73+
}
74+
75+
}
76+
77+
return c
78+
}

configuration.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
input:
2+
path: []
3+
content:
4+
grep: []
5+
yara: []
6+
options:
7+
findInHardDrives: true
8+
findInRemovableDrives: true
9+
findInNetworkDrives: true
10+
output:
11+
base64Files: true
12+
filesCopyPath: ''

configuration.yaml.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
input:
2+
path:
3+
- '%APPDATA%\\*.exe'
4+
- '%TEMP%\\*.exe'
5+
- 'Windows\SysWOW64\c?d.exe'
6+
- 'Windows\System32\notepad\*'
7+
- '/temp\\{[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12}\}\\\w+\.exe$/'
8+
content:
9+
grep:
10+
- 'This program cannot be run in DOS mode'
11+
yara:
12+
- './example.yar'
13+
options:
14+
findInHardDrives: true
15+
findInRemovableDrives: false
16+
findInNetworkDrives: false
17+
output:
18+
base64Files: true
19+
filesCopyPath: ''

example.yar

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rule example{
2+
strings:
3+
$a = "This program cannot be run in DOS mode"
4+
condition:
5+
all of them and uint16(0) == 0x5a4d
6+
}

finder.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"log"
6+
"regexp"
7+
"strings"
8+
)
9+
10+
func pathsFinder(files []string, patterns []string) (matchingFiles []string) {
11+
for _, expression := range patterns {
12+
for _, f := range files {
13+
if match, _ := regexp.MatchString(`(?i)`+expression, f); match {
14+
matchingFiles = append(matchingFiles, f)
15+
}
16+
}
17+
}
18+
19+
return matchingFiles
20+
}
21+
22+
func findInFiles(files []string, patterns []string) (matchingFiles []string) {
23+
for _, f := range files {
24+
25+
b, err := ioutil.ReadFile(f)
26+
if err != nil {
27+
log.Println("Unable to read", f)
28+
continue
29+
}
30+
31+
for _, expression := range patterns {
32+
if strings.Contains(string(b), expression) {
33+
if !contains(matchingFiles, f) {
34+
matchingFiles = append(matchingFiles, f)
35+
}
36+
}
37+
}
38+
}
39+
40+
return matchingFiles
41+
}

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/codeyourweb/fastfinder
2+
3+
go 1.17
4+
5+
require (
6+
github.com/akamensky/argparse v1.3.1
7+
github.com/gen2brain/go-unarr v0.1.2
8+
github.com/h2non/filetype v1.1.3
9+
github.com/hillu/go-yara/v4 v4.1.0
10+
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881
11+
gopkg.in/yaml.v2 v2.4.0
12+
)

go.sum

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
github.com/akamensky/argparse v1.3.1 h1:kP6+OyvR0fuBH6UhbE6yh/nskrDEIQgEA1SUXDPjx4g=
2+
github.com/akamensky/argparse v1.3.1/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
3+
github.com/gen2brain/go-unarr v0.1.2 h1:17kYZ2WMCVFrnmU4A+7BeFXblIOyE8weqggjay+kVIU=
4+
github.com/gen2brain/go-unarr v0.1.2/go.mod h1:P05CsEe8jVEXhxqXqp9mFKUKFV0BKpFmtgNWf8Mcoos=
5+
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
6+
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
7+
github.com/hillu/go-yara/v4 v4.1.0 h1:ZLT9ar+g5r1IgEp1QVYpdqYCgKMNm7DuZYUJpHZ3yUI=
8+
github.com/hillu/go-yara/v4 v4.1.0/go.mod h1:rkb/gSAoO8qcmj+pv6fDZN4tOa3N7R+qqGlEkzT4iys=
9+
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 h1:TyHqChC80pFkXWraUUf6RuB5IqFdQieMLwwCJokV2pc=
10+
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
12+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
13+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
14+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

0 commit comments

Comments
 (0)