Skip to content

Commit 6ae2983

Browse files
committed
Add vbox kernel module detection
1 parent 64717d6 commit 6ae2983

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

vmdetect/common.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func DoesFileExist(path string) bool {
2626
return !os.IsNotExist(err)
2727
}
2828

29-
func DoesFileContain(file *os.File, stringToBeFound string) bool {
29+
func DoesFileContain(file *os.File, stringsToBeFound ...string) bool {
3030
reader := bufio.NewReader(file)
3131

3232
for {
@@ -41,8 +41,10 @@ func DoesFileContain(file *os.File, stringToBeFound string) bool {
4141
return false
4242
}
4343

44-
if strings.Contains(line, stringToBeFound) {
45-
return true
44+
for _, stringToBeFound := range stringsToBeFound {
45+
if strings.Contains(line, stringToBeFound) {
46+
return true
47+
}
4648
}
4749
}
4850
}

vmdetect/linux.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ func checkXenProcFile() bool {
153153
return DoesFileExist("/proc/xen")
154154
}
155155

156+
func checkKernelModules() bool {
157+
158+
file, err := os.Open("/proc/modules")
159+
160+
if err != nil {
161+
PrintError(err)
162+
return false
163+
}
164+
165+
return DoesFileContain(file, "vboxguest")
166+
}
167+
156168
/*
157169
Public function returning true if a VM is detected.
158170
If so, a non-empty string is also returned to tell how it was detected.
@@ -168,6 +180,10 @@ func IsRunningInVirtualMachine() (bool, string) {
168180
return true, "CPU Vendor (cpuid space)"
169181
}
170182

183+
if checkKernelModules() {
184+
return true, "Kernel module (/proc/modules)"
185+
}
186+
171187
if checkUML() {
172188
return true, "CPU Vendor (/proc/cpuinfo)"
173189
}

0 commit comments

Comments
 (0)