/
Mover.go
63 lines (57 loc) · 2.03 KB
/
Mover.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
// This file is part of OpenRansim.
//
// Foobar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
const mover_folder = "MoverTest"
const new_mover_folder = "MoverTest_2"
var mover_key string
var MoverCmd = &cobra.Command{
Use: "mover",
Short: "Encrypts the data in a different folder than the original one and deletes the original",
Long: `Encrypts the data in a different folder than the original one and deletes the original`,
PreRun: func(cmd *cobra.Command, args []string) {
create_folder(mover_folder)
create_folder(new_mover_folder)
create_files(mover_folder, num_files)
mover_key = generate_rsa_key()
},
RunE: func(cmd *cobra.Command, args []string) error {
files := get_files(mover_folder)
for _, file := range files {
file_name := fmt.Sprintf(pwd+"/%s/%s", mover_folder, file.Name())
text, err := read_from_file(file_name)
check(err)
ciphertext := encrypt_aes(string(text), mover_key)
new_file_name := fmt.Sprintf(pwd+"/%s/%s", new_mover_folder, file.Name())
write_to_file(ciphertext, new_file_name)
remove(file_name)
}
remove(fmt.Sprintf(pwd+"/%s", mover_folder))
return nil
},
PostRun: func(cmd *cobra.Command, args []string) {
files := get_files(new_mover_folder)
if len(files) == num_files {
fmt.Println("Vulnerable!!!")
} else {
fmt.Println("Passed :)")
}
remove_all(fmt.Sprintf(pwd+"/%s", new_mover_folder))
remove_all(fmt.Sprintf(pwd+"/%s", mover_folder))
},
}