Skip to content

Commit 6a143b6

Browse files
committed
Public release
1 parent 853548f commit 6a143b6

10 files changed

Lines changed: 336 additions & 0 deletions

File tree

.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: p0dalirius
4+
patreon: Podalirius

.github/banner.png

590 KB
Loading
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Auto-prefix & Label Issues
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
7+
jobs:
8+
prefix_and_label:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Ensure labels exist, then prefix titles & add labels
12+
uses: actions/github-script@v6
13+
with:
14+
script: |
15+
const owner = context.repo.owner;
16+
const repo = context.repo.repo;
17+
18+
// 1. Ensure required labels exist
19+
const required = [
20+
{ name: 'bug', color: 'd73a4a', description: 'Something isn\'t working' },
21+
{ name: 'enhancement', color: 'a2eeef', description: 'New feature or request' }
22+
];
23+
24+
// Fetch current labels in the repo
25+
const { data: existingLabels } = await github.rest.issues.listLabelsForRepo({
26+
owner, repo, per_page: 100
27+
});
28+
const existingNames = new Set(existingLabels.map(l => l.name));
29+
30+
// Create any missing labels
31+
for (const lbl of required) {
32+
if (!existingNames.has(lbl.name)) {
33+
await github.rest.issues.createLabel({
34+
owner,
35+
repo,
36+
name: lbl.name,
37+
color: lbl.color,
38+
description: lbl.description
39+
});
40+
console.log(`Created label "${lbl.name}"`);
41+
}
42+
}
43+
44+
// 2. Fetch all open issues
45+
const issues = await github.paginate(
46+
github.rest.issues.listForRepo,
47+
{ owner, repo, state: 'open', per_page: 100 }
48+
);
49+
50+
// 3. Keyword sets
51+
const enhancementWords = ["add", "added", "improve", "improved"];
52+
const bugWords = ["bug", "error", "problem", "crash", "failed", "fix", "fixed"];
53+
54+
// 4. Process each issue
55+
for (const issue of issues) {
56+
const origTitle = issue.title;
57+
const lower = origTitle.toLowerCase();
58+
59+
// skip if already prefixed
60+
if (/^\[(bug|enhancement)\]/i.test(origTitle)) continue;
61+
62+
let prefix, labelToAdd;
63+
if (enhancementWords.some(w => lower.includes(w))) {
64+
prefix = "[enhancement]";
65+
labelToAdd = "enhancement";
66+
} else if (bugWords.some(w => lower.includes(w))) {
67+
prefix = "[bug]";
68+
labelToAdd = "bug";
69+
}
70+
71+
if (prefix) {
72+
// update title
73+
await github.rest.issues.update({
74+
owner, repo, issue_number: issue.number,
75+
title: `${prefix} ${origTitle}`
76+
});
77+
console.log(`Prefixed title of #${issue.number}`);
78+
79+
// add label
80+
await github.rest.issues.addLabels({
81+
owner, repo, issue_number: issue.number,
82+
labels: [labelToAdd]
83+
});
84+
console.log(`Added label "${labelToAdd}" to #${issue.number}`);
85+
}
86+
}

.github/workflows/commit.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build on commit
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
name: Build Release Assets
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
os: [linux, windows, darwin]
16+
arch: [amd64, arm64, 386]
17+
binaryname: [ComputeSIDFromServiceName]
18+
# Exclude incompatible couple of GOOS and GOARCH values
19+
exclude:
20+
- os: darwin
21+
arch: 386
22+
23+
env:
24+
GO111MODULE: 'on'
25+
CGO_ENABLED: '0'
26+
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@v3
30+
31+
- name: Set up Go
32+
uses: actions/setup-go@v4
33+
with:
34+
go-version: '1.24.0'
35+
36+
- name: Build Binary
37+
env:
38+
GOOS: ${{ matrix.os }}
39+
GOARCH: ${{ matrix.arch }}
40+
run: |
41+
mkdir -p build
42+
OUTPUT_PATH="../build/${{ matrix.binaryname }}-${{ matrix.os }}-${{ matrix.arch }}"
43+
# Build the binary
44+
go build -ldflags="-s -w" -o $OUTPUT_PATH${{ matrix.os == 'windows' && '.exe' || '' }}

.github/workflows/release.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
name: Build Release Assets
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
os: [linux, windows, darwin]
15+
arch: [amd64, arm64, 386]
16+
binaryname: [ComputeSIDFromServiceName]
17+
# Exclude incompatible couple of GOOS and GOARCH values
18+
exclude:
19+
- os: darwin
20+
arch: 386
21+
22+
env:
23+
GO111MODULE: 'on'
24+
CGO_ENABLED: '0'
25+
26+
steps:
27+
- name: Checkout Repository
28+
uses: actions/checkout@v3
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v4
32+
with:
33+
go-version: '1.24.0'
34+
35+
- name: Build Binary
36+
env:
37+
GOOS: ${{ matrix.os }}
38+
GOARCH: ${{ matrix.arch }}
39+
run: |
40+
mkdir -p bin
41+
OUTPUT_PATH="../build/${{ matrix.binaryname }}-${{ matrix.os }}-${{ matrix.arch }}"
42+
# Build the binary
43+
go build -ldflags="-s -w" -o $OUTPUT_PATH${{ matrix.os == 'windows' && '.exe' || '' }}
44+
45+
- name: Prepare Release Assets
46+
if: ${{ success() }}
47+
run: |
48+
mkdir -p ./release/
49+
cp ./build/${{ matrix.binaryname }}-* ./release/
50+
51+
- name: Upload the Release binaries
52+
uses: svenstaro/upload-release-action@v2
53+
with:
54+
repo_token: ${{ secrets.GITHUB_TOKEN }}
55+
tag: ${{ github.ref }}
56+
file: ./release/${{ matrix.binaryname }}-*
57+
file_glob: true

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Code coverage profiles and other test artifacts
15+
*.out
16+
coverage.*
17+
*.coverprofile
18+
profile.cov
19+
20+
# Dependency directories (remove the comment below to include it)
21+
# vendor/
22+
23+
# Go workspace file
24+
go.work
25+
go.work.sum
26+
27+
# env file
28+
.env
29+
30+
# Editor/IDE
31+
# .idea/
32+
# .vscode/

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
![](./.github/banner.png)
2+
3+
<p align="center">
4+
A cross-platform tool to compute the value of a Windows Security Identifier (SID) from a service name.
5+
<br>
6+
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/TheManticoreProject/ComputeSIDFromServiceName">
7+
<a href="https://twitter.com/intent/follow?screen_name=podalirius_" title="Follow"><img src="https://img.shields.io/twitter/follow/podalirius_?label=Podalirius&style=social"></a>
8+
<a href="https://www.youtube.com/c/Podalirius_?sub_confirmation=1" title="Subscribe"><img alt="YouTube Channel Subscribers" src="https://img.shields.io/youtube/channel/subscribers/UCF_x5O7CSfr82AfNVTKOv_A?style=social"></a>
9+
<br>
10+
</p>
11+
12+
13+
## Features
14+
15+
- [x] Compute the value of a Windows Security Identifier (SID) from a service name
16+
17+
## Example
18+
19+
```bash
20+
$ ./ComputeSIDFromServiceName -s "MSSQLSERVER"
21+
S-1-5-80-1000-1000-1000-1000-1000
22+
```
23+
24+
## Usage
25+
26+
```
27+
$ ./ComputeSIDFromServiceName -h
28+
Usage: ComputeSIDFromServiceName [--debug] --service-name <string>
29+
30+
-d, --debug Debug mode. (default: false)
31+
-s, --service-name <string> Service name to compute SID from.
32+
```
33+
34+
## Contributing
35+
36+
Pull requests are welcome. Feel free to open an issue if you want to add other features.
37+
38+
## References
39+
- https://pcsxcetrasupport3.wordpress.com/2013/09/08/how-do-you-get-a-service-sid-from-a-service-name/

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/TheManticoreProject/ComputeSIDFromServiceName
2+
3+
go 1.24.0
4+
5+
require github.com/TheManticoreProject/goopts v1.2.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/TheManticoreProject/goopts v1.2.4 h1:HTR+i6ZfcwTPSDltENayQvTH2fZP6cDx0GTBUp/RuPM=
2+
github.com/TheManticoreProject/goopts v1.2.4/go.mod h1:NaM3hXXCeN+x9ZSlkS6Bm8i8Lfqe28/rveBsfrMUrAo=

main.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"crypto/sha1"
5+
"encoding/binary"
6+
"fmt"
7+
"os"
8+
"strings"
9+
"unicode/utf16"
10+
11+
"github.com/TheManticoreProject/goopts/parser"
12+
)
13+
14+
var (
15+
// Configuration
16+
debug bool
17+
18+
// Source values
19+
serviceName string
20+
)
21+
22+
func ComputeSIDFromServiceName(serviceName string) (string, error) {
23+
serviceName = strings.TrimSpace(serviceName)
24+
if serviceName == "" {
25+
return "", fmt.Errorf("service name is required")
26+
}
27+
28+
upper := strings.ToUpper(serviceName)
29+
30+
// Encode as UTF-16LE (Windows "Unicode")
31+
utf16Units := utf16.Encode([]rune(upper))
32+
utf16LE := make([]byte, len(utf16Units)*2)
33+
for i, u := range utf16Units {
34+
binary.LittleEndian.PutUint16(utf16LE[i*2:], u)
35+
}
36+
37+
sum := sha1.Sum(utf16LE)
38+
39+
// SHA-1 is 20 bytes -> five little-endian uint32 components
40+
parts := make([]uint32, 5)
41+
for i := 0; i < 20; i += 4 {
42+
parts[i/4] = binary.LittleEndian.Uint32(sum[i : i+4])
43+
}
44+
45+
return fmt.Sprintf("S-1-5-80-%d-%d-%d-%d-%d", parts[0], parts[1], parts[2], parts[3], parts[4]), nil
46+
}
47+
48+
func parseArgs() {
49+
ap := parser.ArgumentsParser{Banner: "ComputeSIDFromServiceName - by Remi GASCOU (Podalirius) @ TheManticoreProject - v1.0.0"}
50+
51+
// Configuration flags
52+
ap.NewBoolArgument(&debug, "-d", "--debug", false, "Debug mode.")
53+
ap.NewStringArgument(&serviceName, "-s", "--service-name", "", true, "Service name to compute SID from.")
54+
55+
ap.Parse()
56+
}
57+
58+
func main() {
59+
parseArgs()
60+
61+
sid, err := ComputeSIDFromServiceName(serviceName)
62+
if err != nil {
63+
fmt.Fprintln(os.Stderr, "Error:", err)
64+
os.Exit(1)
65+
}
66+
fmt.Println(sid)
67+
}

0 commit comments

Comments
 (0)