Awesome
Obfuscatxor
Overview
Very simple string obfuscation package for (near) compile-time obfuscation and hash processing.
Functionality provided at present:
- XOR strings with variable-length key
- Generate CRC64 hashes of strings
Updated with a suggestion from C-Sto to include the XOR and hashing functions inside the template to avoid loading the external library.
Compile-time usage
Create a file (ex: strings.go
) using the following format:
//go:generate go run github.com/redskal/obfuscatxor/cmd/obfuscator -output strings-out.go strings.go
package testing
//obfuscate Key(ObfuscateThis) Phrase(Just a test string) VarName(test1)
//obfuscate Key(ObfuscateMe) Phrase(Something, something, whatever, whatever) VarName(test2)
//hash phrase(hash me please) VarName(hash1)
//hash phrase(another thing to hash) varname(hash2)
When you use go generate
the compiler will parse the //go:generate
comment and use the obfuscator tool to produce an output file containing your XOR'd strings and CRC64 hashes. The generated variables can then be used in your code.
Output file will look like this:
// Code generated by 'go generate'; DO NOT EDIT
package testing
import (
"hash/crc64"
"math/rand"
)
var hashTable = crc64.MakeTable(crc64.ECMA)
var (
// Key: "ObfuscateThis", String: "Just a test string"
test1 = []byte{
0x05, 0x17, 0x15, 0x01, 0x53, 0x02, 0x41, 0x00, 0x00, 0x27, 0x1c, 0x49, 0x00, 0x3b, 0x10,
0x0f, 0x1b, 0x14}
// Key: "ObfuscateMe", String: "Something, something, whatever, whatever"
test2 = []byte{
0x1c, 0x0d, 0x0b, 0x10, 0x07, 0x0b, 0x08, 0x1a, 0x02, 0x61, 0x45, 0x3c, 0x0d, 0x0b, 0x10,
0x07, 0x0b, 0x08, 0x1a, 0x02, 0x61, 0x45, 0x38, 0x0a, 0x07, 0x01, 0x16, 0x15, 0x04, 0x06,
0x49, 0x6d, 0x12, 0x27, 0x03, 0x12, 0x10, 0x05, 0x06, 0x13}
hash1 uint64 = 4933402316976831528 // String: "hash me please"
hash2 uint64 = 15307073676716255198 // String: "another thing to hash"
)
[...SNIP...]
Just make sure the file is included in your project, and you'll have your obfuscated strings and the necessary functions included.
Usage
To use the string XOR function do as follows:
import "fmt"
func main() {
// Key: "ObfuscateThis", String: "Just a test string"
test1 = []byte{
0x05, 0x17, 0x15, 0x01, 0x53, 0x02, 0x41, 0x00, 0x00, 0x27, 0x1c, 0x49, 0x00, 0x3b, 0x10,
0x0f, 0x1b, 0x14}
fmt.Println(StringXOR(string(test1), "ObfuscateThis"))
}
Output will be:
Just a test string
To use the CRC64 hashing it's equally as simple:
import "fmt"
func main() {
hash1 uint64 := 4933402316976831528
str := "hash me please"
if hash1 == obfuscate.GetCRCHash(str) {
fmt.Println("It's the same")
} else {
fmt.Println("Wrong-o!")
}
}
Output will be:
It's the same
Licence
Respect the licence of any and all third party code. Anything that's mine is provided under #YOLO Public License.