Esempio n. 1
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}");
                }
            }
        }
Esempio n. 2
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}");

                }
            }
        }
Esempio n. 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)) {
                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}");
                }
            }
        }
Esempio n. 4
0
 public DefaultBeaconApi(BeaconConsoleWriter consoleWriter)
 {
     this.Console = consoleWriter;
 }