Beispiel #1
0
 public BeaconJob(BeaconObject bo, string[] args, BeaconJobWriter beaconTaskWriter)
 {
     BeaconConsole = beaconTaskWriter;
     BeaconObject  = bo;
     Thread        = new Thread(new ParameterizedThreadStart(this.DoTask));
     Thread.Start(args);
 }
Beispiel #2
0
        public static void InvokeBof(long[] beaconApis, string bofName, object args)
        {
            SetupAssemblyResolver();

            var beaconConsole = (BeaconConsoleWriter.BeaconConsoleWriterDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)(beaconApis[0]),
                                                                                                                       typeof(BeaconConsoleWriter.BeaconConsoleWriterDelegate));
            var initialiseChildBOFNETAppDomain = (InitialiseChildBOFNETAppDomain)Marshal.GetDelegateForFunctionPointer((IntPtr)(beaconApis[1]),
                                                                                                                       typeof(InitialiseChildBOFNETAppDomain));

            var beaconUseToken    = (BeaconUseToken)Marshal.GetDelegateForFunctionPointer((IntPtr)(beaconApis[2]), typeof(BeaconUseToken));
            var beaconRevertToken = (BeaconRevertToken)Marshal.GetDelegateForFunctionPointer((IntPtr)(beaconApis[3]), typeof(BeaconRevertToken));

            using (BeaconConsoleWriter bcw = new BeaconConsoleWriter(beaconConsole)) {
                if (String.IsNullOrEmpty(bofName))
                {
                    bcw.WriteLine($"[!] BOF name not supplied, don't know what to execute, bailing!");
                    return;
                }

                try {
                    BeaconObject bo = CreateBeaconObject(bofName, bcw, initialiseChildBOFNETAppDomain, beaconUseToken, beaconRevertToken);

                    if (args is string cmdLine)
                    {
                        if (!string.IsNullOrEmpty(cmdLine))
                        {
                            bo.Go(CommandLineToArgs(cmdLine));
                        }
                        else
                        {
                            bo.Go(new string[] { });
                        }
                    }
                    else if (args is byte[] raw)
                    {
                        bo.Go(raw);
                    }
                    else
                    {
                        bcw.WriteLine($"[!] Unuspported argument type {args.GetType().FullName} when attempting to invoke BOF");
                    }
                } catch (TypeLoadException tle) {
                    bcw.WriteLine(tle.Message);
                } catch (AmbiguousMatchException) {
                    bcw.WriteLine($"[!] Multiple BOFs found with name {bofName}, use fully qualifed type including namespace");
                    return;
                } catch (ReflectionTypeLoadException rtle) {
                    bcw.WriteLine($"[!] Failed to load a type during BOFNET execution with the folowing loader exceptions:");
                    foreach (Exception e in rtle.LoaderExceptions)
                    {
                        bcw.WriteLine($"{e}");
                    }
                    return;
                } catch (Exception e) {
                    bcw.WriteLine($"[!] BOFNET executed but threw an unhandled exception: {e}");
                }
            }
        }
Beispiel #3
0
        public static void InvokeBof(long consoleCallback, string bofName, object args) {

            if (firstInit) {
                AppDomain.CurrentDomain.AssemblyResolve += Runtime.CurrentDomain_AssemblyResolve;
                LoadedAssemblies["BOFNET"] = Assembly.GetExecutingAssembly();
                firstInit = false;
            }

            BeaconConsoleWriter.BeaconConsoleWriterDelegate nativeDelagte =
                (BeaconConsoleWriter.BeaconConsoleWriterDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(consoleCallback),
                                                                                                       typeof(BeaconConsoleWriter.BeaconConsoleWriterDelegate));
            using (BeaconConsoleWriter bcw = new BeaconConsoleWriter(nativeDelagte)) {

                if (String.IsNullOrEmpty(bofName)) {
                    bcw.WriteLine($"[!] BOF name not supplied, don't know what to execute, bailing!");
                    return;
                }

                try {

                    BeaconObject bo = CreateBeaconObject(bofName, bcw);

                    if (args is string cmdLine) {
                        if (!string.IsNullOrEmpty(cmdLine))
                            bo.Go(CommandLineToArgs(cmdLine));
                        else
                            bo.Go(new string[] { });
                    } else if (args is byte[] raw) {
                        bo.Go(raw);
                    } else {
                        bcw.WriteLine($"[!] Unuspported argument type {args.GetType().FullName} when attempting to invoke BOF");
                    }

                } catch (TypeLoadException tle) {

                    bcw.WriteLine(tle.Message);

                } catch (AmbiguousMatchException) {

                    bcw.WriteLine($"[!] Multiple BOFs found with name {bofName}, use fully qualifed type including namespace");
                    return;

                } catch (ReflectionTypeLoadException rtle) {

                    bcw.WriteLine($"[!] Failed to load a type during BOFNET execution with the folowing loader exceptions:");
                    foreach (Exception e in rtle.LoaderExceptions) {
                        bcw.WriteLine($"{e}");
                    }
                    return;

                } catch (Exception e) {

                    bcw.WriteLine($"[!] BOFNET executed but threw an unhandled exception: {e}");

                }
            }
        }
Beispiel #4
0
        public static BeaconObject CreateBeaconObject(string bofName, BeaconOutputWriter bow) {

            Type bofType = FindType(bofName);

            if (bofType == null) {
                throw new TypeLoadException($"[!] Failed to find type {bofName} within BOFNET AppDomain, have you loaded the containing assembly yet?");
            }

            BeaconObject bo = (BeaconObject)Activator.CreateInstance(bofType, new object[] { new DefaultBeaconApi(bow) });
            return bo;
        }
Beispiel #5
0
 private void DoTask(object args)
 {
     try {
         if (args is string[] stringArgs)
         {
             BeaconObject.Go(stringArgs);
         }
     }catch (Exception e) {
         BeaconConsole.WriteLine($"Job execution failed with exception:\n{e}");
     }
 }
Beispiel #6
0
        public static void InvokeBof(long consoleCallback, string bofName, object args)
        {
            if (firstInit)
            {
                AppDomain.CurrentDomain.AssemblyResolve += Runtime.CurrentDomain_AssemblyResolve;
                LoadedAssemblies["BOFNET"] = Assembly.GetExecutingAssembly();
                firstInit = false;
            }

            BeaconConsoleWriter.BeaconConsoleWriterDelegate nativeDelagte =
                (BeaconConsoleWriter.BeaconConsoleWriterDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(consoleCallback),
                                                                                                       typeof(BeaconConsoleWriter.BeaconConsoleWriterDelegate));
            using (BeaconConsoleWriter bcw = new BeaconConsoleWriter(nativeDelagte)) {
                Type bofType;

                if (String.IsNullOrEmpty(bofName))
                {
                    bcw.WriteLine($"[!] BOF name not supplied, don't know what to execute, bailing!");
                    return;
                }

                try {
                    bofType = FindType(bofName);
                } catch (AmbiguousMatchException) {
                    bcw.WriteLine($"[!] Multiple BOFs found with name {bofName}, use fully qualifed type including namespace");
                    return;
                }

                if (bofType == null)
                {
                    bcw.WriteLine($"[!] Failed to find type {bofName} within BOFNET AppDomain, have you loaded the containing assembly yet?");
                    return;
                }

                BeaconObject bo = (BeaconObject)Activator.CreateInstance(bofType, new object[] { new DefaultBeaconApi(bcw) });

                try {
                    if (args is string cmdLine)
                    {
                        if (!string.IsNullOrEmpty(cmdLine))
                        {
                            bo.Go(CommandLineToArgs(cmdLine));
                        }
                        else
                        {
                            bo.Go(new string[] { });
                        }
                    }
                    else if (args is byte[] raw)
                    {
                        bo.Go(raw);
                    }
                    else
                    {
                        bcw.WriteLine($"[!] Unuspported argument type {args.GetType().FullName} when attempting to invoke BOF");
                    }
                }catch (Exception e) {
                    bcw.WriteLine($"[!] BOFNET executed but threw an unhandled exception: {e}");
                }
            }
        }
Beispiel #7
0
 public override string ToString()
 {
     return($"Type: {BeaconObject.GetType().Name}, Id: {Thread.ManagedThreadId}, Active: {Thread.IsAlive}, Console Data: {BeaconConsole.HasData}");
 }