Пример #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("");
        }