myph.git


myph

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

commit 2a5a6edaac22cc187c19a4f1cdb856d7845c45a1
parent b3d5409ba69e2681c8dcbef92d6005102c49d5a2
Author: winds0r <[email protected]>
Date: Thu, 13 Jul 2023 22:05:19 +0900

feat(loader): adding support for different Encoding types when interpolating

Diffstat:
Mcli/parser.go | 11+++++++++++
Aloader/encodings.go | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/cli/parser.go b/cli/parser.go
@@ -30,6 +30,17 @@ func GetParser(opts *Options) *cobra.Command {
                 os.Exit(1)
             }
 
+            shellcode, err := loader.ReadFile(opts.ShellcodePath)
+            if err != nil {
+                fmt.Printf("[!] Error reading shellcode file: %s", err)
+                os.Exit(1)
+            }
+
+            encType := loader.SelectRandomEncodingType()
+            shellcodeAsString := loader.EncodeForInterpolation(encType, shellcode)
+
+            fmt.Println(shellcodeAsString)
+
 			os.Setenv("GOOS", opts.OS)
 			os.Setenv("GOARCH", opts.arch)
         },
diff --git a/loader/encodings.go b/loader/encodings.go
@@ -0,0 +1,71 @@
+package loader
+
+import (
+	"errors"
+	"math/rand"
+	"time"
+    b64 "encoding/base64"
+    b32 "encoding/base32"
+    hex "encoding/hex"
+)
+
+/// Enum type that defines which bytes encoding to use
+/// in template source-code
+type BytesEncodingType string
+
+const (
+    EncodingBase64 BytesEncodingType    = "base64"
+    EncodingBase32 BytesEncodingType    = "base32"
+    EncodingHex BytesEncodingType       = "hex"
+)
+
+/// Available encodings type
+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 {
+    return string(*e)
+}
+
+/// 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", "hex":
+        *e = BytesEncodingType(v)
+        return nil
+    default:
+        return errors.New(`must be one of "base64", "base32", or "hex"`)
+    }
+}
+
+/// Type is only used in help text
+func (e *BytesEncodingType) Type() string {
+    return "BytesEncodingType"
+}
+
+/// Select a random encoding type
+func SelectRandomEncodingType() BytesEncodingType {
+    rand.Seed(time.Now().Unix())
+    n := rand.Int() % len(Encodings)
+
+    return BytesEncodingType(Encodings[n])
+}
+
+
+/// Encode a series of bytes so that it can be interpolated into a template
+func EncodeForInterpolation(method BytesEncodingType, toEncode []byte) string {
+    switch method {
+
+    case EncodingBase64:
+        return b64.StdEncoding.EncodeToString(toEncode)
+
+    case EncodingBase32:
+        return b32.StdEncoding.EncodeToString(toEncode)
+
+    case EncodingHex:
+        return hex.EncodeToString(toEncode)
+
+    default:
+        return ""
+    }
+}