mirror of
https://github.com/lukaszraczylo/go-obfuscation.git
synced 2026-10-14 05:48:22 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
apiKey = "sk-proj-FAKE-KEY-1234567890abcdef"
|
||||
secretVal = "super-secret-license-key-DO-NOT-SHARE"
|
||||
dbConnStr = "postgres://admin:P@[email protected]:5432/production"
|
||||
jwtSecret = "my-jwt-signing-secret-2024"
|
||||
)
|
||||
|
||||
var licenseKey = "LIC-XXXX-YYYY-ZZZZ-PRODUCTION"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Application started successfully")
|
||||
fmt.Printf("Version: %s\n", getVersion())
|
||||
fmt.Printf("Build: %s\n", getBuildID())
|
||||
|
||||
processRequest("user-12345")
|
||||
}
|
||||
|
||||
func getVersion() string {
|
||||
return "1.0.0-prod"
|
||||
}
|
||||
|
||||
func getBuildID() string {
|
||||
return fmt.Sprintf("build-%d", time.Now().Unix())
|
||||
}
|
||||
|
||||
func processRequest(userID string) {
|
||||
fmt.Printf("Processing request for user: %s\n", userID)
|
||||
|
||||
if userID == "" {
|
||||
fmt.Fprintln(os.Stderr, "Error: empty user ID")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
token := generateToken(userID)
|
||||
fmt.Printf("Generated token: %s\n", maskString(token))
|
||||
|
||||
result := validateLicense(licenseKey)
|
||||
fmt.Printf("License valid: %v\n", result)
|
||||
|
||||
_ = apiKey
|
||||
_ = secretVal
|
||||
_ = dbConnStr
|
||||
_ = jwtSecret
|
||||
}
|
||||
|
||||
func generateToken(userID string) string {
|
||||
h := sha256.Sum256([]byte(fmt.Sprintf("%s:%d", userID, time.Now().UnixNano())))
|
||||
return fmt.Sprintf("tok_%x", h[:8])
|
||||
}
|
||||
|
||||
func validateLicense(key string) bool {
|
||||
return len(key) > 10
|
||||
}
|
||||
|
||||
func maskString(s string) string {
|
||||
if len(s) <= 8 {
|
||||
return "****"
|
||||
}
|
||||
return s[:4] + "****" + s[len(s)-4:]
|
||||
}
|
||||
|
||||
func init() {
|
||||
fmt.Println("Initializing secure environment...")
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/self-evolving-research/obfuscator/pkg/integrity"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr, "Usage: inthash <binary-path>\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
hash, err := integrity.ComputeHashForEmbedding(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Print(hash)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/self-evolving-research/obfuscator/internal/transform"
|
||||
)
|
||||
|
||||
func main() {
|
||||
srcDir := flag.String("src", "", "Source directory to transform")
|
||||
dstDir := flag.String("dst", "", "Destination directory for transformed source")
|
||||
encryptStrings := flag.Bool("strings", true, "Encrypt string literals")
|
||||
opaquePreds := flag.Bool("opaque", true, "Inject opaque predicates")
|
||||
deadCode := flag.Bool("deadcode", true, "Inject dead code")
|
||||
randomize := flag.Bool("randomize", true, "Randomize declaration order")
|
||||
indirectDispatch := flag.Bool("indirect", true, "Indirect function dispatch")
|
||||
bogusCFG := flag.Bool("bogus-cfg", true, "Bogus control-flow injection")
|
||||
flatten := flag.Bool("flatten", true, "Control-flow flattening")
|
||||
seed := flag.Int64("seed", 0, "Build seed for polymorphic output (0 = use current timestamp)")
|
||||
injectBuildID := flag.Bool("buildid", true, "Inject unique build ID constant")
|
||||
virtualizeVM := flag.Bool("vm", true, "Virtualize simple functions into VM bytecode")
|
||||
flag.Parse()
|
||||
|
||||
if *srcDir == "" || *dstDir == "" {
|
||||
fmt.Fprintf(os.Stderr, "Usage: transformer -src <dir> -dst <dir>\n")
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *seed == 0 {
|
||||
*seed = time.Now().UnixNano()
|
||||
}
|
||||
|
||||
absSrc, err := filepath.Abs(*srcDir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Invalid src path: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
absDst, err := filepath.Abs(*dstDir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Invalid dst path: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
config := transform.Config{
|
||||
EncryptStrings: *encryptStrings,
|
||||
InjectOpaquePreds: *opaquePreds,
|
||||
InjectDeadCode: *deadCode,
|
||||
RandomizeOrder: *randomize,
|
||||
IndirectDispatch: *indirectDispatch,
|
||||
BogusControlFlow: *bogusCFG,
|
||||
FlattenControl: *flatten,
|
||||
BuildSeed: *seed,
|
||||
InjectBuildID: *injectBuildID,
|
||||
VirtualizeFunctions: *virtualizeVM,
|
||||
}
|
||||
|
||||
t := transform.New(config)
|
||||
|
||||
fmt.Printf("[transformer] src=%s dst=%s\n", absSrc, absDst)
|
||||
fmt.Printf("[transformer] seed=%d buildid=%v\n", config.BuildSeed, config.InjectBuildID)
|
||||
fmt.Printf("[transformer] strings=%v opaque=%v deadcode=%v bogus=%v flatten=%v vm=%v\n",
|
||||
config.EncryptStrings, config.InjectOpaquePreds,
|
||||
config.InjectDeadCode, config.BogusControlFlow, config.FlattenControl,
|
||||
config.VirtualizeFunctions)
|
||||
|
||||
start := time.Now()
|
||||
|
||||
if err := t.TransformDir(absSrc, absDst); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Transform failed: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("[transformer] done in %v\n", time.Since(start))
|
||||
}
|
||||
Reference in New Issue
Block a user