@@ -20,15 +20,15 @@ import (
20
20
// WindowsFileSystemAnalysisRoutine analyse windows filesystem every 300 seconds
21
21
func WindowsFileSystemAnalysisRoutine (pQuarantine string , pKill bool , pAggressive bool , pNotifications bool , pVerbose bool , rules * yara.Rules ) {
22
22
for true {
23
- env := ListEnvironmentPathFiles ()
24
- temp := ListTemporaryFiles ()
23
+ env := ListEnvironmentPathFiles (pVerbose )
24
+ temp := ListTemporaryFiles (pVerbose )
25
25
26
26
for _ , p := range env {
27
- FileAnalysis (p , pQuarantine , pKill , pAggressive , pNotifications , pVerbose , rules )
27
+ FileAnalysis (p , pQuarantine , pKill , pAggressive , pNotifications , pVerbose , rules , "ENV" )
28
28
}
29
29
30
30
for _ , p := range temp {
31
- FileAnalysis (p , pQuarantine , pKill , pAggressive , pNotifications , pVerbose , rules )
31
+ FileAnalysis (p , pQuarantine , pKill , pAggressive , pNotifications , pVerbose , rules , "TEMP" )
32
32
}
33
33
34
34
time .Sleep (300 * time .Second )
@@ -38,19 +38,19 @@ func WindowsFileSystemAnalysisRoutine(pQuarantine string, pKill bool, pAggressiv
38
38
// UserFileSystemAnalysisRoutine analyse windows filesystem every 60 seconds
39
39
func UserFileSystemAnalysisRoutine (pQuarantine string , pKill bool , pAggressive bool , pNotifications bool , pVerbose bool , rules * yara.Rules ) {
40
40
for true {
41
- files := ListUserWorkspaceFiles ()
41
+ files := ListUserWorkspaceFiles (pVerbose )
42
42
43
43
for _ , p := range files {
44
- FileAnalysis (p , pQuarantine , pKill , pAggressive , pNotifications , pVerbose , rules )
44
+ FileAnalysis (p , pQuarantine , pKill , pAggressive , pNotifications , pVerbose , rules , "USER" )
45
45
}
46
46
time .Sleep (60 * time .Second )
47
47
}
48
48
}
49
49
50
50
// ListUserWorkspaceFiles recursively list all files in USERPROFILE directory
51
- func ListUserWorkspaceFiles () (files []string ) {
52
- f , err := RetrivesFilesFromUserPath (os .Getenv ("USERPROFILE" ), true , defaultScannedFileExtensions , true )
53
- if err != nil {
51
+ func ListUserWorkspaceFiles (verbose bool ) (files []string ) {
52
+ f , err := RetrivesFilesFromUserPath (os .Getenv ("USERPROFILE" ), true , defaultScannedFileExtensions , true , verbose )
53
+ if err != nil && verbose {
54
54
log .Println (err )
55
55
}
56
56
@@ -61,20 +61,20 @@ func ListUserWorkspaceFiles() (files []string) {
61
61
}
62
62
63
63
// FileAnalysis sub-routine for file analysis (used in registry / task scheduler / startmenu scan)
64
- func FileAnalysis (path string , pQuarantine string , pKill bool , pAggressive bool , pNotifications bool , pVerbose bool , rules * yara.Rules ) {
64
+ func FileAnalysis (path string , pQuarantine string , pKill bool , pAggressive bool , pNotifications bool , pVerbose bool , rules * yara.Rules , sourceIndex string ) {
65
65
var err error
66
66
var content []byte
67
67
var result yara.MatchRules
68
68
69
69
content , err = ioutil .ReadFile (path )
70
- if err != nil {
70
+ if err != nil && pVerbose {
71
71
log .Println (path , err )
72
72
}
73
73
74
74
fileHash := fmt .Sprintf ("%x" , md5 .Sum (content ))
75
75
if ! StringInSlice (fileHash , filescanHistory ) {
76
76
if pVerbose {
77
- log .Println ("[INFO] Analyzing" , path )
77
+ log .Println ("[INFO] [" + sourceIndex + "] Analyzing" , path )
78
78
}
79
79
80
80
result , err = YaraScan (content , rules )
@@ -86,14 +86,14 @@ func FileAnalysis(path string, pQuarantine string, pKill bool, pAggressive bool,
86
86
87
87
// logging
88
88
for _ , match := range result {
89
- log .Println ("[INFO ]" , "YARA MATCH" , path , match .Namespace , match .Rule )
89
+ log .Println ("[ALERT ]" , "YARA MATCH" , path , match .Namespace , match .Rule )
90
90
}
91
91
92
92
// dump matching process to quarantine
93
93
if len (pQuarantine ) > 0 {
94
94
log .Println ("[INFO]" , "DUMPING FILE" , path )
95
95
err := QuarantineFile (content , filepath .Base (path ), pQuarantine )
96
- if err != nil && pVerbose {
96
+ if err != nil {
97
97
log .Println ("[ERROR]" , "Cannot quarantine file" , path , err )
98
98
}
99
99
}
@@ -105,12 +105,12 @@ func FileAnalysis(path string, pQuarantine string, pKill bool, pAggressive bool,
105
105
}
106
106
107
107
// ListEnvironmentPathFiles list all files in PATH directories
108
- func ListEnvironmentPathFiles () (files []string ) {
108
+ func ListEnvironmentPathFiles (verbose bool ) (files []string ) {
109
109
env := os .Getenv ("PATH" )
110
110
paths := strings .Split (env , ";" )
111
111
for _ , p := range paths {
112
- f , err := RetrivesFilesFromUserPath (p , true , defaultScannedFileExtensions , false )
113
- if err != nil {
112
+ f , err := RetrivesFilesFromUserPath (p , true , defaultScannedFileExtensions , false , verbose )
113
+ if err != nil && verbose {
114
114
log .Println (err )
115
115
continue
116
116
}
@@ -124,7 +124,7 @@ func ListEnvironmentPathFiles() (files []string) {
124
124
}
125
125
126
126
// ListTemporaryFiles list all files in TEMP / TMP / %SystemRoot%\Temp
127
- func ListTemporaryFiles () (files []string ) {
127
+ func ListTemporaryFiles (verbose bool ) (files []string ) {
128
128
129
129
var folders = []string {os .Getenv ("TEMP" )}
130
130
if os .Getenv ("TMP" ) != os .Getenv ("TEMP" ) {
@@ -136,8 +136,8 @@ func ListTemporaryFiles() (files []string) {
136
136
}
137
137
138
138
for _ , p := range folders {
139
- f , err := RetrivesFilesFromUserPath (p , true , defaultScannedFileExtensions , true )
140
- if err != nil {
139
+ f , err := RetrivesFilesFromUserPath (p , true , defaultScannedFileExtensions , true , verbose )
140
+ if err != nil && verbose {
141
141
log .Println (err )
142
142
continue
143
143
}
@@ -190,7 +190,7 @@ func FormatPathFromComplexString(command string) (paths []string) {
190
190
}
191
191
192
192
// RetrivesFilesFromUserPath return a []string of available files from given path (includeFileExtensions is available only if listFiles is true)
193
- func RetrivesFilesFromUserPath (path string , listFiles bool , includeFileExtensions []string , recursive bool ) ([]string , error ) {
193
+ func RetrivesFilesFromUserPath (path string , listFiles bool , includeFileExtensions []string , recursive bool , verbose bool ) ([]string , error ) {
194
194
var p []string
195
195
196
196
info , err := os .Stat (path )
@@ -213,8 +213,8 @@ func RetrivesFilesFromUserPath(path string, listFiles bool, includeFileExtension
213
213
}
214
214
} else {
215
215
err := filepath .Walk (path , func (walk string , info os.FileInfo , err error ) error {
216
- if err != nil {
217
- log .Println (err )
216
+ if err != nil && verbose {
217
+ log .Println ("[ERROR]" , err )
218
218
}
219
219
220
220
if err == nil && ! (info .IsDir () == listFiles ) && (len (includeFileExtensions ) == 0 || StringInSlice (filepath .Ext (walk ), includeFileExtensions )) {
@@ -224,8 +224,8 @@ func RetrivesFilesFromUserPath(path string, listFiles bool, includeFileExtension
224
224
return nil
225
225
})
226
226
227
- if err != nil {
228
- log .Println (err )
227
+ if err != nil && verbose {
228
+ log .Println ("[ERROR]" , err )
229
229
}
230
230
}
231
231
}
0 commit comments