Import Anubis v1.28.2

Replace the tree with upstream TecharoHQ/anubis v1.28.2 (a1384fbf42e3).
Masyunis customizations are re-applied in the following commits.
This commit is contained in:
sol_bot Bot committed 2026-11-28 14:52:26 +03:00
1 parent eb3e46d8d0
commit e07de898cd
573 files changed
+35846 -6807

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
package servicesid
import (
"crypto/sha1"
"encoding/binary"
"fmt"
"strings"
"unicode/utf16"
)
// serviceSIDPrefix is the identifier authority Windows files per-service SIDs
// under. Everything below it is derived from the service name.
const serviceSIDPrefix = "S-1-5-80"
// anubisServiceName is the name the MSI registers the service under. It is the
// input to the SID derivation below, so it has to match ServiceInstall/@Name in
// run/windows/anubis.wxs exactly, case aside.
const AnubisServiceName = "Anubis"
// anubisServiceSID is the SID of the NT SERVICE\Anubis virtual account the
// service runs as, spelled out rather than computed so that the value the
// installer grants access to is visible in a diff and pinned by a test.
const AnubisServiceSID = "S-1-5-80-765274699-3418405142-632509039-2036741013-1444054785"
// Encode returns the SID of the NT SERVICE account belonging to a Windows
// service, in the string form icacls and the rest of Windows accept.
//
// Windows derives these rather than allocating them: it uppercases the service
// name, encodes it as UTF-16LE, takes the SHA-1 of that, and appends the digest
// to S-1-5-80 as five little-endian uint32 subauthorities. The service does not
// have to exist for the SID to be meaningful, which is what lets the installer
// grant access to the config directory before the service is registered.
//
// The SHA-1 here is Windows' choice of construction, not a security decision of
// ours. Any other hash would produce a SID that names nothing.
//
// This lives outside service_windows.go on purpose. Nothing in the build or in
// CI runs Windows, so anything behind that build constraint is compiled and
// never executed; keeping the arithmetic portable is what makes it testable.
func Encode(name string) string {
encoded := utf16.Encode([]rune(strings.ToUpper(name)))
buf := make([]byte, 2*len(encoded))
for i, unit := range encoded {
binary.LittleEndian.PutUint16(buf[2*i:], unit)
}
sum := sha1.Sum(buf)
var sb strings.Builder
sb.WriteString(serviceSIDPrefix)
for i := 0; i < len(sum); i += 4 {
fmt.Fprintf(&sb, "-%d", binary.LittleEndian.Uint32(sum[i:]))
}
return sb.String()
}
+44
View File
@@ -0,0 +1,44 @@
package servicesid
import "testing"
func TestServiceSID(t *testing.T) {
for _, tt := range []struct {
name string
service string
want string
}{
{
// TrustedInstaller ships with Windows and its SID is published in
// enough places to serve as a known-answer test for the whole
// derivation. If this case fails, the arithmetic is wrong.
name: "TrustedInstaller matches the published SID",
service: "TrustedInstaller",
want: "S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",
},
{
// Pins the hardcoded constant to the derivation. Renaming the
// service without recomputing the SID fails here rather than on a
// Windows box, where it would surface as the service being unable
// to read its own configuration.
name: "the pinned Anubis SID is the derived one",
service: AnubisServiceName,
want: AnubisServiceSID,
},
{
// The name is uppercased before hashing, so case in the service
// name must not reach the digest.
name: "case in the service name does not matter",
service: "aNuBiS",
want: AnubisServiceSID,
},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := Encode(tt.service); got != tt.want {
t.Errorf("Encode(%q) = %q, want %q", tt.service, got, tt.want)
}
})
}
}