Skip to content

Commit

Permalink
Retrieve Windows UUID from Registry
Browse files Browse the repository at this point in the history
  • Loading branch information
usiegl00 committed Feb 7, 2021
1 parent fe43536 commit dce29eb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions sliver/hostuuid/uuid_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ package hostuuid
*/

import (
"bytes"
"os/exec"
"golang.org/x/sys/windows/registry"
)

// Stored Format: {U-U-I-D}
const uuid_keypath = "HKEY_LOCAL_MACHINE\\SYSTEM\\HardwareConfig"
const uuid_key = "LastConfig"

func GetUUID() string {
cmd := exec.Command("wmic.exe", "csproduct", "get", "UUID")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
key, err := registry.OpenKey(registry.CURRENT_USER, uuid_keypath, registry.QUERY_VALUE)
if err != nil {
return ""
}

str, _, err := key.GetStringValue(uuid_key)
if err != nil {
return ""
}
str := out.String()
return str[41:77]

return str[1:37]
}

0 comments on commit dce29eb

Please sign in to comment.