Skip to content

Commit 3f9365a

Browse files
committed
Add common checks function
1 parent 92ff17e commit 3f9365a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

vmdetect/common.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package vmdetect
33
import (
44
"bufio"
55
"fmt"
6+
"github.com/klauspost/cpuid"
67
"io"
78
"os"
89
"strings"
@@ -48,3 +49,15 @@ func DoesFileContain(file *os.File, stringsToBeFound ...string) bool {
4849
}
4950
}
5051
}
52+
53+
/*
54+
Tries to detect VMs using cross-platform techniques.
55+
*/
56+
func CommonChecks() (bool, string) {
57+
// https://lwn.net/Articles/301888/
58+
if cpuid.CPU.VM() {
59+
return true, "CPU Vendor (cpuid space)"
60+
}
61+
62+
return false, "nothing"
63+
}

vmdetect/linux.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package vmdetect
44

55
import (
66
"bytes"
7-
"github.com/klauspost/cpuid"
87
"io/ioutil"
98
"os"
109
"os/user"
@@ -175,9 +174,8 @@ func IsRunningInVirtualMachine() (bool, string) {
175174
PrintWarning("Unprivileged user detected, some techniques might not work")
176175
}
177176

178-
// https://lwn.net/Articles/301888/
179-
if cpuid.CPU.VM() {
180-
return true, "CPU Vendor (cpuid space)"
177+
if vmDetected, how := CommonChecks(); vmDetected {
178+
return vmDetected, how
181179
}
182180

183181
if checkKernelModules() {

0 commit comments

Comments
 (0)