-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommandLineExecution.cs
More file actions
49 lines (39 loc) · 1.46 KB
/
CommandLineExecution.cs
File metadata and controls
49 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
namespace Ilay_sRanomwarePoc
{
static class CommandLineExecution
{
private const string CommandLine = @"C:\Windows\System32\cmd.exe";
//optional//
private const string WorkingDirectory = @"C:/Users/ilay/";
public static string CommandExecution(string CmdCommand) //executes a command and returns its output
{
try
{
Process Execution = new Process();
ProcessStartInfo ExecutionInfo = new ProcessStartInfo(WorkingDirectory);
ExecutionInfo.UseShellExecute = false;
ExecutionInfo.RedirectStandardOutput = true;
ExecutionInfo.FileName = CommandLine;
ExecutionInfo.Arguments = $"/c {CmdCommand}";
ExecutionInfo.WorkingDirectory = WorkingDirectory;
Execution.StartInfo = ExecutionInfo;
Execution.Start();
string Output = Execution.StandardOutput.ReadToEnd();
Execution.WaitForExit();
Execution.Kill();
return Output;
}
catch
{
Console.WriteLine("Error while trying to execute the cmd command!");
return null;
}
}
}
}