Initial OfficeCom Sentinel client and deployment assets
This commit is contained in:
71
installer/AttackTracerNinjaBootstrapper/Program.cs
Normal file
71
installer/AttackTracerNinjaBootstrapper/Program.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO.Compression;
|
||||
using System.Reflection;
|
||||
|
||||
namespace AttackTracerNinjaBootstrapper;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private static int Main()
|
||||
{
|
||||
string tempRoot = Path.Combine(Path.GetTempPath(), "AttackTracerNinjaSetup", Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(tempRoot);
|
||||
|
||||
try
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
string resourceName = assembly.GetManifestResourceNames()
|
||||
.First(name => name.EndsWith("payload.zip", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
string zipPath = Path.Combine(tempRoot, "payload.zip");
|
||||
using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)
|
||||
?? throw new InvalidOperationException("Embedded payload.zip was not found."))
|
||||
using (FileStream output = File.Create(zipPath))
|
||||
{
|
||||
resourceStream.CopyTo(output);
|
||||
}
|
||||
|
||||
string extractRoot = Path.Combine(tempRoot, "payload");
|
||||
ZipFile.ExtractToDirectory(zipPath, extractRoot);
|
||||
|
||||
string installScript = Path.Combine(extractRoot, "install-attacktracer-ninja.ps1");
|
||||
if (!File.Exists(installScript))
|
||||
{
|
||||
throw new FileNotFoundException("Installer script missing from payload.", installScript);
|
||||
}
|
||||
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "powershell.exe",
|
||||
Arguments = $"-ExecutionPolicy Bypass -File \"{installScript}\"",
|
||||
WorkingDirectory = extractRoot,
|
||||
UseShellExecute = true
|
||||
};
|
||||
|
||||
using Process process = Process.Start(startInfo)
|
||||
?? throw new InvalidOperationException("Failed to launch installer process.");
|
||||
|
||||
process.WaitForExit();
|
||||
return process.ExitCode;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"AttackTracerNinja installer failed: {ex}");
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(tempRoot))
|
||||
{
|
||||
Directory.Delete(tempRoot, recursive: true);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Best-effort cleanup; a locked temp folder should not hide the installer result.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user