public static void HandleGetKeyloggerLogsResponse(Client client, GetKeyloggerLogsResponse packet) { if (client.Value == null || client.Value.FrmKl == null) { return; } if (packet.FileCount == 0) { client.Value.FrmKl.SetGetLogsEnabled(true); return; } if (string.IsNullOrEmpty(packet.Filename)) { return; } string downloadPath = Path.Combine(client.Value.DownloadDirectory, "Logs\\"); if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } downloadPath = Path.Combine(downloadPath, packet.Filename + ".html"); FileSplit destFile = new FileSplit(downloadPath); destFile.AppendBlock(packet.Block, packet.CurrentBlock); if (packet.Index == packet.FileCount && (packet.CurrentBlock + 1) == packet.MaxBlocks) { FileInfo[] iFiles = new DirectoryInfo(Path.Combine(client.Value.DownloadDirectory, "Logs\\")).GetFiles(); if (iFiles.Length == 0) { return; } foreach (FileInfo file in iFiles) { if (client.Value == null || client.Value.FrmKl == null) { break; } client.Value.FrmKl.AddLogToListview(file.Name); } if (client.Value == null || client.Value.FrmKl == null) { return; } client.Value.FrmKl.SetGetLogsEnabled(true); } }
private void Execute(ISender client, GetKeyloggerLogsResponse message) { if (message.FileCount == 0) { OnReport("Ready"); return; } // don't escape from download directory if (FileHelper.HasIllegalCharacters(message.Filename)) { // disconnect malicious client client.Disconnect(); return; } if (!Directory.Exists(_baseDownloadPath)) { Directory.CreateDirectory(_baseDownloadPath); } string downloadPath = Path.Combine(_baseDownloadPath, message.Filename + ".html"); FileSplit destFile = new FileSplit(downloadPath); destFile.AppendBlock(message.Block, message.CurrentBlock); if (message.CurrentBlock + 1 == message.MaxBlocks) { try { File.WriteAllText(downloadPath, FileHelper.ReadLogFile(downloadPath, _client.Value.EncryptionKey)); } catch (Exception) { OnReport("Failed to write logs"); } if (message.Index == message.FileCount) { OnReport("Ready"); } } }
public static void HandleGetKeyloggerLogsResponse(Client client, GetKeyloggerLogsResponse packet) { if (client.Value == null || client.Value.FrmKl == null) { return; } if (packet.FileCount == 0) { client.Value.FrmKl.SetGetLogsEnabled(true); return; } if (string.IsNullOrEmpty(packet.Filename)) { return; } // don't escape from download directory if (FileHelper.CheckPathForIllegalChars(packet.Filename)) { // disconnect malicious client client.Disconnect(); return; } string downloadPath = Path.Combine(client.Value.DownloadDirectory, "Logs\\"); if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } downloadPath = Path.Combine(downloadPath, packet.Filename + ".html"); FileSplit destFile = new FileSplit(downloadPath); destFile.AppendBlock(packet.Block, packet.CurrentBlock); if ((packet.CurrentBlock + 1) == packet.MaxBlocks) { try { File.WriteAllText(downloadPath, FileHelper.ReadLogFile(downloadPath)); } catch { } if (packet.Index == packet.FileCount) { FileInfo[] iFiles = new DirectoryInfo(Path.Combine(client.Value.DownloadDirectory, "Logs\\")).GetFiles(); if (iFiles.Length == 0) { return; } foreach (FileInfo file in iFiles) { if (client.Value == null || client.Value.FrmKl == null) { break; } client.Value.FrmKl.AddLogToListview(file.Name); } if (client.Value == null || client.Value.FrmKl == null) { return; } client.Value.FrmKl.SetGetLogsEnabled(true); } } }