-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileScanner.go
More file actions
77 lines (65 loc) · 1.61 KB
/
Copy pathFileScanner.go
File metadata and controls
77 lines (65 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
)
// Database for all Clients
var clientDB = map[string]string{
"VapeV4": "17da27502307d04049ae11abac77bbcc14cf9a35dd54d879930b528ba4b9384f",
}
func calculateSHA256(fileData []byte) (string, error) {
hash := sha256.New()
_, err := hash.Write(fileData)
if err != nil {
return "", err
}
return hex.EncodeToString(hash.Sum(nil)), nil
}
func detectClient(filePath string) (string, bool) {
fileData, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Printf("Error reading file: %s\n", err)
return "", false
}
fileSHA256, err := calculateSHA256(fileData)
if err != nil {
fmt.Printf("Error calculating SHA256 hash: %s\n", err)
return "", false
}
for clientName, clientHash := range clientDB {
if fileSHA256 == clientHash {
return clientName, true
}
}
return "", false
}
func scanDirectory(dirPath string) {
startTime := time.Now()
filesScanned := 0
err := filepath.Walk(dirPath, func(filePath string, info os.FileInfo, err error) error {
if err != nil {
fmt.Printf("Error accessing file: %s\n", err)
return nil
}
if !info.IsDir() {
clientName, isInfected := detectClient(filePath)
if isInfected {
fmt.Printf("Clients Detected: %s (%s)\n", filePath, clientName)
}
filesScanned++
}
return nil
})
if err != nil {
fmt.Printf("Error scanning directory: %s\n", err)
}
elapsed := time.Since(startTime)
filesPerSecond := float64(filesScanned) / elapsed.Seconds()
fmt.Printf("Scan took: %s\n", elapsed)
fmt.Printf("Files scanned per second: %.2f\n", filesPerSecond)
}