namespace DSInternals.Common.Data { using System.IO; using System.Text; public abstract class DPAPIObject { /// /// Path to the generated Mimikatz DPAPI batch processing script. /// public const string KiwiFilePath = "kiwiscript.txt"; /// /// DPAPI blob. /// public byte[] Data { get; protected set; } /// /// Gets the relative path to which this blob will be saved. /// public abstract string FilePath { get; } /// /// Gets the Mimikatz command that would process the DPAPI blob. /// public abstract string KiwiCommand { get; } /// /// Saves the DPAPI blob to an appropriate file in the current directory. /// public void Save() { this.Save(Directory.GetCurrentDirectory()); } /// /// Saves the DPAPI blob to an appropriate file in the specified directory. /// /// Directory to save the DPAPI blob to. public abstract void Save(string directoryPath); /// /// Appends the Mimikatz command to a text file in the current directory. /// public void SaveKiwiCommand() { this.SaveKiwiCommand(Directory.GetCurrentDirectory()); } /// /// Appends the Mimikatz command to a text file in the specified directory. /// /// Directory to save the text file to. public void SaveKiwiCommand(string directoryPath) { string command = this.KiwiCommand; if(string.IsNullOrEmpty(command)) { // Mimikatz probably does not support this DPAPI object type, so there is nothing to write to the script file return; } // The target directory must exist Validator.AssertDirectoryExists(directoryPath); var filePath = Path.Combine(directoryPath, KiwiFilePath); using (var writer = File.AppendText(filePath)) { writer.WriteLine(command); } } } }