-
Notifications
You must be signed in to change notification settings - Fork 14
/
loldriverscan.go
164 lines (140 loc) · 3.78 KB
/
loldriverscan.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
package main
import (
"encoding/json"
"flag"
"fmt"
pkg "loldriverscan/internal"
"os"
"golang.org/x/sys/windows/svc"
)
const (
lolDriversIoDetailUrl = `https://www.loldrivers.io/drivers/`
headerArt = `
_ _ _____ _ _____
| | | | __ \ (_) / ____|
| | ___ | | | | |_ __ ___ _____ _ _| (___ ___ __ _ _ __
| | / _ \| | | | | '__| \ \ / / _ \ '__\___ \ / __/ _' | '_ \
| |___| (_) | | |__| | | | |\ V / __/ | ____) | (_| (_| | | | |
|______\___/|_|_____/|_| |_| \_/ \___|_| |_____/ \___\__,_|_| |_|
FourCore.io
`
)
var (
Version string = "v1.0"
)
func main() {
verbosePtr := flag.Bool("v", false, "Enable verbose mode")
jsonOutputPtr := flag.String("json", "", "Use - for stdout or a filepath to save to the file")
versionPtr := flag.Bool("version", false, "version details")
flag.Parse()
verbose := *verbosePtr
jsonOutput := *jsonOutputPtr
printVersion := *versionPtr
if printVersion {
fmt.Println(Version)
return
}
if jsonOutput == "" {
fmt.Println(headerArt)
}
svcMgr, err := pkg.ConnectToServiceManager()
if err != nil {
panic(err)
}
driverServices, err := pkg.ListDriverServices(svcMgr)
if err != nil {
panic(err)
}
lolDriversList, err := pkg.CreateVulnerableDriverFinder()
if err != nil {
panic(err)
}
loldrivers := []pkg.LolDriver{}
for _, svcName := range driverServices {
dSvc, err := pkg.OpenService(svcMgr, svcName)
if err != nil {
if verbose {
fmt.Printf("[-] Cannot open service %v: %v\n", svcName, err)
}
continue
}
svcConf, err := dSvc.Config()
if err != nil {
if verbose {
fmt.Printf("[-] Cannot fetch service config for %v: %v\n", svcName, err)
}
continue
}
if svcConf.BinaryPathName == "" {
if verbose {
fmt.Printf("[-] No service binary present for %v\n", svcName)
}
continue
}
normalisedDriverPath, err := pkg.HeuristicNormalisePath(svcConf.BinaryPathName)
if err != nil {
if verbose {
fmt.Printf("[-] Cannot normalize driver path for %v (Path: %v): %v\n", svcName, svcConf.BinaryPathName, err)
}
continue
}
authentihashes, err := pkg.GetAuthentihash(normalisedDriverPath)
if err != nil {
if verbose {
fmt.Printf("[-] Cannot compute sha256 hash for %v: %v\n", normalisedDriverPath, err)
}
continue
}
hashes, err := pkg.HashFile(normalisedDriverPath)
if err != nil {
if verbose {
fmt.Printf("[-] Cannot compute sha256 hash for %v: %v\n", normalisedDriverPath, err)
}
continue
}
driver, err := lolDriversList.FindDriver(hashes, authentihashes)
if err != nil {
continue
}
driver.Path = normalisedDriverPath
driver.ID = lolDriversIoDetailUrl + driver.ID
if status, err := dSvc.Query(); err != nil {
driver.Status = "Unknown"
} else {
switch status.State {
case svc.Running:
driver.Status = "Running"
case svc.Stopped:
driver.Status = "Stopped"
case svc.Paused:
driver.Status = "Paused"
case svc.StartPending:
driver.Status = "Start Pending"
case svc.StopPending:
driver.Status = "Stop Pending"
default:
driver.Status = "Unknown"
}
}
loldrivers = append(loldrivers, driver)
}
if len(loldrivers) == 0 {
fmt.Println("[+]No vulnerable drivers found")
} else {
if jsonOutput == "" {
pkg.PrintLolDrivers(loldrivers)
} else {
jsonData, err := json.MarshalIndent(loldrivers, "", " ")
if err != nil {
panic(fmt.Sprintf("cannot marshal json data: %v", err))
}
if jsonOutput == "-" {
fmt.Println(string(jsonData))
} else {
if err := os.WriteFile(jsonOutput, jsonData, 0644); err != nil {
panic(fmt.Sprintf("error writing to json file %v: %v", jsonOutput, err))
}
}
}
}
}