예제 #1
0
        public static void Execute(Job job, Agent implant)
        {
            Task task = job.Task;

            MoveParameters arguments = JsonConvert.DeserializeObject <MoveParameters>(task.parameters);

            if (string.IsNullOrEmpty(arguments.source))
            {
                job.SetError("No source path given to move.");
                return;
            }
            if (string.IsNullOrEmpty(arguments.destination))
            {
                job.SetError("No destination path was given.");
                return;
            }

            if (!File.Exists(arguments.source))
            {
                job.SetError($"File \"{arguments.source}\" does not exist.");
                return;
            }

            if (File.Exists(arguments.destination))
            {
                job.SetError($"File \"{arguments.destination}\" already exists. Delete or move this file before overwriting it.");
                return;
            }
            FileInfo source = new FileInfo(arguments.source);
            FileInfo dest;

            try
            {
                File.Move(arguments.source, arguments.destination);
                dest = new FileInfo(arguments.destination);
                job.Task.completed = true;
                ApolloTaskResponse resp = new ApolloTaskResponse(job.Task, $"Successfully moved \"{arguments.source}\" to \"{arguments.destination}\"")
                {
                    artifacts = new Artifact[]
                    {
                        new Artifact()
                        {
                            base_artifact = "File Move", artifact = $"Renamed {source.FullName} to {dest.FullName} (MD5: {FileUtils.GetFileMD5(dest.FullName)})"
                        }
                    }
                };
                job.SetComplete(resp);
            } catch (Exception ex)
            {
                job.SetError($"Error performing the move operation. Reason: {ex.Message}");
            }
        }
예제 #2
0
        public static void Execute(Job job, Agent implant)
        {
            Task task = job.Task;

            MoveParameters arguments = JsonConvert.DeserializeObject <MoveParameters>(task.parameters);

            if (string.IsNullOrEmpty(arguments.source))
            {
                job.SetError("No source path given to move.");
                return;
            }
            if (string.IsNullOrEmpty(arguments.destination))
            {
                job.SetError("No destination path was given.");
                return;
            }

            if (!File.Exists(arguments.source))
            {
                job.SetError($"File \"{arguments.source}\" does not exist.");
                return;
            }

            if (File.Exists(arguments.destination))
            {
                job.SetError($"File \"{arguments.destination}\" already exists. Delete or move this file before overwriting it.");
                return;
            }

            try
            {
                File.Move(arguments.source, arguments.destination);
                job.SetComplete($"Successfully moved \"{arguments.source}\" to \"{arguments.destination}\"");
            } catch (Exception ex)
            {
                job.SetError($"Error performing the move operation. Reason: {ex.Message}");
            }
        }