pass multiple commands in the processStartInfo argument

Occasional Visitor

Hello everyone !

 

I'm running a proof of concept - POC on a Linux machine and I need to pass multiple commands in the processStartInfo argument,

unfortunately all the attempts I made were not successful.

Below is the code and I implemented it (I'm using Aspnet.core 5 - using System.Diagnostics):

command[0] = "ping" - IT IS BEING PASSED DYNAMICS


System.Diagnostics.ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo($"{comando[0]}");

StartInfo.Arguments = "\"8.8.8.8;ls -ls\"";

System.Diagnostics.Process.Start(StartInfo);

 

 

one of the errors that occurs:

 

1) ping: 8.8.8.8;ls -ls: Unknown name or service


2) fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]

An unhandled exception has occurred while executing the request.

System.ComponentModel.Win32Exception (2): No such file or directory

at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)

at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)

at System.Diagnostics.Process.Start()

at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)

at AppVulnPills.Controllers.HostCadController.VerificaHostName(String ip) in /home/nilton/Documentos/Projetos_NIlton/AppVulnPills/AppVulnPills/Controllers/HostCadController.cs:line 130

at AppVulnPills.Controllers.HostCadController.EfetuarCadastroHost(HostModel host) in /home/nilton/Documentos/Projetos_NIlton/AppVulnPills/AppVulnPills/Controllers/HostCadController.cs:line 292

at lambda_method29(Closure , Object , Object[] )

at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

--- End of stack trace from previous location ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()

--- End of stack trace from previous location ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()

--- End of stack trace from previous location ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)

at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)

at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Could someone please tell me what I'm doing wrong?

 

Note: I need to pass the command as the arguments dynamically, I use two variables for this. in the example above the

Argument is set and I'm just passing the command dynamically, but I'll also need to pass the arguments

dynamically, passing both dynamically also occurs error.

One more detail I also used the filename and UseShellExecute the same problem occurred.

StartInfo.UseShellExecute = true;

StartInfo.FileName = "../bin/bash";

0 Replies