public IActionResult RequestFile([FromBody] DownloadRequestViewModel param) { if (ModelState.IsValid) { return(Ok()); } else { return(BadRequest(ModelState)); } }
public IActionResult RequestFile([FromBody] DownloadRequestViewModel param) { if (ModelState.IsValid) { Guid Id = Guid.NewGuid(); _downloadService.DownloadRequest(param, Id); return(Ok(Id)); } else { return(BadRequest(ModelState)); } }
public void DownloadRequest(DownloadRequestViewModel param, Guid Id) { Computer computer = _context.Computers.Single(c => c.Id == param.ComputerId); Credential credential = _context.Credentials.Single(c => c.Id == computer.CredentialId); if (computer.WinRM || computer.RPC) { // Create a PowerShell script to run PSInvestigate string executionArgs = string.Format( @"Download-AceFile -Uri {0} -Thumbprint {1} -Path {2} -Id {3}", param.Uri, _settings.Thumbprint, param.FilePath, Id ); string psScript = string.Format( @"Invoke-Expression (New-Object System.Net.WebClient).DownloadString('{0}/scripts/Download-AceFile.ps1'); {1}; Get-Process | Out-File -FilePath C:\temp\jared.txt", param.Uri, executionArgs ); Console.WriteLine("[{0}] PsScript: {1}", computer.ComputerName, psScript); string commandline = string.Format( @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -EncodedCommand {0}", Convert.ToBase64String(Encoding.Unicode.GetBytes(psScript)) ); if (computer.WinRM) { KickOffCim(computer, credential, commandline, new WSManSessionOptions()); } else { KickOffCim(computer, credential, commandline, new DComSessionOptions()); } } else if (computer.SSH) { throw new NotImplementedException(); } else if (computer.SMB) { throw new NotImplementedException(); } else { throw new Exception(string.Format("No valid protocols available for {0}", computer.ComputerName)); } }