Skip to content

Commit 03ba0ea

Browse files
committed
Return zero guid on hostuuid from mac error
1 parent 42a4e93 commit 03ba0ea

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

implant/sliver/hostuuid/uuid.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import (
3131
"github.com/gofrs/uuid"
3232
)
3333

34+
var zeroGUID = uuid.Must(uuid.FromString("00000000-0000-0000-0000-000000000000"))
35+
3436
// UUIDFromMAC - Generate a UUID based on the machine's MAC addresses, this is
35-
// generally used as a last resort to fingerpint the host machine. It creates
37+
// generally used as a last resort to fingerprint the host machine. It creates
3638
// a uuid by hashing the MAC addresses of all network interfaces and using the
3739
// first 16 bytes of the hash as the UUID. This should work so long as network
3840
// interfaces are not added or removed, since its physical addresses this should
@@ -43,22 +45,25 @@ func UUIDFromMAC() string {
4345
// {{end}}
4446
interfaces, err := net.Interfaces()
4547
if err != nil {
46-
return ""
48+
return zeroGUID.String()
4749
}
4850
hardwareAddrs := []string{}
4951
for _, iface := range interfaces {
5052
if iface.HardwareAddr != nil {
5153
hardwareAddrs = append(hardwareAddrs, iface.HardwareAddr.String())
5254
}
5355
}
56+
if len(hardwareAddrs) == 0 {
57+
return zeroGUID.String()
58+
}
5459
sort.Strings(hardwareAddrs) // Ensure deterministic order
5560
digest := sha256.New()
5661
for _, addr := range hardwareAddrs {
5762
digest.Write([]byte(addr))
5863
}
5964
value, err := uuid.FromBytes(digest.Sum(nil)[:16]) // Must be 128-bits
6065
if err != nil {
61-
return ""
66+
return zeroGUID.String()
6267
}
6368
return value.String()
6469
}

implant/sliver/hostuuid/uuid_darwin.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// +build darwin
1+
//go:build darwin
22

33
package hostuuid
44

55
/*
6-
Sliver Implant Framework
7-
Copyright (C) 2019 Bishop Fox
6+
Sliver Implant Framework
7+
Copyright (C) 2019 Bishop Fox
88
9-
This program is free software: you can redistribute it and/or modify
10-
it under the terms of the GNU General Public License as published by
11-
the Free Software Foundation, either version 3 of the License, or
12-
(at your option) any later version.
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
1313
14-
This program is distributed in the hope that it will be useful,
15-
but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
GNU General Public License for more details.
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
1818
19-
You should have received a copy of the GNU General Public License
20-
along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
*/
2222

2323
/*

implant/sliver/hostuuid/uuid_linux.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package hostuuid
54

@@ -23,15 +22,15 @@ package hostuuid
2322

2423
import (
2524
"fmt"
26-
"io/ioutil"
25+
"os"
2726
)
2827

2928
// GetUUID - Get a system specific UUID
3029
func GetUUID() string {
31-
uuid, err := ioutil.ReadFile("/etc/machine-id")
30+
uuid, err := os.ReadFile("/etc/machine-id")
3231
// UUID length is 32 plus newline
3332
if err != nil || len(uuid) != 33 {
34-
uuid, err = ioutil.ReadFile("/var/lib/dbus/machine-id")
33+
uuid, err = os.ReadFile("/var/lib/dbus/machine-id")
3534
if err != nil || len(uuid) != 33 {
3635
return UUIDFromMAC() // Failed, try to use MAC addresses
3736
}

0 commit comments

Comments
 (0)