Exemple #1
0
        public async Task <string> SharpShell(Grunt grunt, GruntCommand command, List <ParsedParameter> parameters)
        {
            if (parameters.Count() < 2 || !parameters[0].Value.Equals("SharpShell", StringComparison.OrdinalIgnoreCase))
            {
                return(EliteConsole.PrintFormattedErrorLine("Usage: SharpShell <code>"));
            }
            string WrapperFunctionFormat =
                @"using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Security;
using System.Security.Principal;
using System.Collections.Generic;
using SharpSploit.Credentials;
using SharpSploit.Enumeration;
using SharpSploit.Execution;
using SharpSploit.Generic;
using SharpSploit.Misc;
public static class Task
{{
    public static string Execute()
    {{
        {0}
    }}
}}";

            string    csharpcode        = string.Join(" ", parameters.Skip(1).Select(P => P.Value).ToArray());
            GruntTask newSharpShellTask = await _context.CreateGruntTask(new GruntTask
            {
                Name           = "SharpShell-" + Utilities.CreateShortGuid(),
                AlternateNames = new List <string>(),
                Description    = "Execute custom c# code.",
                Code           = string.Format(WrapperFunctionFormat, csharpcode),
                Options        = new List <GruntTaskOption>()
            });

            await _context.AddAsync(new GruntTaskReferenceSourceLibrary
            {
                ReferenceSourceLibrary = await _context.GetReferenceSourceLibraryByName("SharpSploit"),
                GruntTask = newSharpShellTask
            });

            await _context.SaveChangesAsync();

            await _context.CreateGruntTasking(new GruntTasking
            {
                GruntId        = grunt.Id,
                GruntTaskId    = newSharpShellTask.Id,
                Type           = GruntTaskingType.Assembly,
                Status         = GruntTaskingStatus.Uninitialized,
                GruntCommandId = command.Id,
                GruntCommand   = command
            }, _grunthub);

            return("");
        }
        public async Task <IActionResult> Create(GruntTaskModel taskModel)
        {
            try
            {
                GruntTask task = new GruntTask
                {
                    Name          = taskModel.Name,
                    Description   = taskModel.Description,
                    Help          = taskModel.Help,
                    Code          = taskModel.Code,
                    UnsafeCompile = taskModel.UnsafeCompile,
                    TokenTask     = taskModel.TokenTask,
                    Options       = taskModel.Options
                };
                taskModel.ReferenceSourceLibraries.ForEach(async RSL => {
                    task.Add(await _context.GetReferenceSourceLibrary(RSL));
                });
                taskModel.ReferenceAssemblies.ForEach(async RA => {
                    task.Add(await _context.GetReferenceAssembly(RA));
                });
                taskModel.EmbeddedResources.ForEach(async ER => {
                    task.Add(await _context.GetEmbeddedResource(ER));
                });
                ViewBag.ReferenceSourceLibraries = await _context.GetReferenceSourceLibraries();

                ViewBag.ReferenceAssemblies = await _context.GetReferenceAssemblies();

                ViewBag.EmbeddedResources = await _context.GetEmbeddedResources();

                GruntTask createdTask = await _context.CreateGruntTask(task);

                return(RedirectToAction(nameof(Edit), new { Id = createdTask.Id }));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                ViewBag.ReferenceSourceLibraries = await _context.GetReferenceSourceLibraries();

                ViewBag.ReferenceAssemblies = await _context.GetReferenceAssemblies();

                ViewBag.EmbeddedResources = await _context.GetEmbeddedResources();

                return(View(new GruntTask()));
            }
        }
Exemple #3
0
        public async Task <ActionResult <GruntTask> > CreateGruntTask([FromBody] GruntTask task)
        {
            GruntTask savedTask = await _context.CreateGruntTask(task);

            return(CreatedAtRoute(nameof(GetGruntTask), new { id = savedTask.Id }, savedTask));
        }